Rename wrapper and use struct instead of map for type/unit tracking
CI / Go tests (push) Waiting to run
Details
CI / More Go tests (push) Waiting to run
Details
CI / Go tests with previous Go version (push) Waiting to run
Details
CI / UI tests (push) Waiting to run
Details
CI / Go tests on Windows (push) Waiting to run
Details
CI / Mixins tests (push) Waiting to run
Details
CI / Build Prometheus for common architectures (0) (push) Waiting to run
Details
CI / Build Prometheus for common architectures (1) (push) Waiting to run
Details
CI / Build Prometheus for common architectures (2) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (0) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (1) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (10) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (11) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (2) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (3) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (4) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (5) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (6) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (7) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (8) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (9) (push) Waiting to run
Details
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
Details
CI / Check generated parser (push) Waiting to run
Details
CI / golangci-lint (push) Waiting to run
Details
CI / fuzzing (push) Waiting to run
Details
CI / codeql (push) Waiting to run
Details
CI / Publish main branch artifacts (push) Blocked by required conditions
Details
CI / Publish release artefacts (push) Blocked by required conditions
Details
CI / Publish UI on npm Registry (push) Blocked by required conditions
Details
CI / Go tests (push) Waiting to run
Details
CI / More Go tests (push) Waiting to run
Details
CI / Go tests with previous Go version (push) Waiting to run
Details
CI / UI tests (push) Waiting to run
Details
CI / Go tests on Windows (push) Waiting to run
Details
CI / Mixins tests (push) Waiting to run
Details
CI / Build Prometheus for common architectures (0) (push) Waiting to run
Details
CI / Build Prometheus for common architectures (1) (push) Waiting to run
Details
CI / Build Prometheus for common architectures (2) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (0) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (1) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (10) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (11) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (2) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (3) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (4) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (5) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (6) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (7) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (8) (push) Waiting to run
Details
CI / Build Prometheus for all architectures (9) (push) Waiting to run
Details
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
Details
CI / Check generated parser (push) Waiting to run
Details
CI / golangci-lint (push) Waiting to run
Details
CI / fuzzing (push) Waiting to run
Details
CI / codeql (push) Waiting to run
Details
CI / Publish main branch artifacts (push) Blocked by required conditions
Details
CI / Publish release artefacts (push) Blocked by required conditions
Details
CI / Publish UI on npm Registry (push) Blocked by required conditions
Details
Signed-off-by: Carrie Edwards <edwrdscarrie@gmail.com>
This commit is contained in:
parent
67971622ba
commit
9f9e408405
|
@ -785,7 +785,7 @@ func main() {
|
||||||
|
|
||||||
var wrappedStorage storage.Storage = localStorage
|
var wrappedStorage storage.Storage = localStorage
|
||||||
if cfg.scrape.EnableTypeAndUnitLabels {
|
if cfg.scrape.EnableTypeAndUnitLabels {
|
||||||
wrappedStorage = storage.AnnotatingStorage(localStorage)
|
wrappedStorage = storage.TypeAndUnitMismatchStorage(localStorage)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -3722,7 +3722,7 @@ func TestTypeUnitMismatchAnnotations(t *testing.T) {
|
||||||
store := promqltest.LoadedStorage(t, "load 1m\n"+strings.TrimSpace(testCase.data))
|
store := promqltest.LoadedStorage(t, "load 1m\n"+strings.TrimSpace(testCase.data))
|
||||||
var wrappedStorage storage.Storage = store
|
var wrappedStorage storage.Storage = store
|
||||||
if testCase.typeAndUnitLabelsEnabled {
|
if testCase.typeAndUnitLabelsEnabled {
|
||||||
wrappedStorage = storage.AnnotatingStorage(store)
|
wrappedStorage = storage.TypeAndUnitMismatchStorage(store)
|
||||||
}
|
}
|
||||||
t.Cleanup(func() { _ = store.Close() })
|
t.Cleanup(func() { _ = store.Close() })
|
||||||
|
|
||||||
|
|
|
@ -21,63 +21,61 @@ import (
|
||||||
"github.com/prometheus/prometheus/util/annotations"
|
"github.com/prometheus/prometheus/util/annotations"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AnnotatingStorage wraps given storage and tracks type and unit
|
// TypeAndUnitMismatchStorage wraps given storage and tracks type and unit
|
||||||
// labels across series. It will produce an info annotation if there
|
// labels across series. It will produce an info annotation if there
|
||||||
// is a mismatch between type or unit in series with the same name.
|
// is a mismatch between type or unit in series with the same name.
|
||||||
func AnnotatingStorage(s Storage) Storage {
|
func TypeAndUnitMismatchStorage(s Storage) Storage {
|
||||||
return &annotatingStorage{
|
return &typeAndUnitMismatchStorage{
|
||||||
Storage: s,
|
Storage: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type annotatingStorage struct {
|
type typeAndUnitMismatchStorage struct {
|
||||||
Storage
|
Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
type annotatingQuerier struct {
|
type typeAndUnitMismatchQuerier struct {
|
||||||
Querier
|
Querier
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *annotatingStorage) Querier(mint, maxt int64) (Querier, error) {
|
func (s *typeAndUnitMismatchStorage) Querier(mint, maxt int64) (Querier, error) {
|
||||||
q, err := s.Storage.Querier(mint, maxt)
|
q, err := s.Storage.Querier(mint, maxt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &annotatingQuerier{
|
return &typeAndUnitMismatchQuerier{
|
||||||
Querier: q,
|
Querier: q,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *annotatingQuerier) Select(ctx context.Context, sort bool, hints *SelectHints, matchers ...*labels.Matcher) SeriesSet {
|
func (q *typeAndUnitMismatchQuerier) Select(ctx context.Context, sort bool, hints *SelectHints, matchers ...*labels.Matcher) SeriesSet {
|
||||||
ss := q.Querier.Select(ctx, sort, hints, matchers...)
|
ss := q.Querier.Select(ctx, sort, hints, matchers...)
|
||||||
return AnnotatingSeriesSet(ss)
|
return TypeAndUnitMismatchSeriesSet(ss)
|
||||||
}
|
}
|
||||||
|
|
||||||
type annotatingSeriesSet struct {
|
type typeAndUnitInfo struct {
|
||||||
|
typ string
|
||||||
|
unit string
|
||||||
|
}
|
||||||
|
|
||||||
|
type typeAndUnitMismatchSeriesSet struct {
|
||||||
SeriesSet
|
SeriesSet
|
||||||
|
|
||||||
seen map[string]struct {
|
prev *typeAndUnitInfo
|
||||||
Type string
|
|
||||||
Unit string
|
|
||||||
}
|
|
||||||
annotations annotations.Annotations
|
annotations annotations.Annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
func AnnotatingSeriesSet(s SeriesSet) SeriesSet {
|
func TypeAndUnitMismatchSeriesSet(s SeriesSet) SeriesSet {
|
||||||
return &annotatingSeriesSet{
|
return &typeAndUnitMismatchSeriesSet{
|
||||||
SeriesSet: s,
|
SeriesSet: s,
|
||||||
seen: make(map[string]struct {
|
|
||||||
Type string
|
|
||||||
Unit string
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *annotatingSeriesSet) At() Series {
|
func (s *typeAndUnitMismatchSeriesSet) At() Series {
|
||||||
return s.SeriesSet.At()
|
return s.SeriesSet.At()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *annotatingSeriesSet) Next() bool {
|
func (s *typeAndUnitMismatchSeriesSet) Next() bool {
|
||||||
if !s.SeriesSet.Next() {
|
if !s.SeriesSet.Next() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -87,29 +85,29 @@ func (s *annotatingSeriesSet) Next() bool {
|
||||||
mType := series.Labels().Get("__type__")
|
mType := series.Labels().Get("__type__")
|
||||||
mUnit := series.Labels().Get("__unit__")
|
mUnit := series.Labels().Get("__unit__")
|
||||||
|
|
||||||
if prev, ok := s.seen[metric]; ok {
|
if s.prev == nil {
|
||||||
if prev.Type != mType || prev.Unit != mUnit {
|
s.prev = &typeAndUnitInfo{
|
||||||
if prev.Type == "unknown" || mType == "unknown" {
|
typ: mType,
|
||||||
if prev.Type == "unknown" && mType != "unknown" {
|
unit: mUnit,
|
||||||
s.seen[metric] = struct {
|
|
||||||
Type string
|
|
||||||
Unit string
|
|
||||||
}{Type: mType, Unit: mUnit}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
s.annotations.Add(fmt.Errorf("%w %q", annotations.MismatchedTypeOrUnitInfo, metric))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
s.seen[metric] = struct {
|
if s.prev.typ != mType || s.prev.unit != mUnit {
|
||||||
Type string
|
// Skip annotation if either type is "unknown" - this allows unknown to coexist with known types
|
||||||
Unit string
|
if s.prev.typ == "unknown" || mType == "unknown" {
|
||||||
}{Type: mType, Unit: mUnit}
|
// Update to the known type if we have one
|
||||||
|
if s.prev.typ == "unknown" && mType != "unknown" {
|
||||||
|
s.prev.typ = mType
|
||||||
|
s.prev.unit = mUnit
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
s.annotations.Add(fmt.Errorf("%w for metric %q", annotations.MismatchedTypeOrUnitInfo, metric))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *annotatingSeriesSet) Warnings() annotations.Annotations {
|
func (s *typeAndUnitMismatchSeriesSet) Warnings() annotations.Annotations {
|
||||||
got := s.SeriesSet.Warnings()
|
got := s.SeriesSet.Warnings()
|
||||||
if got == nil {
|
if got == nil {
|
||||||
got = make(annotations.Annotations)
|
got = make(annotations.Annotations)
|
Loading…
Reference in New Issue