Skip to content

Commit

Permalink
Loki Prometheus mixin: Fix incorrect selectors and simplify mixin usa…
Browse files Browse the repository at this point in the history
…ge (grafana#6189)

* fix(dashboards): fix matchers and selectors

Signed-off-by: irizzant <i.rizzante@gmail.com>

* doc: add entry in CHANGELOG

* feat(dashboards): add kube-prometheus mixin

Signed-off-by: irizzant <i.rizzante@gmail.com>

* doc: update CHANGELOG

* fix(mixins): fix wrong job selectors

Signed-off-by: irizzant <i.rizzante@gmail.com>

* Revert "fix(mixins): fix wrong job selectors"

This reverts commit f819a0b.

* fix(dashboards): add ServiceMonitor object

Signed-off-by: Ivan Rizzante <i.rizzante@gmail.com>

* fix(jsonnet): format jsonnet

Signed-off-by: irizzant <i.rizzante@gmail.com>

* fix(dashboards): add ServiceMonitor to Loki Simple Scalable

Signed-off-by: irizzant <i.rizzante@gmail.com>

* Revert "fix(dashboards): add ServiceMonitor to Loki Simple Scalable"

This reverts commit ba24006.

* doc: add details about create_service_monitor` parameter

Signed-off-by: irizzant <i.rizzante@gmail.com>
  • Loading branch information
irizzant authored Jun 28, 2022
1 parent 27477bf commit 002dd8a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Main

* [6189](https://github.com/grafana/loki/pull/6189) **irizzant**: Add creation of a `ServiceMonitor` object for Prometheus scraping through configuration parameter `create_service_monitor`. Simplify mixin usage by adding (https://github.com/prometheus-operator/kube-prometheus) library.
* [6444](https://github.com/grafana/loki/pull/6444) **aminesnow** Add TLS config to query frontend.
* [6372](https://github.com/grafana/loki/pull/6372) **splitice**: Add support for numbers in JSON fields.
* [6105](https://github.com/grafana/loki/pull/6105) **rutgerke** Export metrics for the Promtail journal target.
Expand Down
3 changes: 3 additions & 0 deletions production/ksonnet/loki/config.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
cluster: error 'must define cluster',
http_listen_port: 3100,

create_service_monitor: false,

replication_factor: 3,
memcached_replicas: 3,

Expand Down Expand Up @@ -386,4 +388,5 @@
deployment.mixin.spec.template.metadata.withAnnotationsMixin({
config_hash: std.md5(std.toString($._config.loki)),
}),

}
5 changes: 4 additions & 1 deletion production/ksonnet/loki/loki.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
(import 'boltdb_shipper.libsonnet') +

// Memberlist related deployment configuration, mostly migration related
(import 'memberlist.libsonnet')
(import 'memberlist.libsonnet') +

// Prometheus ServiceMonitor
(import 'servicemonitor.libsonnet')
50 changes: 50 additions & 0 deletions production/ksonnet/loki/servicemonitor.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
local this = self,

serviceMonitor: if $._config.create_service_monitor then {
apiVersion: 'monitoring.coreos.com/v1',
kind: 'ServiceMonitor',
metadata: {
name: 'loki-servicemonitor',
namespace: $._config.namespace,
},
spec: {
namespaceSelector: {
matchNames: [$._config.namespace],
},
servicesToRelabel:: [
'compactor',
'distributor',
'ingester',
'querier',
'ruler',
],
endpoints: [
{
port: port.name,
path: '/metrics',
[if std.member(self.servicesToRelabel, this[name].spec.selector.name) then 'relabelings']: [{
sourceLabels: ['job'],
action: 'replace',
replacement: $._config.namespace + '/$1',
targetLabel: 'job',
}],
}
for name in std.objectFields(this)
if std.isObject($[name]) && std.objectHas(this[name], 'kind') && this[name].kind == 'Service'
for port in std.filter(function(x) std.length(std.findSubstr('http-metrics', x.name)) > 0, this[name].spec.ports)
],
selector: {
matchExpressions: [{
key: 'name',
operator: 'In',
values: [
this[name].spec.selector.name
for name in std.objectFields(this)
if std.isObject(this[name]) && std.objectHas(this[name], 'kind') && this[name].kind == 'Service'
],
}],
},
},
} else {},
}
9 changes: 9 additions & 0 deletions production/loki-mixin/jsonnetfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
}
},
"version": "master"
},
{
"source": {
"git": {
"remote": "https://github.com/prometheus-operator/kube-prometheus.git",
"subdir": "jsonnet/kube-prometheus/lib"
}
},
"version": "main"
}
],
"legacyImports": true
Expand Down

0 comments on commit 002dd8a

Please sign in to comment.