This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
metrics.go
107 lines (88 loc) · 6.17 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package config
import (
toolsetslatest "github.com/caos/orbos/internal/operator/boom/api/latest"
ambassadormetrics "github.com/caos/orbos/internal/operator/boom/application/applications/ambassador/metrics"
"github.com/caos/orbos/internal/operator/boom/application/applications/apiserver"
argocdmetrics "github.com/caos/orbos/internal/operator/boom/application/applications/argocd/metrics"
"github.com/caos/orbos/internal/operator/boom/application/applications/boom"
kubestatemetrics "github.com/caos/orbos/internal/operator/boom/application/applications/kubestatemetrics/metrics"
lometrics "github.com/caos/orbos/internal/operator/boom/application/applications/loggingoperator/metrics"
lokimetrics "github.com/caos/orbos/internal/operator/boom/application/applications/loki/metrics"
"github.com/caos/orbos/internal/operator/boom/application/applications/orbiter"
"github.com/caos/orbos/internal/operator/boom/application/applications/prometheus/metrics"
"github.com/caos/orbos/internal/operator/boom/application/applications/prometheus/servicemonitor"
pnemetrics "github.com/caos/orbos/internal/operator/boom/application/applications/prometheusnodeexporter/metrics"
pometrics "github.com/caos/orbos/internal/operator/boom/application/applications/prometheusoperator/metrics"
psemetrics "github.com/caos/orbos/internal/operator/boom/application/applications/prometheussystemdexporter/metrics"
"github.com/caos/orbos/internal/operator/boom/application/applications/zitadel"
"github.com/caos/orbos/internal/operator/boom/labels"
)
func ScrapeMetricsCrdsConfig(instanceName string, namespace string, toolsetCRDSpec *toolsetslatest.ToolsetSpec) *Config {
servicemonitors := make([]*servicemonitor.Config, 0)
if toolsetCRDSpec.APIGateway != nil && toolsetCRDSpec.APIGateway.Deploy &&
toolsetCRDSpec.MetricsPersisting != nil && (toolsetCRDSpec.MetricsPersisting.Metrics == nil || toolsetCRDSpec.MetricsPersisting.Metrics.Ambassador) {
servicemonitors = append(servicemonitors, ambassadormetrics.GetServicemonitor(instanceName))
}
if toolsetCRDSpec.MetricCollection != nil && toolsetCRDSpec.MetricCollection.Deploy &&
toolsetCRDSpec.MetricsPersisting != nil && (toolsetCRDSpec.MetricsPersisting.Metrics == nil || toolsetCRDSpec.MetricsPersisting.Metrics.PrometheusOperator) {
servicemonitors = append(servicemonitors, pometrics.GetServicemonitor(instanceName))
}
if toolsetCRDSpec.NodeMetricsExporter != nil && toolsetCRDSpec.NodeMetricsExporter.Deploy &&
toolsetCRDSpec.MetricsPersisting != nil && (toolsetCRDSpec.MetricsPersisting.Metrics == nil || toolsetCRDSpec.MetricsPersisting.Metrics.PrometheusNodeExporter) {
servicemonitors = append(servicemonitors, pnemetrics.GetServicemonitors(instanceName)...)
}
if toolsetCRDSpec.SystemdMetricsExporter != nil && toolsetCRDSpec.SystemdMetricsExporter.Deploy &&
toolsetCRDSpec.MetricsPersisting != nil && (toolsetCRDSpec.MetricsPersisting.Metrics == nil || toolsetCRDSpec.MetricsPersisting.Metrics.PrometheusSystemdExporter) {
servicemonitors = append(servicemonitors, psemetrics.GetServicemonitor(instanceName))
}
if toolsetCRDSpec.KubeMetricsExporter != nil && toolsetCRDSpec.KubeMetricsExporter.Deploy &&
toolsetCRDSpec.MetricsPersisting != nil && (toolsetCRDSpec.MetricsPersisting.Metrics == nil || toolsetCRDSpec.MetricsPersisting.Metrics.KubeStateMetrics) {
servicemonitors = append(servicemonitors, kubestatemetrics.GetServicemonitors(instanceName)...)
}
if toolsetCRDSpec.Reconciling != nil && toolsetCRDSpec.Reconciling.Deploy &&
toolsetCRDSpec.MetricsPersisting != nil && (toolsetCRDSpec.MetricsPersisting.Metrics == nil || toolsetCRDSpec.MetricsPersisting.Metrics.Argocd) {
servicemonitors = append(servicemonitors, argocdmetrics.GetServicemonitors(instanceName)...)
}
if toolsetCRDSpec.LogCollection != nil && toolsetCRDSpec.LogCollection.Deploy &&
toolsetCRDSpec.MetricsPersisting != nil && (toolsetCRDSpec.MetricsPersisting.Metrics == nil || toolsetCRDSpec.MetricsPersisting.Metrics.LoggingOperator) {
servicemonitors = append(servicemonitors, lometrics.GetServicemonitors(instanceName)...)
}
if toolsetCRDSpec.LogsPersisting != nil && toolsetCRDSpec.LogsPersisting.Deploy &&
toolsetCRDSpec.MetricsPersisting != nil && (toolsetCRDSpec.MetricsPersisting.Metrics == nil || toolsetCRDSpec.MetricsPersisting.Metrics.Loki) {
servicemonitors = append(servicemonitors, lokimetrics.GetServicemonitor(instanceName))
}
if toolsetCRDSpec.MetricsPersisting != nil && (toolsetCRDSpec.MetricsPersisting.Metrics == nil || toolsetCRDSpec.MetricsPersisting.Metrics.APIServer) {
servicemonitors = append(servicemonitors, apiserver.GetServicemonitor(instanceName))
}
if toolsetCRDSpec.MetricsPersisting != nil && (toolsetCRDSpec.MetricsPersisting.Metrics == nil || toolsetCRDSpec.MetricsPersisting.Metrics.Boom) {
servicemonitors = append(servicemonitors, boom.GetServicemonitor(instanceName))
}
if toolsetCRDSpec.MetricsPersisting != nil && (toolsetCRDSpec.MetricsPersisting.Metrics == nil || toolsetCRDSpec.MetricsPersisting.Metrics.Orbiter) {
servicemonitors = append(servicemonitors, orbiter.GetServicemonitor(instanceName))
}
if toolsetCRDSpec.MetricsPersisting != nil && (toolsetCRDSpec.MetricsPersisting.Metrics == nil || toolsetCRDSpec.MetricsPersisting.Metrics.Zitadel) {
servicemonitors = append(servicemonitors, zitadel.GetServicemonitor(instanceName))
}
if len(servicemonitors) > 0 {
servicemonitors = append(servicemonitors, metrics.GetServicemonitor(instanceName))
prom := &Config{
Prefix: "",
Namespace: namespace,
MonitorLabels: labels.GetMonitorSelectorLabels(instanceName),
RuleLabels: labels.GetRuleSelectorLabels(instanceName),
ServiceMonitors: servicemonitors,
AdditionalScrapeConfigs: getScrapeConfigs(),
}
if toolsetCRDSpec.MetricsPersisting != nil && toolsetCRDSpec.MetricsPersisting.Storage != nil {
prom.StorageSpec = &StorageSpec{
StorageClass: toolsetCRDSpec.MetricsPersisting.Storage.StorageClass,
Storage: toolsetCRDSpec.MetricsPersisting.Storage.Size,
}
if toolsetCRDSpec.MetricsPersisting.Storage.AccessModes != nil {
prom.StorageSpec.AccessModes = toolsetCRDSpec.MetricsPersisting.Storage.AccessModes
}
}
return prom
}
return nil
}