MCPcopy Create free account
hub / github.com/efficientgo/e2e / NewPrometheus

Function NewPrometheus

monitoring/monitoring.go:42–91  ·  view source on GitHub ↗
(env e2e.Environment, name string, image string, flagOverride map[string]string)

Source from the content-addressed store, hash-verified

40}
41
42func NewPrometheus(env e2e.Environment, name string, image string, flagOverride map[string]string) *Prometheus {
43 if image == "" {
44 image = "quay.io/prometheus/prometheus:v2.37.0"
45 }
46 ports := map[string]int{"http": 9090}
47
48 f := env.Runnable(name).WithPorts(ports).Future()
49 config := fmt.Sprintf(`
50global:
51 external_labels:
52 prometheus: %v
53scrape_configs:
54- job_name: 'myself'
55 # Quick scrapes for test purposes.
56 scrape_interval: 1s
57 scrape_timeout: 1s
58 static_configs:
59 - targets: [%s]
60 relabel_configs:
61 - source_labels: ['__address__']
62 regex: '^.+:80$'
63 action: drop
64`, name, f.InternalEndpoint("http"))
65 if err := os.WriteFile(filepath.Join(f.Dir(), "prometheus.yml"), []byte(config), 0600); err != nil {
66 return &Prometheus{Runnable: e2e.NewFailedRunnable(name, errors.Wrap(err, "create prometheus config failed"))}
67 }
68
69 args := map[string]string{
70 "--config.file": filepath.Join(f.Dir(), "prometheus.yml"),
71 "--storage.tsdb.path": f.Dir(),
72 "--storage.tsdb.max-block-duration": "2h", // No compaction - mostly not needed for quick test.
73 "--log.level": "info",
74 "--web.listen-address": fmt.Sprintf(":%d", ports["http"]),
75 }
76 if flagOverride != nil {
77 args = e2e.MergeFlagsWithoutRemovingEmpty(args, flagOverride)
78 }
79
80 p := AsInstrumented(f.Init(e2e.StartOptions{
81 Image: image,
82 Command: e2e.NewCommandWithoutEntrypoint("prometheus", e2e.BuildArgs(args)...),
83 Readiness: e2e.NewHTTPReadinessProbe("http", "/-/ready", 200, 200),
84 User: strconv.Itoa(os.Getuid()),
85 }), "http")
86
87 return &Prometheus{
88 Runnable: p,
89 Instrumented: p,
90 }
91}
92
93func (p *Prometheus) SetConfigEncoded(config []byte) error {
94 if p.BuildErr() != nil {

Callers 1

StartFunction · 0.70

Calls 12

NewFailedRunnableFunction · 0.92
BuildArgsFunction · 0.92
NewHTTPReadinessProbeFunction · 0.92
AsInstrumentedFunction · 0.85
FutureMethod · 0.65
WithPortsMethod · 0.65
RunnableMethod · 0.65
InternalEndpointMethod · 0.65
DirMethod · 0.65
InitMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…