@@ -7,6 +7,7 @@ package clusterstats
77
88import (
99 "context"
10+ "strings"
1011 "time"
1112
1213 "github.com/cockroachdb/cockroach/pkg/roachprod/logger"
@@ -95,8 +96,8 @@ func (cs *clusterStatCollector) CollectPoint(
9596 if err != nil {
9697 return nil , err
9798 }
98- if len ( warnings ) > 0 {
99- return nil , errors . Newf ( "found warnings querying prometheus: %s" , warnings )
99+ if err := handlePromWarnings ( ctx , l , q , warnings ); err != nil {
100+ return nil , err
100101 }
101102
102103 fromVec := fromVal .(model.Vector )
@@ -169,8 +170,8 @@ func (cs *clusterStatCollector) CollectInterval(
169170 if err != nil {
170171 return nil , err
171172 }
172- if len ( warnings ) > 0 {
173- return nil , errors . Newf ( "found warnings querying prometheus: %s" , warnings )
173+ if err := handlePromWarnings ( ctx , l , q , warnings ); err != nil {
174+ return nil , err
174175 }
175176
176177 fromMatrixTagged := fromVal .(model.Matrix )
@@ -210,3 +211,38 @@ func (cs *clusterStatCollector) CollectInterval(
210211
211212 return result , nil
212213}
214+
215+ // handlePromWarnings classifies the annotations returned alongside a Prometheus
216+ // query result. Prometheus annotations come in two flavors, identified by the
217+ // prefix on the wire:
218+ //
219+ // - "PromQL info: ..." annotations are informational (e.g. a counter-named
220+ // metric lint emitted since Prometheus 2.53). The query result is still
221+ // valid; we log these and continue.
222+ // - "PromQL warning: ..." annotations indicate a likely problem with the
223+ // query (e.g. mismatched histogram operations) where Prometheus may have
224+ // dropped result elements. Any other unrecognized annotation (e.g. legacy
225+ // remote-read warnings, which predate the PromQL annotation system) is
226+ // treated the same way to preserve the prior fail-loud behavior.
227+ //
228+ // The returned error, if any, matches the format used historically so existing
229+ // callers and log scrapers see the same string.
230+ func handlePromWarnings (
231+ ctx context.Context , l * logger.Logger , q string , warnings promv1.Warnings ,
232+ ) error {
233+ if len (warnings ) == 0 {
234+ return nil
235+ }
236+ var serious promv1.Warnings
237+ for _ , w := range warnings {
238+ if strings .HasPrefix (w , "PromQL info:" ) {
239+ l .PrintfCtx (ctx , "prometheus info querying %q: %s" , q , w )
240+ continue
241+ }
242+ serious = append (serious , w )
243+ }
244+ if len (serious ) == 0 {
245+ return nil
246+ }
247+ return errors .Newf ("found warnings querying prometheus: %s" , serious )
248+ }
0 commit comments