Merge pull request #909 from paulfantom/thanos-sidecar-follow-up

First-level support for thanos sidecar
This commit is contained in:
Paweł Krupa 2021-02-04 16:37:10 +01:00 committed by GitHub
commit 18630eaca1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 87 deletions

View File

@ -1,17 +1,18 @@
local kp = local kp =
(import 'kube-prometheus/main.libsonnet') + (import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/addons/thanos-sidecar.libsonnet') +
{ {
values+:: { values+:: {
common+: { common+: {
namespace: 'monitoring', namespace: 'monitoring',
}, },
thanos: { prometheus+: {
version: '0.17.2', thanos: {
image: 'quay.io/thanos-io/thanos:v' + $.values.thanos.version, version: '0.17.2',
objectStorageConfig: { image: 'quay.io/thanos-io/thanos:v0.17.2',
key: 'thanos.yaml', // How the file inside the secret is called objectStorageConfig: {
name: 'thanos-objectstorage', // This is the name of your Kubernetes secret with the config key: 'thanos.yaml', // How the file inside the secret is called
name: 'thanos-objectstorage', // This is the name of your Kubernetes secret with the config
},
}, },
}, },
}, },

View File

@ -1,77 +0,0 @@
(import 'github.com/thanos-io/thanos/mixin/alerts/sidecar.libsonnet') +
{
values+:: {
thanos: {
version: error 'must provide thanos version',
image: error 'must provide thanos image',
objectStorageConfig: error 'must provide thanos object storage configuration',
},
},
prometheus+: {
local p = self,
// Add the grpc port to the Prometheus service to be able to query it with the Thanos Querier
service+: {
spec+: {
ports+: [
{ name: 'grpc', port: 10901, targetPort: 10901 },
],
},
},
// Create a new service that exposes both sidecar's HTTP metrics port and gRPC StoreAPI
serviceThanosSidecar: {
apiVersion: 'v1',
kind: 'Service',
metadata: {
name: 'prometheus-' + p.config.name + '-thanos-sidecar',
namespace: p.config.namespace,
labels: { prometheus: p.config.name, app: 'thanos-sidecar' },
},
spec: {
ports: [
{ name: 'grpc', port: 10901, targetPort: 10901 },
{ name: 'http', port: 10902, targetPort: 10902 },
],
selector: { app: 'prometheus', prometheus: p.config.name },
clusterIP: 'None',
},
},
prometheus+: {
spec+: {
thanos+: {
version: $.values.thanos.version,
image: $.values.thanos.image,
objectStorageConfig: $.values.thanos.objectStorageConfig,
},
},
},
serviceMonitorThanosSidecar:
{
apiVersion: 'monitoring.coreos.com/v1',
kind: 'ServiceMonitor',
metadata: {
name: 'thanos-sidecar',
namespace: p.config.namespace,
labels: {
'app.kubernetes.io/name': 'prometheus',
},
},
spec: {
// Use the service's app label (thanos-sidecar) as the value for the job label.
jobLabel: 'app',
selector: {
matchLabels: {
prometheus: p.config.name,
app: 'thanos-sidecar',
},
},
endpoints: [
{
port: 'http',
interval: '30s',
},
],
},
},
},
}

View File

@ -35,8 +35,10 @@ local defaults = {
_config: { _config: {
prometheusSelector: 'job="prometheus-' + defaults.name + '",namespace="' + defaults.namespace + '"', prometheusSelector: 'job="prometheus-' + defaults.name + '",namespace="' + defaults.namespace + '"',
prometheusName: '{{$labels.namespace}}/{{$labels.pod}}', prometheusName: '{{$labels.namespace}}/{{$labels.pod}}',
thanosSelector: 'job="thanos-sidecar"',
}, },
}, },
thanos: {},
}; };
@ -47,7 +49,15 @@ function(params) {
assert std.isObject(p.config.resources), assert std.isObject(p.config.resources),
assert std.isObject(p.config.mixin._config), assert std.isObject(p.config.mixin._config),
mixin:: (import 'github.com/prometheus/prometheus/documentation/prometheus-mixin/mixin.libsonnet') { mixin:: (import 'github.com/prometheus/prometheus/documentation/prometheus-mixin/mixin.libsonnet') + (
if p.config.thanos != {} then
(import 'github.com/thanos-io/thanos/mixin/alerts/sidecar.libsonnet') + {
sidecar: {
selector: p.config.mixin._config.thanosSelector,
},
}
else {}
) {
_config+:: p.config.mixin._config, _config+:: p.config.mixin._config,
}, },
@ -86,8 +96,13 @@ function(params) {
}, },
spec: { spec: {
ports: [ ports: [
{ name: 'web', targetPort: 'web', port: 9090 }, { name: 'web', targetPort: 'web', port: 9090 },
], ] +
(
if p.config.thanos != {} then
[{ name: 'grpc', port: 10901, targetPort: 10901 }]
else []
),
selector: { app: 'prometheus' } + p.config.selectorLabels, selector: { app: 'prometheus' } + p.config.selectorLabels,
sessionAffinity: 'ClientIP', sessionAffinity: 'ClientIP',
}, },
@ -259,6 +274,7 @@ function(params) {
runAsNonRoot: true, runAsNonRoot: true,
fsGroup: 2000, fsGroup: 2000,
}, },
thanos: p.config.thanos,
}, },
}, },
@ -491,4 +507,56 @@ function(params) {
}], }],
}, },
}, },
// Include thanos sidecar Service only if thanos config was passed by user
[if std.objectHas(params, 'thanos') && std.length(params.thanos) > 0 then 'serviceThanosSidecar']: {
apiVersion: 'v1',
kind: 'Service',
metadata+: {
name: 'prometheus-' + p.config.name + '-thanos-sidecar',
namespace: p.config.namespace,
labels+: p.config.commonLabels {
prometheus: p.config.name,
'app.kubernetes.io/component': 'thanos-sidecar',
},
},
spec+: {
ports: [
{ name: 'grpc', port: 10901, targetPort: 10901 },
{ name: 'http', port: 10902, targetPort: 10902 },
],
selector: p.config.selectorLabels {
prometheus: p.config.name,
'app.kubernetes.io/component': 'prometheus',
},
clusterIP: 'None',
},
},
// Include thanos sidecar ServiceMonitor only if thanos config was passed by user
[if std.objectHas(params, 'thanos') && std.length(params.thanos) > 0 then 'serviceMonitorThanosSidecar']: {
apiVersion: 'monitoring.coreos.com/v1',
kind: 'ServiceMonitor',
metadata+: {
name: 'thanos-sidecar',
namespace: p.config.namespace,
labels: p.config.commonLabels {
prometheus: p.config.name,
'app.kubernetes.io/component': 'thanos-sidecar',
},
},
spec+: {
jobLabel: 'app.kubernetes.io/component',
selector: {
matchLabels: {
prometheus: p.config.name,
'app.kubernetes.io/component': 'thanos-sidecar',
},
},
endpoints: [{
port: 'http',
interval: '30s',
}],
},
},
} }

View File

@ -44,4 +44,5 @@ spec:
serviceAccountName: prometheus-k8s serviceAccountName: prometheus-k8s
serviceMonitorNamespaceSelector: {} serviceMonitorNamespaceSelector: {}
serviceMonitorSelector: {} serviceMonitorSelector: {}
thanos: {}
version: 2.24.0 version: 2.24.0