Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change all time formatting to UTC and off of time.RFC3339Nano #617

Merged
merged 2 commits into from
Jul 9, 2019

Conversation

jacksontj
Copy link
Contributor

Prometheus has issues parsing RFC3339Nano timestamps if the year has more than 4 digits, in addition it is the second-pass parse attempt. Since this is a client library and the interface is a time.Time it makes sense that we pick the clearest simplest format-- so I propose we use the model.Time representation of time in our communications to prometheus. This (1) removes the issues with timezones in those queries going downstream and (2) completely works around this #614 issue as the parsing mechanism in prometheus can handle those times in this format.

Related to #614

@krasi-georgiev
Copy link
Contributor

As discussed this would be fixed on the server side so that clients in other languages don't hit the same problem.

@brian-brazil
Copy link
Contributor

I think using unixtime makes more sense, and greatly reduces the chances we'll hit issues compared to a more human readable format.

We're trying to kill off model, so please avoid increasing usage of it.

@jacksontj
Copy link
Contributor Author

I understand the want to reduce model usage bit this clients API is already based on it, so at this point removal of common from this specific client is a significantly larger project.

@brian-brazil
Copy link
Contributor

I'm not saying to remove existing uses right now, I'm saying let's not add more.

@jacksontj
Copy link
Contributor Author

jacksontj commented Jul 8, 2019

That change seems entirely pointless to me. At this point there are already 88 occurances of model.* in this package-- why would I take the time to copy/paste that single struct over (which BTW is also used in all the model.Value etc.) to remove 1 occurance? At this point that seems like wasted effort, not to mention duplicating the code (since we'd use both model.Time and a copy of it in the same package).

@beorn7
Copy link
Member

beorn7 commented Jul 9, 2019

@brian-brazil:

I think using unixtime makes more sense,

Do I understand this correctly that you are in general in favor of this change?

@jacksontj: return model.TimeFromUnixNano(t.UTC().UnixNano()).String() is just a very elaborate way of turning t into a string-formatted float with the unixtime as a value. I think what @brian-brazil wants is to simply replace that line with

return strconv.FormatFloat(float64(t.UnixNano())/1e9, 'f', -1, 64)

There is really no reason to involve any logic from any other Prometheus packages.

@brian-brazil
Copy link
Contributor

Do I understand this correctly that you are in general in favor of this change?

Yes.

@beorn7
Copy link
Member

beorn7 commented Jul 9, 2019

OK, cool. I'd say, let's just use the line I suggested above instead of the model.TimeFromUnixNano call, and then this is good to go. (Modulo one tiny note added below.)

api/prometheus/v1/api.go Outdated Show resolved Hide resolved
Prometheus has issues parsing RFC3339Nano timestamps if the year has more than 4 digits, in addition it is the second-pass parse attempt. Since this is a client library and the interface is a `time.Time` it makes sense that we pick the clearest simplest format-- so I propose we use the `model.Time` representation of time in our communications to prometheus. This (1) removes the issues with timezones in those queries going downstream and (2) completely works around this prometheus#614 issue as the parsing mechanism in prometheus can handle those times in this format.

Related to prometheus#614

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
@jacksontj
Copy link
Contributor Author

@beorn7 PR updated with comments, should be ready for merge

Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacksontj many thanks.
@krasi-georgiev does this work for you, too?

@krasi-georgiev
Copy link
Contributor

yep all good.

@beorn7
Copy link
Member

beorn7 commented Jul 9, 2019

Thanks everyone!

@beorn7 beorn7 merged commit b4cb89a into prometheus:master Jul 9, 2019
@jacksontj jacksontj deleted the time_formatting branch July 9, 2019 15:58
@jacksontj
Copy link
Contributor Author

@beorn7 seems that the formatTime function you have me doesn't quite work

Doing some local testing this is the output of:

	fmt.Println(startTime, formatTime(startTime))
	fmt.Println(endTime, formatTime(endTime))
-292273086-05-16 16:47:06 +0000 UTC 6795364580.679345
292277025-08-18 07:12:54.999 +0000 UTC -6795364579.680346

@jacksontj
Copy link
Contributor Author

jacksontj commented Jul 9, 2019

Here's the same on go playground: https://play.golang.org/p/qMLQcs_WG2J

It seems that going to this unix format has similar formatting issues where it won't go negative properly :/

jacksontj added a commit to jacksontj/client_golang that referenced this pull request Jul 9, 2019
…ingle int64

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>

Fixup for prometheus#617
@jacksontj
Copy link
Contributor Author

#619 has the fix :)

@beorn7
Copy link
Member

beorn7 commented Jul 9, 2019

Ooof, yeah, of course, because UnixNano is rather limited in its time range.
(Would have been the same problem if using the model package.)
Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants