@@ -11,9 +11,12 @@ import (
11
11
"errors"
12
12
"fmt"
13
13
"io"
14
+ "maps"
14
15
"net/http"
15
16
"os"
16
17
"path/filepath"
18
+ "slices"
19
+ "strings"
17
20
"time"
18
21
19
22
"github.com/derailed/popeye/internal"
@@ -408,17 +411,41 @@ func (p *Popeye) dumpPrometheus(ctx context.Context, asset string, persist bool)
408
411
instance += "-" + * p .flags .InClusterName
409
412
}
410
413
414
+ validFormats := map [string ]expfmt.Format {
415
+ "protocompact" : expfmt .NewFormat (expfmt .TypeProtoCompact ),
416
+ "protodelim" : expfmt .NewFormat (expfmt .TypeProtoDelim ),
417
+ "prototext" : expfmt .NewFormat (expfmt .TypeProtoText ),
418
+ "textplain" : expfmt .NewFormat (expfmt .TypeTextPlain ),
419
+ "openmetrics" : expfmt .NewFormat (expfmt .TypeOpenMetrics ),
420
+ }
421
+
422
+ format := validFormats ["textplain" ]
423
+ if config .IsStrSet (p .flags .PushGateway .Format ) {
424
+ if f , exists := validFormats [* p .flags .PushGateway .Format ]; exists {
425
+ format = f
426
+ } else {
427
+ validFormatsList := slices .Collect (maps .Keys (validFormats ))
428
+ return fmt .Errorf (
429
+ "'--push-gtwy-format' must be one of: %s" ,
430
+ strings .Join (validFormatsList , ", " ),
431
+ )
432
+ }
433
+ }
434
+
411
435
pusher := p .builder .ToPrometheus (
412
436
p .flags .PushGateway ,
413
437
instance ,
414
438
p .client ().ActiveNamespace (),
415
439
asset ,
416
440
p .codes .Glossary ,
417
441
)
418
- // Enable saving to file
442
+
443
+ pusher = pusher .Format (format )
444
+ // Persist is used when prometheus output format is selected...
445
+ // ...custom p.Do func intercepts push output and prints it...
446
+ // ...to stdout, while replying to pusher with stub HTTP 200
419
447
if persist {
420
448
pusher = pusher .Client (p )
421
- pusher = pusher .Format (expfmt .NewFormat (expfmt .TypeTextPlain ))
422
449
}
423
450
424
451
return pusher .AddContext (ctx )
0 commit comments