2019-11-19 01:33:30 -08:00
|
|
|
// Copyright 2019 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package exemplar
|
|
|
|
|
2021-11-08 06:23:17 -08:00
|
|
|
import "github.com/prometheus/prometheus/model/labels"
|
2019-11-19 01:33:30 -08:00
|
|
|
|
lint: Revamp our linting rules, mostly around doc comments
Several things done here:
- Set `max-issues-per-linter` to 0 so that we actually see all linter
warnings and not just 50 per linter. (As we also set
`max-same-issues` to 0, I assume this was the intention from the
beginning.)
- Stop using the golangci-lint default excludes (by setting
`exclude-use-default: false`. Those are too generous and don't match
our style conventions. (I have re-added some of the excludes
explicitly in this commit. See below.)
- Re-add the `errcheck` exclusion we have used so far via the
defaults.
- Exclude the signature requirement `govet` has for `Seek` methods
because we use non-standard `Seek` methods a lot. (But we keep other
requirements, while the default excludes completely disabled the
check for common method segnatures.)
- Exclude warnings about missing doc comments on exported symbols. (We
used to be pretty adamant about doc comments, but stopped that at
some point in the past. By now, we have about 500 missing doc
comments. We may consider reintroducing this check, but that's
outside of the scope of this commit. The default excludes of
golangci-lint essentially ignore doc comments completely.)
- By stop using the default excludes, we now get warnings back on
malformed doc comments. That's the most impactful change in this
commit. It does not enforce doc comments (again), but _if_ there is
a doc comment, it has to have the recommended form. (Most of the
changes in this commit are fixing this form.)
- Improve wording/spelling of some comments in .golangci.yml, and
remove an outdated comment.
- Leave `package-comments` inactive, but add a TODO asking if we
should change that.
- Add a new sub-linter `comment-spacings` (and fix corresponding
comments), which avoids missing spaces after the leading `//`.
Signed-off-by: beorn7 <beorn@grafana.com>
2024-08-22 04:59:36 -07:00
|
|
|
// ExemplarMaxLabelSetLength is defined by OpenMetrics: "The combined length of
|
|
|
|
// the label names and values of an Exemplar's LabelSet MUST NOT exceed 128
|
|
|
|
// UTF-8 characters."
|
2021-05-06 13:53:52 -07:00
|
|
|
// https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#exemplars
|
|
|
|
const ExemplarMaxLabelSetLength = 128
|
|
|
|
|
2019-11-19 01:33:30 -08:00
|
|
|
// Exemplar is additional information associated with a time series.
|
|
|
|
type Exemplar struct {
|
2021-05-06 13:53:52 -07:00
|
|
|
Labels labels.Labels `json:"labels"`
|
|
|
|
Value float64 `json:"value"`
|
|
|
|
Ts int64 `json:"timestamp"`
|
2019-11-19 01:33:30 -08:00
|
|
|
HasTs bool
|
|
|
|
}
|
2021-03-16 02:47:45 -07:00
|
|
|
|
|
|
|
type QueryResult struct {
|
|
|
|
SeriesLabels labels.Labels `json:"seriesLabels"`
|
|
|
|
Exemplars []Exemplar `json:"exemplars"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Equals compares if the exemplar e is the same as e2. Note that if HasTs is false for
|
|
|
|
// both exemplars then the timestamps will be ignored for the comparison. This can come up
|
|
|
|
// when an exemplar is exported without it's own timestamp, in which case the scrape timestamp
|
|
|
|
// is assigned to the Ts field. However we still want to treat the same exemplar, scraped without
|
|
|
|
// an exported timestamp, as a duplicate of itself for each subsequent scrape.
|
|
|
|
func (e Exemplar) Equals(e2 Exemplar) bool {
|
|
|
|
if !labels.Equal(e.Labels, e2.Labels) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e.HasTs || e2.HasTs) && e.Ts != e2.Ts {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return e.Value == e2.Value
|
|
|
|
}
|
2023-11-24 06:38:35 -08:00
|
|
|
|
lint: Revamp our linting rules, mostly around doc comments
Several things done here:
- Set `max-issues-per-linter` to 0 so that we actually see all linter
warnings and not just 50 per linter. (As we also set
`max-same-issues` to 0, I assume this was the intention from the
beginning.)
- Stop using the golangci-lint default excludes (by setting
`exclude-use-default: false`. Those are too generous and don't match
our style conventions. (I have re-added some of the excludes
explicitly in this commit. See below.)
- Re-add the `errcheck` exclusion we have used so far via the
defaults.
- Exclude the signature requirement `govet` has for `Seek` methods
because we use non-standard `Seek` methods a lot. (But we keep other
requirements, while the default excludes completely disabled the
check for common method segnatures.)
- Exclude warnings about missing doc comments on exported symbols. (We
used to be pretty adamant about doc comments, but stopped that at
some point in the past. By now, we have about 500 missing doc
comments. We may consider reintroducing this check, but that's
outside of the scope of this commit. The default excludes of
golangci-lint essentially ignore doc comments completely.)
- By stop using the default excludes, we now get warnings back on
malformed doc comments. That's the most impactful change in this
commit. It does not enforce doc comments (again), but _if_ there is
a doc comment, it has to have the recommended form. (Most of the
changes in this commit are fixing this form.)
- Improve wording/spelling of some comments in .golangci.yml, and
remove an outdated comment.
- Leave `package-comments` inactive, but add a TODO asking if we
should change that.
- Add a new sub-linter `comment-spacings` (and fix corresponding
comments), which avoids missing spaces after the leading `//`.
Signed-off-by: beorn7 <beorn@grafana.com>
2024-08-22 04:59:36 -07:00
|
|
|
// Compare first timestamps, then values, then labels.
|
2023-11-24 06:38:35 -08:00
|
|
|
func Compare(a, b Exemplar) int {
|
|
|
|
if a.Ts < b.Ts {
|
|
|
|
return -1
|
|
|
|
} else if a.Ts > b.Ts {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
if a.Value < b.Value {
|
|
|
|
return -1
|
|
|
|
} else if a.Value > b.Value {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return labels.Compare(a.Labels, b.Labels)
|
|
|
|
}
|