feat: prometheus 2.53.4 support · GoogleCloudPlatform/prometheus-engine@4a32e4b (original) (raw)
`@@ -69,6 +69,7 @@ import (
`
69
69
`"github.com/prometheus/prometheus/promql/parser"
`
70
70
`"github.com/prometheus/prometheus/rules"
`
71
71
`"github.com/prometheus/prometheus/storage"
`
``
72
`+
"github.com/prometheus/prometheus/util/annotations"
`
72
73
`"github.com/prometheus/prometheus/util/strutil"
`
73
74
`)
`
74
75
``
`@@ -135,6 +136,12 @@ func main() {
`
135
136
`queryHistogram,
`
136
137
` )
`
137
138
``
``
139
`+
sdMetrics, err := discovery.CreateAndRegisterSDMetrics(reg)
`
``
140
`+
if err != nil {
`
``
141
`+
_ = level.Error(logger).Log("msg", "failed to register service discovery metrics", "err", err)
`
``
142
`+
os.Exit(1)
`
``
143
`+
}
`
``
144
+
138
145
`// The rule-evaluator version is identical to the export library version for now, so
`
139
146
`// we reuse that constant.
`
140
147
`version, err := export.Version()
`
`@@ -198,7 +205,7 @@ func main() {
`
198
205
`destination := export.NewStorage(exporter)
`
199
206
``
200
207
`ctxDiscover, cancelDiscover := context.WithCancel(ctx)
`
201
``
`-
discoveryManager := discovery.NewManager(ctxDiscover, log.With(logger, "component", "discovery manager notify"), discovery.Name("notify"))
`
``
208
`+
discoveryManager := discovery.NewManager(ctxDiscover, log.With(logger, "component", "discovery manager notify"), reg, sdMetrics, discovery.Name("notify"))
`
202
209
`notifierOptions := notifier.Options{
`
203
210
`Registerer: reg,
`
204
211
`QueueCapacity: defaultEvaluatorOpts.QueueCapacity,
`
`@@ -818,21 +825,21 @@ func convertModelToPromQLValue(val model.Value) (parser.Value, error) {
`
818
825
` }
`
819
826
`}
`
820
827
``
821
``
`-
// Converting v1.Warnings to storage.Warnings.
`
822
``
`-
func convertV1WarningsToStorageWarnings(w v1.Warnings) storage.Warnings {
`
823
``
`-
warnings := make(storage.Warnings, len(w))
`
824
``
`-
for i, warning := range w {
`
825
``
`-
warnings[i] = errors.New(warning)
`
``
828
`+
// Converting v1.Warnings to annotations.Annotations.
`
``
829
`+
func convertV1WarningsToAnnotations(w v1.Warnings) annotations.Annotations {
`
``
830
`+
a := annotations.New()
`
``
831
`+
for _, warning := range w {
`
``
832
`+
a.Add(errors.New(warning))
`
826
833
` }
`
827
``
`-
return warnings
`
``
834
`+
return *a
`
828
835
`}
`
829
836
``
830
837
`// listSeriesSet implements the storage.SeriesSet interface on top a list of listSeries.
`
831
838
`type listSeriesSet struct {
`
832
839
`m promql.Matrix
`
833
840
`idx int
`
834
841
`err error
`
835
``
`-
warnings storage.Warnings
`
``
842
`+
warnings annotations.Annotations
`
836
843
`}
`
837
844
``
838
845
`// Next advances the iterator and returns true if there's data to consume.
`
`@@ -852,12 +859,12 @@ func (ss *listSeriesSet) Err() error {
`
852
859
`}
`
853
860
``
854
861
`// Warnings returns warnings encountered while iterating.
`
855
``
`-
func (ss *listSeriesSet) Warnings() storage.Warnings {
`
``
862
`+
func (ss *listSeriesSet) Warnings() annotations.Annotations {
`
856
863
`return ss.warnings
`
857
864
`}
`
858
865
``
859
866
`func newListSeriesSet(v promql.Matrix, err error, w v1.Warnings) *listSeriesSet {
`
860
``
`-
return &listSeriesSet{m: v, idx: -1, err: err, warnings: convertV1WarningsToStorageWarnings(w)}
`
``
867
`+
return &listSeriesSet{m: v, idx: -1, err: err, warnings: convertV1WarningsToAnnotations(w)}
`
861
868
`}
`
862
869
``
863
870
`// convertMatchersToPromQL converts []*labels.Matcher to a PromQL query.
`
`@@ -878,10 +885,9 @@ type queryStorage struct {
`
878
885
`}
`
879
886
``
880
887
`// Querier provides querying access over time series data of a fixed time range.
`
881
``
`-
func (s *queryStorage) Querier(ctx context.Context, mint, maxt int64) (storage.Querier, error) {
`
``
888
`+
func (s *queryStorage) Querier(mint, maxt int64) (storage.Querier, error) {
`
882
889
`db := &queryAccess{
`
883
890
`api: s.api,
`
884
``
`-
ctx: ctx,
`
885
891
`mint: mint / 1000, // divide by 1000 to convert milliseconds to seconds.
`
886
892
`maxt: maxt / 1000,
`
887
893
`query: QueryFunc,
`
`@@ -896,12 +902,11 @@ type queryAccess struct {
`
896
902
`api v1.API
`
897
903
`mint int64
`
898
904
`maxt int64
`
899
``
`-
ctx context.Context
`
900
905
`query func(context.Context, string, time.Time, v1.API) (parser.Value, v1.Warnings, error)
`
901
906
`}
`
902
907
``
903
908
`// Select returns a set of series that matches the given label matchers and time range.
`
904
``
`-
func (db *queryAccess) Select(sort bool, hints *storage.SelectHints, matchers ...*labels.Matcher) storage.SeriesSet {
`
``
909
`+
func (db *queryAccess) Select(ctx context.Context, sort bool, hints *storage.SelectHints, matchers ...*labels.Matcher) storage.SeriesSet {
`
905
910
`if sort || hints != nil {
`
906
911
`return newListSeriesSet(nil, errors.New("sorting series and select hints are not supported"), nil)
`
907
912
` }
`
`@@ -913,7 +918,7 @@ func (db *queryAccess) Select(sort bool, hints *storage.SelectHints, matchers ..
`
913
918
``
914
919
`queryExpression, filteredMatchers := convertMatchersToPromQL(matchers, duration)
`
915
920
`maxt := time.Unix(db.maxt, 0)
`
916
``
`-
v, warnings, err := db.query(db.ctx, queryExpression, maxt, db.api)
`
``
921
`+
v, warnings, err := db.query(ctx, queryExpression, maxt, db.api)
`
917
922
`if err != nil {
`
918
923
`return newListSeriesSet(nil, err, warnings)
`
919
924
` }
`