Skip to content

Commit

Permalink
Rename FilesSelector to FileSelector and rulesConfigMap to rulesChecksum
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed May 11, 2018
1 parent c37c4ef commit 674b1d0
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Documentation/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ Specification of the desired behavior of the Prometheus cluster. More info: http
| externalUrl | The external URL the Prometheus instances will be available under. This is necessary to generate correct URLs. This is necessary if Prometheus is not served from root of a DNS name. | string | false |
| routePrefix | The route prefix Prometheus registers HTTP handlers for. This is useful, if using ExternalURL and a proxy is rewriting HTTP routes of a request, and the actual ExternalURL is still true, but the server serves requests under a different route prefix. For example for use with `kubectl proxy`. | string | false |
| storage | Storage spec to specify how storage shall be used. | *[StorageSpec](#storagespec) | false |
| alertingRuleFilesSelector | A selector to select which AlertingRuleFiles to mount for loading alerting rules from. | *[metav1.LabelSelector](https://v1-6.docs.kubernetes.io/docs/api-reference/v1.6/#labelselector-v1-meta) | false |
| alertingRuleFilesNamespaceSelector | Namespaces to be selected for AlertingRuleFiles discovery. If empty, only check own namespace. | *[metav1.LabelSelector](https://v1-6.docs.kubernetes.io/docs/api-reference/v1.6/#labelselector-v1-meta) | false |
| alertingRuleFileSelector | A selector to select which AlertingRuleFiles to mount for loading alerting rules from. | *[metav1.LabelSelector](https://v1-6.docs.kubernetes.io/docs/api-reference/v1.6/#labelselector-v1-meta) | false |
| alertingRuleFileNamespaceSelector | Namespaces to be selected for AlertingRuleFiles discovery. If empty, only check own namespace. | *[metav1.LabelSelector](https://v1-6.docs.kubernetes.io/docs/api-reference/v1.6/#labelselector-v1-meta) | false |
| alerting | Define details regarding alerting. | *[AlertingSpec](#alertingspec) | false |
| resources | Define resources requests and limits for single Pods. | [v1.ResourceRequirements](https://v1-6.docs.kubernetes.io/docs/api-reference/v1.6/#resourcerequirements-v1-core) | false |
| nodeSelector | Define which Nodes the Pods are scheduled on. | map[string]string | false |
Expand Down
2 changes: 1 addition & 1 deletion contrib/kube-prometheus/jsonnetfile.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"subdir": "contrib/kube-prometheus/jsonnet/kube-prometheus"
}
},
"version": "8065b943d6816f9ed744e27150a51d9d0a72ff59"
"version": "4cee37563cb5039cdfcc69749de13d2928f71a8d"
}
]
}
4 changes: 2 additions & 2 deletions example/prometheus-operator-crd/prometheus.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ spec:
type: array
required:
- alertmanagers
alertingRuleFilesNamespaceSelector:
alertingRuleFileNamespaceSelector:
description: A label selector is a label query over a set of resources.
The result of matchLabels and matchExpressions are ANDed. An empty
label selector matches all objects. A null label selector matches
Expand Down Expand Up @@ -631,7 +631,7 @@ spec:
"In", and the values array contains only "value". The requirements
are ANDed.
type: object
alertingRuleFilesSelector:
alertingRuleFileSelector:
description: A label selector is a label query over a set of resources.
The result of matchLabels and matchExpressions are ANDed. An empty
label selector matches all objects. A null label selector matches
Expand Down
2 changes: 1 addition & 1 deletion hack/generate/jsonnetfile.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"subdir": ""
}
},
"version": "8050d6dae568f5171b9ea664344ab6e3811d0d23"
"version": "dda11dd2ec3928cbb7f36830ec0d8aa5fb13ce0c"
}
]
}
4 changes: 2 additions & 2 deletions pkg/client/monitoring/v1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/client/monitoring/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ type PrometheusSpec struct {
// Storage spec to specify how storage shall be used.
Storage *StorageSpec `json:"storage,omitempty"`
// A selector to select which AlertingRuleFiles to mount for loading alerting rules from.
AlertingRuleFilesSelector *metav1.LabelSelector `json:"alertingRuleFilesSelector,omitempty"`
AlertingRuleFileSelector *metav1.LabelSelector `json:"alertingRuleFileSelector,omitempty"`
// Namespaces to be selected for AlertingRuleFiles discovery. If empty, only
// check own namespace.
AlertingRuleFilesNamespaceSelector *metav1.LabelSelector `json:"alertingRuleFilesNamespaceSelector,omitempty"`
AlertingRuleFileNamespaceSelector *metav1.LabelSelector `json:"alertingRuleFileNamespaceSelector,omitempty"`
// Define details regarding alerting.
Alerting *AlertingSpec `json:"alerting,omitempty"`
// Define resources requests and limits for single Pods.
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/monitoring/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions pkg/prometheus/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,18 +731,17 @@ func (c *Operator) sync(key string) error {

level.Info(c.logger).Log("msg", "sync prometheus", "key", key)

// TODO: Rename ruleFileConfigMaps
ruleFileConfigMaps, err := c.ruleFileConfigMaps(p)
rulesChecksum, err := c.createOrUpdateAlertingRuleFileConfigMap(p)
if err != nil {
return errors.Wrap(err, "retrieving rule file configmaps failed")
return err
}

// TODO: Make sure configmap and secret are not constantly reloaded
// If no service monitor selectors are configured, the user wants to manage
// configuration himself.
if p.Spec.ServiceMonitorSelector != nil {
// We just always regenerate the configuration to be safe.
if err := c.createConfig(p, ruleFileConfigMaps); err != nil {
if err := c.createConfig(p, rulesChecksum); err != nil {
return errors.Wrap(err, "creating config failed")
}
}
Expand Down Expand Up @@ -795,21 +794,22 @@ func (c *Operator) sync(key string) error {
return nil
}

func (c *Operator) ruleFileConfigMaps(p *monitoringv1.Prometheus) (string, error) {
// TODO: Move to separate alertingrulefile go file
func (c *Operator) createOrUpdateAlertingRuleFileConfigMap(p *monitoringv1.Prometheus) (string, error) {
namespaces := []string{}
res := make(map[string]string)
cClient := c.kclient.CoreV1().ConfigMaps(p.Namespace)

fileSelector, err := metav1.LabelSelectorAsSelector(p.Spec.AlertingRuleFilesSelector)
fileSelector, err := metav1.LabelSelectorAsSelector(p.Spec.AlertingRuleFileSelector)
if err != nil {
return "", err
}

// If 'AlertingRuleFilesNamespaceSelector' is nil, only check own namespace.
if p.Spec.AlertingRuleFilesNamespaceSelector == nil {
if p.Spec.AlertingRuleFileNamespaceSelector == nil {
namespaces = append(namespaces, p.Namespace)
} else {
ruleFileNamespaceSelector, err := metav1.LabelSelectorAsSelector(p.Spec.AlertingRuleFilesNamespaceSelector)
ruleFileNamespaceSelector, err := metav1.LabelSelectorAsSelector(p.Spec.AlertingRuleFileNamespaceSelector)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -1133,7 +1133,7 @@ func (c *Operator) loadBasicAuthSecrets(mons map[string]*monitoringv1.ServiceMon

}

func (c *Operator) createConfig(p *monitoringv1.Prometheus, ruleFileConfigMaps string) error {
func (c *Operator) createConfig(p *monitoringv1.Prometheus, rulesChecksum string) error {
smons, err := c.selectServiceMonitors(p)
if err != nil {
return errors.Wrap(err, "selecting ServiceMonitors failed")
Expand All @@ -1159,7 +1159,7 @@ func (c *Operator) createConfig(p *monitoringv1.Prometheus, ruleFileConfigMaps s
}

// Update secret based on the most recent configuration.
conf, err := generateConfig(p, smons, ruleFileConfigMaps, basicAuthSecrets, additionalScrapeConfigs)
conf, err := generateConfig(p, smons, rulesChecksum, basicAuthSecrets, additionalScrapeConfigs)
if err != nil {
return errors.Wrap(err, "generating config failed")
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/prometheus/promcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func buildExternalLabels(p *v1.Prometheus) yaml.MapSlice {
return stringMapToMapSlice(m)
}

func generateConfig(p *v1.Prometheus, mons map[string]*v1.ServiceMonitor, ruleConfigMaps string, basicAuthSecrets map[string]BasicAuthCredentials, additionalScrapeConfigs []byte) ([]byte, error) {
func generateConfig(p *v1.Prometheus, mons map[string]*v1.ServiceMonitor, rulesChecksum string, basicAuthSecrets map[string]BasicAuthCredentials, additionalScrapeConfigs []byte) ([]byte, error) {
versionStr := p.Spec.Version
if versionStr == "" {
versionStr = DefaultVersion
Expand Down Expand Up @@ -196,10 +196,9 @@ func generateConfig(p *v1.Prometheus, mons map[string]*v1.ServiceMonitor, ruleCo
return nil, err
}

// TODO rename ruleConfigMaps to alertingrulefiles checksum
// TODO: Do not add checksum, but instead make config reloader listen for rule file changes
// Add alerting rule files checksum to the end of the config
return append(result, []byte("\n# "+ruleConfigMaps)...), nil
return append(result, []byte("\n# "+rulesChecksum)...), nil
}

func generateServiceMonitorConfig(version semver.Version, m *v1.ServiceMonitor, ep v1.Endpoint, i int, basicAuthSecrets map[string]BasicAuthCredentials) yaml.MapSlice {
Expand Down
2 changes: 1 addition & 1 deletion pkg/prometheus/promcfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func generateTestConfig(version string) ([]byte, error) {
"group": "group1",
},
},
AlertingRuleFilesSelector: &metav1.LabelSelector{
AlertingRuleFileSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"role": "rulefile",
},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func TestPrometheusMultipleAlertingRuleFilesDifferentNS(t *testing.T) {
}

p := framework.MakeBasicPrometheus(rootNS, name, name, 1)
p.Spec.AlertingRuleFilesNamespaceSelector = &metav1.LabelSelector{
p.Spec.AlertingRuleFileNamespaceSelector = &metav1.LabelSelector{
MatchLabels: alertingRuleFilesNamespaceSelector,
}
if err := framework.CreatePrometheusAndWaitUntilReady(rootNS, p); err != nil {
Expand Down
1 change: 0 additions & 1 deletion test/framework/alertingrulefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// TODO: Rename to AlertingRuleFile
func (f *Framework) MakeBasicAlertingRuleFile(ns, name, rules string) *monitoringv1alpha1.AlertingRuleFile {
return &monitoringv1alpha1.AlertingRuleFile{
ObjectMeta: metav1.ObjectMeta{
Expand Down
6 changes: 3 additions & 3 deletions test/framework/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (f *Framework) MakeBasicPrometheus(ns, name, group string, replicas int32)
},
},
ServiceAccountName: "prometheus",
AlertingRuleFilesSelector: &metav1.LabelSelector{
AlertingRuleFileSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"role": "rulefile",
},
Expand Down Expand Up @@ -150,11 +150,11 @@ func (f *Framework) MakePrometheusService(name, group string, serviceType v1.Ser
func (f *Framework) CreatePrometheusAndWaitUntilReady(ns string, p *monitoringv1.Prometheus) error {
_, err := f.MonClientV1.Prometheuses(ns).Create(p)
if err != nil {
return fmt.Errorf("creating %d Prometheus instances failed (%v): %v", p.Spec.Replicas, p.Name, err)
return fmt.Errorf("creating %v Prometheus instances failed (%v): %v", p.Spec.Replicas, p.Name, err)
}

if err := f.WaitForPrometheusReady(p, 5*time.Minute); err != nil {
return fmt.Errorf("waiting for %d Prometheus instances timed out (%v): %v", p.Spec.Replicas, p.Name, err)
return fmt.Errorf("waiting for %v Prometheus instances timed out (%v): %v", p.Spec.Replicas, p.Name, err)
}

return nil
Expand Down

0 comments on commit 674b1d0

Please sign in to comment.