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

Revert "Merge pull request from metalmatze/statictargets-fix"

This reverts commit 7c84fdb17d, reversing
changes made to fa10f2751c.

With the _additional-scrape-config_ feature via Kubernetes secrets, the
_static-configs_ feature in Service Monitors is redundant. This patch
reverts the latter one.
This commit is contained in:
Max Leonard Inden 2018-04-25 15:53:30 +02:00
parent e45f7653a7
commit ab13af9628
No known key found for this signature in database
GPG key ID: 5403C5464810BC26
6 changed files with 10 additions and 85 deletions
Documentation
example/prometheus-operator-crd
pkg

View file

@ -152,7 +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 |
| staticTargets | StaticTargets with targets to scrape. This is an experimental feature, it may change in any upcoming release in a breaking way. | []string | false |
| staticTargets | StaticTargets with targets to scrape. | []string | false |
[Back to TOC](#table-of-contents)

View file

@ -141,9 +141,7 @@ spec:
description: Timeout after which the scrape is ended
type: string
staticTargets:
description: StaticTargets with targets to scrape. This is an
experimental feature, it may change in any upcoming release
in a breaking way.
description: StaticTargets with targets to scrape.
items:
type: string
type: array

View file

@ -541,7 +541,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
},
"staticTargets": {
SchemaProps: spec.SchemaProps{
Description: "StaticTargets with targets to scrape. This is an experimental feature, it may change in any upcoming release in a breaking way.",
Description: "StaticTargets with targets to scrape.",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{

View file

@ -347,7 +347,7 @@ 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. This is an experimental feature, it may change in any upcoming release in a breaking way.
// StaticTargets with targets to scrape.
StaticTargets []string `json:"staticTargets,omitempty"`
}

View file

@ -247,8 +247,9 @@ func generateServiceMonitorConfig(version semver.Version, m *v1.ServiceMonitor,
if ep.StaticTargets != nil {
cfg = append(cfg, yaml.MapItem{
Key: "static_configs",
Value: []yaml.MapSlice{
yaml.MapSlice{{Key: "targets", Value: ep.StaticTargets}},
Value: yaml.MapItem{
Key: "targets",
Value: ep.StaticTargets,
},
})
}

View file

@ -18,13 +18,13 @@ import (
"bytes"
"testing"
"github.com/blang/semver"
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
)
func TestConfigGeneration(t *testing.T) {
@ -153,80 +153,6 @@ alerting:
}
}
func TestStaticTargets(t *testing.T) {
ep := monitoringv1.Endpoint{
Port: "web",
Interval: "30s",
Path: "/federate",
HonorLabels: true,
Params: map[string][]string{"metrics[]": {"{__name__=~\"job:.*\"}"}},
StaticTargets: []string{
"source-prometheus-1:9090",
"source-prometheus-2:9090",
"source-prometheus-3:9090",
},
}
sm := &monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "statictargetsmonitor",
Namespace: "default",
Labels: map[string]string{
"group": "group1",
},
},
Spec: monitoringv1.ServiceMonitorSpec{
Endpoints: []monitoringv1.Endpoint{ep},
},
}
smConfig := generateServiceMonitorConfig(semver.Version{}, sm, ep, 0, nil)
s, err := yaml.Marshal(smConfig)
if err != nil {
t.Fatal(err)
}
expected := `job_name: default/statictargetsmonitor/0
honor_labels: true
scrape_interval: 30s
metrics_path: /federate
params:
metrics[]:
- '{__name__=~"job:.*"}'
static_configs:
- targets:
- source-prometheus-1:9090
- source-prometheus-2:9090
- source-prometheus-3:9090
relabel_configs:
- action: keep
source_labels:
- __meta_kubernetes_endpoint_port_name
regex: web
- source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- source_labels:
- __meta_kubernetes_service_name
target_label: service
- source_labels:
- __meta_kubernetes_service_name
target_label: job
replacement: ${1}
- target_label: endpoint
replacement: web
`
result := string(s)
if expected != result {
t.Fatalf("Unexpected result.\n\nGot:\n\n%s\n\nExpected:\n\n%s\n\n", result, expected)
}
}
func generateTestConfig(version string) ([]byte, error) {
replicas := int32(1)
return generateConfig(