-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fix invalid start/end params in series api #2015
Conversation
Signed-off-by: yeya24 <yb532204897@gmail.com>
@@ -663,9 +666,9 @@ func (p *PrometheusStore) seriesLabels(ctx context.Context, matchers []storepb.L | |||
} | |||
|
|||
q.Add("match[]", metric) | |||
q.Add("start", formatTime(timestamp.Time(startTime))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if there is a better way to format the timestamp from int64 directly? I am not quite familiar with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like time.RFC3339Nano is supported so maybe startTime.Format(time.RFC3339Nano)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried several times but still doesn't work, the generated timestamp is not valid in Prometheus side. Are you OK with the current implementation? @bwplotka
I think there is no big difference between the two ways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be super nice to make it valid, I can't see reason why it would not work:
The code is literally this:
func parseTime(s string) (time.Time, error) {
if t, err := strconv.ParseFloat(s, 64); err == nil {
s, ns := math.Modf(t)
ns = math.Round(ns*1000) / 1000
return time.Unix(int64(s), int64(ns*float64(time.Second))), nil
}
if t, err := time.Parse(time.RFC3339Nano, s); err == nil {
return t, nil
}
// Stdlib's time parser can only handle 4 digit years. As a workaround until
// that is fixed we want to at least support our own boundary times.
// Context: https://github.com/prometheus/client_golang/issues/614
// Upstream issue: https://github.com/golang/go/issues/20555
switch s {
case minTimeFormatted:
return minTime, nil
case maxTimeFormatted:
return maxTime, nil
}
return time.Time{}, errors.Errorf("cannot parse %q to a valid timestamp", s)
}
so you can test even locally for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yeya24 maybe let's add another test-case which would test this out so that we would know for sure if this is reproducible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GiedriusS Added one. From that testcase, using timestamp.Time(startTime).Format(time.RFC3339Nano)
will fail. I think it is OK to use the current one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unfortunate that Golang's stdlib cannot parse all of the values that one can format in time.RFC3339Nano
: golang/go#20555. However, I'd vote for @bwplotka's suggestion here: maybe lets just not add these parameters if they haven't been specified? Prometheus then handles all of this accordingly. I think we'd avoid more problems down the line. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out! However, I am still not sure about how to handle all the cases.
Currently the minTime of sidecar can be configured via a flag. But its default value "0000-01-01T00:00:00Z"
is invalid at the Prometheus side. How to avoid this case? And what if users set some other time that cannot be parsed as well? @GiedriusS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
One suggestion and LGTM! Thanks for fixing 👍
@@ -663,9 +666,9 @@ func (p *PrometheusStore) seriesLabels(ctx context.Context, matchers []storepb.L | |||
} | |||
|
|||
q.Add("match[]", metric) | |||
q.Add("start", formatTime(timestamp.Time(startTime))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like time.RFC3339Nano is supported so maybe startTime.Format(time.RFC3339Nano)
?
Signed-off-by: yeya24 <yb532204897@gmail.com>
I've built this PR and unfortunately it did not fix the problem for me. Grafana queries that populate variables returned more items that they should have. |
Hi, @sylr Recent 30 min of label_values(up, instance) Several days ago data of label_values(up, instance). The result is different from the previous one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some digging I believe we should merge and release this version. @yeya24 is right, formatting to float actually makes more sense. See: prometheus/client_golang#614
Thank you @yeya24 for quick reaction! |
Ok so I'd like to correct my previous comment as I thought the problem was located only on the querier, it was not according to my new observations:
|
* fix invalid start/end params in series api Signed-off-by: yeya24 <yb532204897@gmail.com> * add testcase for serieslabels time range Signed-off-by: yeya24 <yb532204897@gmail.com>
* Fix invalid start/end params in series api (#2015) * fix invalid start/end params in series api Signed-off-by: yeya24 <yb532204897@gmail.com> * add testcase for serieslabels time range Signed-off-by: yeya24 <yb532204897@gmail.com> * Revert "Fix revert metric name regression (#2005)" This reverts commit 7d16852. * Cut release 0.10.1 Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> Co-authored-by: Ben Ye <yb532204897@gmail.com>
Signed-off-by: yeya24 yb532204897@gmail.com
Changes
Fixes #2011
cc @IKSIN @GiedriusS
Verification
I have already tested both in Grafana and local API request.