mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 11:48:53 +00:00
Merge pull request #1100 from metalmatze/staticconfigs
Add StaticConfigs to ServiceMonitors
This commit is contained in:
commit
3533e1c22f
7 changed files with 62 additions and 0 deletions
Documentation
example/prometheus-operator-crd
pkg
client/monitoring/v1
prometheus
|
@ -151,6 +151,7 @@ Endpoint defines a scrapeable endpoint serving Prometheus metrics.
|
|||
| honorLabels | HonorLabels chooses the metric's labels on collisions with target labels. | bool | false |
|
||||
| basicAuth | BasicAuth allow an endpoint to authenticate over basic authentication More info: https://prometheus.io/docs/operating/configuration/#endpoints | *[BasicAuth](#basicauth) | false |
|
||||
| metricRelabelings | MetricRelabelConfigs to apply to samples before ingestion. | []*[RelabelConfig](#relabelconfig) | false |
|
||||
| staticTargets | StaticTargets with targets to scrape. | []string | false |
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
|
|
|
@ -140,6 +140,11 @@ spec:
|
|||
scrapeTimeout:
|
||||
description: Timeout after which the scrape is ended
|
||||
type: string
|
||||
staticTargets:
|
||||
description: StaticTargets with targets to scrape.
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
targetPort: {}
|
||||
tlsConfig:
|
||||
description: TLSConfig specifies TLS configuration parameters.
|
||||
|
|
|
@ -532,6 +532,20 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
|
|||
},
|
||||
},
|
||||
},
|
||||
"staticTargets": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "StaticTargets with targets to scrape.",
|
||||
Type: []string{"array"},
|
||||
Items: &spec.SchemaOrArray{
|
||||
Schema: &spec.Schema{
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -332,6 +332,8 @@ type Endpoint struct {
|
|||
BasicAuth *BasicAuth `json:"basicAuth,omitempty"`
|
||||
// MetricRelabelConfigs to apply to samples before ingestion.
|
||||
MetricRelabelConfigs []*RelabelConfig `json:"metricRelabelings,omitempty"`
|
||||
// StaticTargets with targets to scrape.
|
||||
StaticTargets []string `json:"staticTargets,omitempty"`
|
||||
}
|
||||
|
||||
// BasicAuth allow an endpoint to authenticate over basic authentication
|
||||
|
|
|
@ -333,6 +333,11 @@ func (in *Endpoint) DeepCopyInto(out *Endpoint) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if in.StaticTargets != nil {
|
||||
in, out := &in.StaticTargets, &out.StaticTargets
|
||||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -211,6 +211,16 @@ func generateServiceMonitorConfig(version semver.Version, m *v1.ServiceMonitor,
|
|||
|
||||
cfg = addTLStoYaml(cfg, ep.TLSConfig)
|
||||
|
||||
if ep.StaticTargets != nil {
|
||||
cfg = append(cfg, yaml.MapItem{
|
||||
Key: "static_configs",
|
||||
Value: yaml.MapItem{
|
||||
Key: "targets",
|
||||
Value: ep.StaticTargets,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if ep.BearerTokenFile != "" {
|
||||
cfg = append(cfg, yaml.MapItem{Key: "bearer_token_file", Value: ep.BearerTokenFile})
|
||||
}
|
||||
|
|
|
@ -312,5 +312,30 @@ func makeServiceMonitors() map[string]*monitoringv1.ServiceMonitor {
|
|||
},
|
||||
}
|
||||
|
||||
res["servicemonitor5"] = &monitoringv1.ServiceMonitor{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "testservicemonitor5",
|
||||
Namespace: "default",
|
||||
Labels: map[string]string{
|
||||
"group": "group4",
|
||||
},
|
||||
},
|
||||
Spec: monitoringv1.ServiceMonitorSpec{
|
||||
Endpoints: []monitoringv1.Endpoint{
|
||||
{
|
||||
Port: "web",
|
||||
Interval: "30s",
|
||||
Path: "/federate",
|
||||
Params: map[string][]string{"metrics[]": {"{__name__=~\"job:.*\"}"}},
|
||||
StaticTargets: []string{
|
||||
"source-prometheus-1:9090",
|
||||
"source-prometheus-2:9090",
|
||||
"source-prometheus-3:9090",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue