1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 11:48:53 +00:00

Add StaticConfigs to ServiceMonitors

This commit is contained in:
Matthias Loibl 2018-03-16 17:50:15 +01:00
parent 0ae7f5ddf9
commit 1780729b5a
No known key found for this signature in database
GPG key ID: B1C7DF661ABB2C1A
7 changed files with 129 additions and 1 deletions
Documentation
example/prometheus-operator-crd
pkg

View file

@ -29,6 +29,7 @@ This Document documents the types introduced by the Prometheus Operator to be co
* [ServiceMonitor](#servicemonitor)
* [ServiceMonitorList](#servicemonitorlist)
* [ServiceMonitorSpec](#servicemonitorspec)
* [StaticConfig](#staticconfig)
* [StorageSpec](#storagespec)
* [TLSConfig](#tlsconfig)
@ -151,6 +152,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 |
| staticConfigs | StaticConfigs with targets to scrape. | *[StaticConfig](#staticconfig) | false |
[Back to TOC](#table-of-contents)
@ -326,6 +328,16 @@ ServiceMonitorSpec contains specification parameters for a ServiceMonitor.
[Back to TOC](#table-of-contents)
## StaticConfig
StaticConfig allows to specify a set of targets and parameters describing how to scrape them. More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#<static_config>
| Field | Description | Scheme | Required |
| ----- | ----------- | ------ | -------- |
| targets | | []string | true |
[Back to TOC](#table-of-contents)
## StorageSpec
StorageSpec defines the configured storage for a group Prometheus servers.

View file

@ -140,6 +140,16 @@ spec:
scrapeTimeout:
description: Timeout after which the scrape is ended
type: string
staticConfigs:
description: 'StaticConfig allows to specify a set of targets
and parameters describing how to scrape them. More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#<static_config>'
properties:
targets:
items:
type: string
type: array
required:
- targets
targetPort: {}
tlsConfig:
description: TLSConfig specifies TLS configuration parameters.

View file

@ -532,11 +532,17 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
},
},
},
"staticConfigs": {
SchemaProps: spec.SchemaProps{
Description: "StaticConfigs with targets to scrape.",
Ref: ref("github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.StaticConfig"),
},
},
},
},
},
Dependencies: []string{
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.BasicAuth", "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.RelabelConfig", "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.TLSConfig", "k8s.io/apimachinery/pkg/util/intstr.IntOrString"},
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.BasicAuth", "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.RelabelConfig", "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.StaticConfig", "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.TLSConfig", "k8s.io/apimachinery/pkg/util/intstr.IntOrString"},
},
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.NamespaceSelector": {
Schema: spec.Schema{
@ -1301,6 +1307,30 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
Dependencies: []string{
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.Endpoint", "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.NamespaceSelector", "k8s.io/apimachinery/pkg/apis/meta/v1.LabelSelector"},
},
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.StaticConfig": {
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "StaticConfig allows to specify a set of targets and parameters describing how to scrape them. More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#<static_config>",
Properties: map[string]spec.Schema{
"targets": {
SchemaProps: spec.SchemaProps{
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "",
},
},
},
},
},
},
Required: []string{"targets"},
},
},
Dependencies: []string{},
},
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.StorageSpec": {
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{

View file

@ -332,6 +332,15 @@ type Endpoint struct {
BasicAuth *BasicAuth `json:"basicAuth,omitempty"`
// MetricRelabelConfigs to apply to samples before ingestion.
MetricRelabelConfigs []*RelabelConfig `json:"metricRelabelings,omitempty"`
// StaticConfigs with targets to scrape.
StaticConfigs *StaticConfig `json:"staticConfigs,omitempty"`
}
// StaticConfig allows to specify a set of targets and parameters describing how to scrape them.
// More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#<static_config>
// +k8s:openapi-gen=true
type StaticConfig struct {
Targets []string `json:"targets"`
}
// BasicAuth allow an endpoint to authenticate over basic authentication

View file

@ -333,6 +333,15 @@ func (in *Endpoint) DeepCopyInto(out *Endpoint) {
}
}
}
if in.StaticConfigs != nil {
in, out := &in.StaticConfigs, &out.StaticConfigs
if *in == nil {
*out = nil
} else {
*out = new(StaticConfig)
(*in).DeepCopyInto(*out)
}
}
return
}
@ -764,6 +773,27 @@ func (in *ServiceMonitorSpec) DeepCopy() *ServiceMonitorSpec {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StaticConfig) DeepCopyInto(out *StaticConfig) {
*out = *in
if in.Targets != nil {
in, out := &in.Targets, &out.Targets
*out = make([]string, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StaticConfig.
func (in *StaticConfig) DeepCopy() *StaticConfig {
if in == nil {
return nil
}
out := new(StaticConfig)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StorageSpec) DeepCopyInto(out *StorageSpec) {
*out = *in

View file

@ -211,6 +211,11 @@ func generateServiceMonitorConfig(version semver.Version, m *v1.ServiceMonitor,
cfg = addTLStoYaml(cfg, ep.TLSConfig)
if ep.StaticConfigs != nil {
fmt.Printf("%+v\n", ep.StaticConfigs)
cfg = append(cfg, yaml.MapItem{Key: "static_configs", Value: ep.StaticConfigs})
}
if ep.BearerTokenFile != "" {
cfg = append(cfg, yaml.MapItem{Key: "bearer_token_file", Value: ep.BearerTokenFile})
}

View file

@ -312,5 +312,37 @@ 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{
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
"group": "group4",
"group3": "group5",
},
},
Endpoints: []monitoringv1.Endpoint{{
Port: "web",
Interval: "30s",
Path: "/federate",
Params: map[string][]string{"metrics[]": {"{__name__=~\"job:.*\"}"}},
StaticConfigs: &monitoringv1.StaticConfig{
Targets: []string{
"source-prometheus-1:9090",
"source-prometheus-2:9090",
"source-prometheus-3:9090",
},
},
},
},
},
}
return res
}