Skip to content

Commit

Permalink
Merge pull request #446 from vyzigold/move_to_scrapeconfigs
Browse files Browse the repository at this point in the history
[OSPRH-8406] Switch to using ScrapeConfigs
  • Loading branch information
openshift-merge-bot[bot] authored Jul 17, 2024
2 parents 7164973 + 5eb13cf commit 9004ebc
Show file tree
Hide file tree
Showing 11 changed files with 330 additions and 409 deletions.
16 changes: 2 additions & 14 deletions api/v1beta1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ const (
// MonitoringStackReadyCondition Status=True condition which indicates if the MonitoringStack is configured and operational
MonitoringStackReadyCondition condition.Type = "MonitoringStackReady"

// ServiceMonitorReadyCondition Status=True condition which indicates if the Ceilometer ServiceMonitor is configured and operational
ServiceMonitorReadyCondition condition.Type = "CeilometerServiceMonitorReady"

// ScrapeConfigReadyCondition Status=True condition which indicates if the Node Exporter ScrapeConfig is configured and operational
ScrapeConfigReadyCondition condition.Type = "NodeExporterScrapeConfigReady"
// ScrapeConfigReadyCondition Status=True condition which indicates if the ScrapeConfig is configured and operational
ScrapeConfigReadyCondition condition.Type = "ScrapeConfigReady"

// PrometheusReadyCondition Status=True condition which indicates if the Prometheus watch is operational
PrometheusReadyCondition condition.Type = "PrometheusReady"
Expand Down Expand Up @@ -140,15 +137,6 @@ const (
// MonitoringStackReadyMisconfiguredMessage
MonitoringStackReadyMisconfiguredMessage = "MonitoringStack isn't configured properly: %s"

//
// ServiceMonitorReady condition messages
//
// ServiceMonitorReadyInitMessage
ServiceMonitorReadyInitMessage = "ServiceMonitor not started"

// ServiceMonitorUnableToOwnMessage
ServiceMonitorUnableToOwnMessage = "Error occured when trying to own %s"

//
// ScrapeConfigReady condition messages
//
Expand Down
4 changes: 0 additions & 4 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,9 @@ rules:
resources:
- servicemonitors
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- network.openstack.org
resources:
Expand Down
322 changes: 173 additions & 149 deletions controllers/metricstorage_controller.go

Large diffs are not rendered by default.

78 changes: 39 additions & 39 deletions pkg/dashboards/openstack-rabbitmq.go

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions pkg/metricstorage/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package metricstorage

const (
RabbitMQPrometheusPort = 15691
)
33 changes: 30 additions & 3 deletions pkg/metricstorage/scrape_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package metricstorage

import (
"fmt"
"sort"

tls "github.com/openstack-k8s-operators/lib-common/modules/common/tls"
telemetryv1 "github.com/openstack-k8s-operators/telemetry-operator/api/v1beta1"
Expand All @@ -37,22 +37,50 @@ func ScrapeConfig(
var scrapeInterval monv1.Duration
if instance.Spec.MonitoringStack != nil && instance.Spec.MonitoringStack.ScrapeInterval != "" {
scrapeInterval = monv1.Duration(instance.Spec.MonitoringStack.ScrapeInterval)
} else if instance.Spec.CustomMonitoringStack != nil && *instance.Spec.CustomMonitoringStack.PrometheusConfig.ScrapeInterval != monv1.Duration("") {
} else if instance.Spec.CustomMonitoringStack != nil &&
instance.Spec.CustomMonitoringStack.PrometheusConfig != nil &&
instance.Spec.CustomMonitoringStack.PrometheusConfig.ScrapeInterval != nil &&
*instance.Spec.CustomMonitoringStack.PrometheusConfig.ScrapeInterval != monv1.Duration("") {
scrapeInterval = *instance.Spec.CustomMonitoringStack.PrometheusConfig.ScrapeInterval
} else {
scrapeInterval = telemetryv1.DefaultScrapeInterval
}

sort.Strings(targets)
var convertedTargets []monv1alpha1.Target
for _, t := range targets {
convertedTargets = append(convertedTargets, monv1alpha1.Target(t))
}

scrapeConfig := &monv1alpha1.ScrapeConfig{
ObjectMeta: metav1.ObjectMeta{
Name: instance.Name,
Namespace: instance.Namespace,
Labels: labels,
},
Spec: monv1alpha1.ScrapeConfigSpec{
MetricRelabelConfigs: []*monv1.RelabelConfig{
{
Action: "labeldrop",
Regex: "pod",
SourceLabels: []monv1.LabelName{},
},
{
Action: "labeldrop",
Regex: "namespace",
SourceLabels: []monv1.LabelName{},
},
{
Action: "labeldrop",
Regex: "job",
SourceLabels: []monv1.LabelName{},
},
{
Action: "labeldrop",
Regex: "publisher",
SourceLabels: []monv1.LabelName{},
},
},
ScrapeInterval: &scrapeInterval,
StaticConfigs: []monv1alpha1.StaticConfig{
{
Expand All @@ -76,7 +104,6 @@ func ScrapeConfig(
scheme := "HTTPS"
scrapeConfig.Spec.Scheme = &scheme
scrapeConfig.Spec.TLSConfig = &tlsConfig
scrapeConfig.ObjectMeta.Name = fmt.Sprintf("%s-tls", instance.Name)
}

return scrapeConfig
Expand Down
105 changes: 0 additions & 105 deletions pkg/metricstorage/service_monitor.go

This file was deleted.

6 changes: 2 additions & 4 deletions tests/kuttl/suites/default/tests/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ status:
conditions:
- type: Ready
status: "True"
- type: CeilometerServiceMonitorReady
status: "True"
- type: DashboardDatasourceReady
status: "True"
- type: DashboardDefinitionReady
Expand All @@ -115,10 +113,10 @@ status:
status: "True"
- type: MonitoringStackReady
status: "True"
- type: NodeExporterScrapeConfigReady
status: "True"
- type: PrometheusReady
status: "True"
- type: ScrapeConfigReady
status: "True"
- type: TLSInputReady
status: "True"
---
Expand Down
67 changes: 26 additions & 41 deletions tests/kuttl/suites/metricstorage/tests/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,68 +30,53 @@ spec:
protocol: TCP
targetPort: 9090
---
apiVersion: monitoring.rhobs/v1
kind: ServiceMonitor
apiVersion: monitoring.rhobs/v1alpha1
kind: ScrapeConfig
metadata:
labels:
service: metricStorage
name: telemetry-kuttl-ceilometer-internal.telemetry-kuttl-tests.svc
name: telemetry-ceilometer
ownerReferences:
- kind: MetricStorage
name: telemetry-kuttl
spec:
endpoints:
- interval: 30s
metricRelabelings:
- action: labeldrop
regex: pod
- action: labeldrop
regex: namespace
- action: labeldrop
regex: instance
- action: labeldrop
regex: job
- action: labeldrop
regex: publisher
namespaceSelector: {}
selector:
matchLabels:
service: ceilometer
scrapeInterval: 30s
metricRelabelings:
- action: labeldrop
regex: pod
- action: labeldrop
regex: namespace
- action: labeldrop
regex: job
- action: labeldrop
regex: publisher
---
apiVersion: monitoring.rhobs/v1
kind: ServiceMonitor
apiVersion: monitoring.rhobs/v1alpha1
kind: ScrapeConfig
metadata:
labels:
service: metricStorage
name: telemetry-kuttl-rabbitmq.telemetry-kuttl-tests.svc
name: telemetry-rabbitmq
ownerReferences:
- kind: MetricStorage
name: telemetry-kuttl
spec:
endpoints:
- interval: 30s
metricRelabelings:
- action: labeldrop
regex: pod
- action: labeldrop
regex: namespace
- action: labeldrop
regex: instance
- action: labeldrop
regex: job
- action: labeldrop
regex: publisher
namespaceSelector: {}
selector:
matchLabels:
app.kubernetes.io/name: rabbitmq
scrapeInterval: 30s
metricRelabelings:
- action: labeldrop
regex: pod
- action: labeldrop
regex: namespace
- action: labeldrop
regex: job
- action: labeldrop
---
apiVersion: monitoring.rhobs/v1alpha1
kind: ScrapeConfig
metadata:
labels:
service: metricStorage
name: telemetry-kuttl
name: telemetry
ownerReferences:
- kind: MetricStorage
name: telemetry-kuttl
Expand Down
Loading

0 comments on commit 9004ebc

Please sign in to comment.