From 853b3cf6327cb63e912cf53e912bb217f20ead5c Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Tue, 15 Jan 2019 18:54:33 +0100 Subject: [PATCH 1/2] contrib/kube-prometheus: Add Thanos compactor as statefulset --- .../kube-prometheus-thanos.libsonnet | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/jsonnet/kube-prometheus/kube-prometheus-thanos.libsonnet b/jsonnet/kube-prometheus/kube-prometheus-thanos.libsonnet index 71d342dc..53c2e614 100644 --- a/jsonnet/kube-prometheus/kube-prometheus-thanos.libsonnet +++ b/jsonnet/kube-prometheus/kube-prometheus-thanos.libsonnet @@ -138,5 +138,44 @@ local servicePort = k.core.v1.service.mixin.spec.portsType; statefulSet.mixin.spec.template.spec.withVolumes([ volume.fromEmptyDir('data'), ]), + + thanosCompactorStatefulset: + local statefulSet = k.apps.v1beta2.statefulSet; + local volume = statefulSet.mixin.spec.template.spec.volumesType; + local container = statefulSet.mixin.spec.template.spec.containersType; + local containerEnv = container.envType; + local containerVolumeMount = container.volumeMountsType; + + local labels = { app: 'thanos', 'thanos-peers': 'true' }; + + local c = + container.new('thanos-compactor', $._config.imageRepos.thanos + ':' + $._config.versions.thanos) + + container.withArgs([ + 'compact', + '--log.level=debug', + '--data-dir=/var/thanos/store', + '--objstore.config=$(OBJSTORE_CONFIG)', + ]) + + container.withEnv([ + containerEnv.fromSecretRef( + 'OBJSTORE_CONFIG', + $._config.thanos.objectStorageConfig.name, + $._config.thanos.objectStorageConfig.key, + ), + ]) + + container.withPorts([ + { name: 'http', containerPort: 10902 }, + ]) + + container.withVolumeMounts([ + containerVolumeMount.new('data', '/var/thanos/store', false), + ]); + + statefulSet.new('thanos-compactor', 1, c, [], labels) + + statefulSet.mixin.metadata.withNamespace($._config.namespace) + + statefulSet.mixin.spec.selector.withMatchLabels(labels) + + statefulSet.mixin.spec.withServiceName('thanos-compactor') + + statefulSet.mixin.spec.template.spec.withVolumes([ + volume.fromEmptyDir('data'), + ]), }, } From e10cafcc25bdcdd99acedf38e52b7fe34a232883 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Wed, 16 Jan 2019 16:56:36 +0100 Subject: [PATCH 2/2] contrib/kube-prometheus: Create Service and ServiceMonitor for Thanos compactor --- .../kube-prometheus-thanos.libsonnet | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/jsonnet/kube-prometheus/kube-prometheus-thanos.libsonnet b/jsonnet/kube-prometheus/kube-prometheus-thanos.libsonnet index 53c2e614..cc6ec460 100644 --- a/jsonnet/kube-prometheus/kube-prometheus-thanos.libsonnet +++ b/jsonnet/kube-prometheus/kube-prometheus-thanos.libsonnet @@ -139,6 +139,42 @@ local servicePort = k.core.v1.service.mixin.spec.portsType; volume.fromEmptyDir('data'), ]), + serviceMonitorThanosCompactor: + { + apiVersion: 'monitoring.coreos.com/v1', + kind: 'ServiceMonitor', + metadata: { + name: 'thanos-compactor', + namespace: $._config.namespace, + labels: { + 'k8s-app': 'thanos-compactor', + }, + }, + spec: { + jobLabel: 'k8s-app', + endpoints: [ + { + port: 'http', + interval: '30s', + }, + ], + selector: { + matchLabels: { + app: 'thanos-compactor', + }, + }, + }, + }, + + thanosCompactorService: + service.new( + 'thanos-compactor', + { app: 'thanos-compactor' }, + servicePort.newNamed('http', 9090, 'http'), + ) + + service.mixin.metadata.withNamespace($._config.namespace) + + service.mixin.metadata.withLabels({ app: 'thanos-compactor' }), + thanosCompactorStatefulset: local statefulSet = k.apps.v1beta2.statefulSet; local volume = statefulSet.mixin.spec.template.spec.volumesType; @@ -146,7 +182,7 @@ local servicePort = k.core.v1.service.mixin.spec.portsType; local containerEnv = container.envType; local containerVolumeMount = container.volumeMountsType; - local labels = { app: 'thanos', 'thanos-peers': 'true' }; + local labels = { app: 'thanos-compactor' }; local c = container.new('thanos-compactor', $._config.imageRepos.thanos + ':' + $._config.versions.thanos) + @@ -155,6 +191,7 @@ local servicePort = k.core.v1.service.mixin.spec.portsType; '--log.level=debug', '--data-dir=/var/thanos/store', '--objstore.config=$(OBJSTORE_CONFIG)', + '--wait', ]) + container.withEnv([ containerEnv.fromSecretRef(