-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from appuio/feat/syn-metrics
Add logic to configure ServiceMonitors
- Loading branch information
Showing
9 changed files
with
288 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
local kap = import 'lib/kapitan.libjsonnet'; | ||
local kube = import 'lib/kube.libjsonnet'; | ||
local prom = import 'lib/prometheus.libsonnet'; | ||
|
||
local inv = kap.inventory(); | ||
local params = inv.parameters.openshift4_logging; | ||
|
||
local syn_metrics = | ||
params.monitoring.enabled && | ||
std.member(inv.applications, 'prometheus'); | ||
|
||
local nsName = 'syn-monitoring-openshift4-logging'; | ||
|
||
local promInstance = | ||
if params.monitoring.instance != null then | ||
params.monitoring.instance | ||
else | ||
inv.parameters.prometheus.defaultInstance; | ||
|
||
local serviceMonitors = [ | ||
prom.ServiceMonitor('cluster-logging-operator',) { | ||
endpoints: { | ||
operator: { | ||
interval: '30s', | ||
metricRelabelings: [ | ||
prom.DropRuntimeMetrics, | ||
], | ||
port: 'http-metrics', | ||
}, | ||
}, | ||
selector: { | ||
matchLabels: { | ||
'control-plane': 'cluster-logging-operator', | ||
}, | ||
}, | ||
targetNamespace: params.namespace, | ||
}, | ||
prom.ServiceMonitor('fluentd') { | ||
endpoints: { | ||
fluentd: | ||
prom.ServiceMonitorHttpsEndpoint('fluentd.openshift-logging.svc') { | ||
// Fluentd doesn't need bearer token | ||
bearerTokenFile:: '', | ||
metricRelabelings: [ | ||
{ | ||
// Drop high-cardinality, low-value metrics regarding the amount | ||
// of logs ingested *per pod & container*. | ||
action: 'drop', | ||
regex: | ||
'(cluster_logging_collector_input_record_(bytes|total)|' + | ||
'log_collected_bytes_total)', | ||
sourceLabels: [ '__name__' ], | ||
}, | ||
], | ||
}, | ||
}, | ||
targetNamespace: params.namespace, | ||
selector: { | ||
matchLabels: { | ||
'logging-infra': 'support', | ||
}, | ||
}, | ||
}, | ||
prom.ServiceMonitor('elasticsearch-cluster') { | ||
endpoints: { | ||
elasticsearch: | ||
prom.ServiceMonitorHttpsEndpoint('elasticsearch-metrics.openshift-logging.svc') | ||
{ | ||
path: '/_prometheus/metrics', | ||
port: 'elasticsearch', | ||
metricRelabelings: [ | ||
prom.DropRuntimeMetrics, | ||
], | ||
}, | ||
}, | ||
targetNamespace: params.namespace, | ||
selector: { | ||
matchLabels: { | ||
'cluster-name': 'elasticsearch', | ||
'scrape-metrics': 'enabled', | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
if syn_metrics then | ||
{ | ||
'70_monitoring_namespace': prom.RegisterNamespace( | ||
kube.Namespace(nsName), | ||
instance=promInstance, | ||
), | ||
'70_monitoring_servicemonitors': std.filter( | ||
function(it) it != null, | ||
[ | ||
if params.monitoring.enableServiceMonitors[sm.metadata.name] then | ||
sm { | ||
metadata+: { | ||
namespace: nsName, | ||
}, | ||
} | ||
for sm in serviceMonitors | ||
] | ||
), | ||
'70_monitoring_networkpolicy': prom.NetworkPolicy(instance=promInstance) { | ||
metadata+: { | ||
// The networkpolicy needs to be in the namespace in which OpenShift | ||
// logging is deployed. | ||
namespace: params.namespace, | ||
}, | ||
}, | ||
} | ||
else | ||
std.trace( | ||
'Monitoring disabled or component `prometheus` not present, ' | ||
+ 'not deploying ServiceMonitors', | ||
{} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
.../golden/syn-monitoring/openshift4-logging/openshift4-logging/70_monitoring_namespace.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
annotations: {} | ||
labels: | ||
monitoring.syn.tools/monitoring: 'true' | ||
name: syn-monitoring-openshift4-logging | ||
name: syn-monitoring-openshift4-logging |
18 changes: 18 additions & 0 deletions
18
...den/syn-monitoring/openshift4-logging/openshift4-logging/70_monitoring_networkpolicy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
apiVersion: networking.k8s.io/v1 | ||
kind: NetworkPolicy | ||
metadata: | ||
annotations: {} | ||
labels: | ||
name: allow-from-prometheus-monitoring | ||
name: allow-from-prometheus-monitoring | ||
namespace: openshift-logging | ||
spec: | ||
egress: [] | ||
ingress: | ||
- from: | ||
- namespaceSelector: | ||
matchLabels: | ||
kubernetes.io/metadata.name: syn-monitoring | ||
podSelector: {} | ||
policyTypes: | ||
- Ingress |
82 changes: 82 additions & 0 deletions
82
...n/syn-monitoring/openshift4-logging/openshift4-logging/70_monitoring_servicemonitors.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
annotations: {} | ||
labels: | ||
name: cluster-logging-operator | ||
name: cluster-logging-operator | ||
namespace: syn-monitoring-openshift4-logging | ||
spec: | ||
endpoints: | ||
- interval: 30s | ||
metricRelabelings: | ||
- action: drop | ||
regex: (go_.*|process_.*|promhttp_.*) | ||
sourceLabels: | ||
- __name__ | ||
port: http-metrics | ||
namespaceSelector: | ||
matchNames: | ||
- openshift-logging | ||
selector: | ||
matchLabels: | ||
control-plane: cluster-logging-operator | ||
--- | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
annotations: {} | ||
labels: | ||
name: fluentd | ||
name: fluentd | ||
namespace: syn-monitoring-openshift4-logging | ||
spec: | ||
endpoints: | ||
- interval: 30s | ||
metricRelabelings: | ||
- action: drop | ||
regex: (cluster_logging_collector_input_record_(bytes|total)|log_collected_bytes_total) | ||
sourceLabels: | ||
- __name__ | ||
port: metrics | ||
scheme: https | ||
tlsConfig: | ||
caFile: /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt | ||
serverName: fluentd.openshift-logging.svc | ||
namespaceSelector: | ||
matchNames: | ||
- openshift-logging | ||
selector: | ||
matchLabels: | ||
logging-infra: support | ||
--- | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
annotations: {} | ||
labels: | ||
name: elasticsearch-cluster | ||
name: elasticsearch-cluster | ||
namespace: syn-monitoring-openshift4-logging | ||
spec: | ||
endpoints: | ||
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token | ||
interval: 30s | ||
metricRelabelings: | ||
- action: drop | ||
regex: (go_.*|process_.*|promhttp_.*) | ||
sourceLabels: | ||
- __name__ | ||
path: /_prometheus/metrics | ||
port: elasticsearch | ||
scheme: https | ||
tlsConfig: | ||
caFile: /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt | ||
serverName: elasticsearch-metrics.openshift-logging.svc | ||
namespaceSelector: | ||
matchNames: | ||
- openshift-logging | ||
selector: | ||
matchLabels: | ||
cluster-name: elasticsearch | ||
scrape-metrics: enabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters