Golang SetTime() - writes fail if time is not time.Now()?

I’m using the Golang client library to write a point (via the non-blocking client). However, I want to use a value of time that is not time.Now() so that I can track values across set of simulated time-series data.

My code essentially looks like this:

p := influxdb2.NewPointWithMeasurement("Data").
        AddTag("name", nameVar). 
		AddField("Var1", ValOfVar1).
		AddField("Var2", ValOfVar2).
		AddField("Var9", ValOfVar9).

SetTime accepts a time.Time() object, but if the object put in SetTime is anything but time.Now(), the program won’t write. I know this is happening because there will be no resulting data in the bucket chosen, and a later part of my program that looks for data will fail.

Is there a way to write a time value, if the time object chosen is not time.Now()?

Can you please share the code from your attempts at using another time, please?

It’s easier if I explain the impact, but I will use code for it as well.

The other time I am trying to use is a time.Time() object, specifically obtained by initially using a Unix Epoch time (in milliseconds, as a uint64) which is converted into a Time() object using:

timeStampNewFormat := time.Unix(0, int64(timeOriginalUnixMilli)*int64(time.Second))

This is used for another operation first (the simulation and then subsequent calculation of the data I would like to capture for InfluxDB), then is passed into the function shared initially as a time.Time() object and is ultimately uploaded as Var9 (in the initially shared function)

After calculating the data, I check the influxDB database first to make sure that I am not going to write data points that already exist. I do this through using another function which sets an upper and lower bound on time calculated, by querying the database and looking for the first and last timeStampNewFormat (Var9) that is written for each set of data (exporting through a variable named timeScale as a map[string]TimeStruct, of which TimeStruct contains two time.Time() objects). That is, the Time objects are compared using:

if timeStampNewFormat.Before(timeDayLimit) && 
					(timeStampNewFormat.Before(timeScale[chosenDataSet].Start) || timeStampNewFormat.After(timeScale[chosenDataSet].End)) {
					WriteToInflux(dataState, clientDB, timeStampNewFormat)

However, if there is no data in the bucket- as in, no data has been written to it - the map is empty, and thus a search for times using this if statement causes a segmentation fault.

Therefore, if instead of time.Now() in the first function, I use

The resulting effect is

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1...

As the bucket is empty, with no data having been written to it.

However, a few seconds after the segfault, some data does arrive in the bucket, with the time accurate to was supposed to be written. However, it’s only a little bit of data. Repeating the program allows it to run without segfaults, but not all of the data arrives at the server.

Apologies everyone. It seems that my issue with this comes down two things:

  1. My method of writing time, which involves a goroutine system that I have suspicions is implemented incorrectly, and
  2. My if statement is being ignored - that is, it is being checked too soon, with no data present on the server yet.

After switching to a different method (that is, by disabling the goroutine system), it seems that InfluxDB can support the other timestep after all.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.