Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sharding support for thanos compactor #1316

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion thanos/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ keywords:
sources:
- https://github.com/thanos-io/thanos
- https://github.com/banzaicloud/banzai-charts/tree/master/thanos
version: 0.4.6
version: 0.5.0
icon: https://raw.githubusercontent.com/thanos-io/thanos/master/docs/img/Thanos-logo_fullmedium.png
maintainers:
- name: Banzai Cloud
Expand Down
2 changes: 2 additions & 0 deletions thanos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ timePartioning:
| compact.compactConcurrency | Number of goroutines to use when compacting groups. | 1 |
| compact.dataVolume.backend | Data volume for the compactor to store temporary data defaults to emptyDir. | {} |
| compact.persistentVolumeClaim | Create the specified persistentVolumeClaim in case persistentVolumeClaim is used for the dataVolume.backend above and needs to be created. | {} |
| compact.hashPartioning.shards | The number of shards used to partition the blocks based on the hashmod of compact.hashPartitioning.label. | "" |
| compact.hashPartioning.label | The label used for sharding. Important: see [here](https://thanos.io/tip/components/compact.md/#warning-only-one-instance-of-compactor-may-run-against-a-single-stream-of-blocks-in-a-single-object-storage) for picking the right labels. | "" |

## Bucket

Expand Down
128 changes: 81 additions & 47 deletions thanos/templates/compact-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,108 +1,142 @@
{{- $root := . }}
{{ if .Values.compact.enabled }}

{{- $shards := int 0 }}

{{- $hashPartitioning := false }}

{{- if .Values.compact.hashPartitioning }}
{{- $shards = int .Values.compact.hashPartitioning.shards }}
{{- $hashPartitioning = true }}
{{- end }}


{{- range $index, $_ := until $shards }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "thanos.componentname" (list $ "compact") }}
name: {{ include "thanos.componentname" (list $ "compact") }}-{{ $index }}
labels:
app.kubernetes.io/name: {{ include "thanos.name" . }}
helm.sh/chart: {{ include "thanos.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/name: {{ include "thanos.name" $root }}
helm.sh/chart: {{ include "thanos.chart" $root }}
app.kubernetes.io/instance: {{ $root.Release.Name }}
app.kubernetes.io/managed-by: {{ $root.Release.Service }}
app.kubernetes.io/version: {{ $root.Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: compact
{{ with .Values.compact.deploymentLabels }}{{ toYaml . | indent 4 }}{{ end -}}
{{- with .Values.compact.deploymentAnnotations }}
partition: "{{ $index }}"
{{ with $root.Values.compact.deploymentLabels }}{{ toYaml . | indent 4 }}{{ end -}}
{{- with $root.Values.compact.deploymentAnnotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
spec:
replicas: {{ .Values.compact.replicaCount | default 1 }}
{{- with .Values.compact.strategy }}
replicas: {{ $root.Values.compact.replicaCount | default 1 }}
{{- with $root.Values.compact.strategy }}
strategy: {{ toYaml . | nindent 4 }}
{{- end }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "thanos.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/name: {{ include "thanos.name" $root }}
app.kubernetes.io/instance: {{ $root.Release.Name }}
app.kubernetes.io/component: compact
{{ with .Values.compact.deploymentMatchLabels }}{{ toYaml . | indent 6 }}{{ end }}
partition: "{{ $index }}"
{{ with $root.Values.compact.deploymentMatchLabels }}{{ toYaml . | indent 6 }}{{ end }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "thanos.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/name: {{ include "thanos.name" $root }}
app.kubernetes.io/instance: {{ $root.Release.Name }}
app.kubernetes.io/component: compact
{{ with .Values.compact.labels }}{{ toYaml . | indent 8 }}{{ end }}
{{- if or .Values.compact.annotations .Values.compact.metrics.annotations.enabled }}
partition: "{{ $index }}"
{{ with $root.Values.compact.labels }}{{ toYaml . | indent 8 }}{{ end }}
{{- if or $root.Values.compact.annotations $root.Values.compact.metrics.annotations.enabled }}
annotations:
{{- end }}
{{- with .Values.compact.annotations }}{{ toYaml . | nindent 8 }}{{- end }}
{{- if .Values.compact.metrics.annotations.enabled }}
{{- with $root.Values.compact.annotations }}{{ toYaml . | nindent 8 }}{{- end }}
{{- if $root.Values.compact.metrics.annotations.enabled }}
prometheus.io/scrape: "true"
prometheus.io/port: "{{ .Values.compact.http.port }}"
prometheus.io/port: "{{ $root.Values.compact.http.port }}"
{{- end }}
spec:
containers:
- name: thanos-compact
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.compact.extraEnv }}
image: "{{ $root.Values.image.repository }}:{{ $root.Values.image.tag }}"
imagePullPolicy: {{ $root.Values.image.pullPolicy }}
{{- with $root.Values.compact.extraEnv }}
env: {{ toYaml . | nindent 8 }}
{{- end }}
args:
- "compact"
- "--log.level={{ .Values.compact.logLevel }}"
- "--log.format={{ .Values.compact.logFormat }}"
- "--http-address=0.0.0.0:{{ .Values.compact.http.port }}"
- "--log.level={{ $root.Values.compact.logLevel }}"
- "--log.format={{ $root.Values.compact.logFormat }}"
- "--http-address=0.0.0.0:{{ $root.Values.compact.http.port }}"
- "--objstore.config-file=/etc/config/object-store.yaml"
- "--data-dir=/var/thanos/compact"
- "--consistency-delay={{ .Values.compact.consistencyDelay }}"
- "--retention.resolution-raw={{ .Values.compact.retentionResolutionRaw }}"
- "--retention.resolution-5m={{ .Values.compact.retentionResolution5m }}"
- "--retention.resolution-1h={{ .Values.compact.retentionResolution1h }}"
- "--block-sync-concurrency={{ .Values.compact.blockSyncConcurrency }}"
- "--compact.concurrency={{ .Values.compact.compactConcurrency }}"
- "--consistency-delay={{ $root.Values.compact.consistencyDelay }}"
- "--retention.resolution-raw={{ $root.Values.compact.retentionResolutionRaw }}"
- "--retention.resolution-5m={{ $root.Values.compact.retentionResolution5m }}"
- "--retention.resolution-1h={{ $root.Values.compact.retentionResolution1h }}"
- "--block-sync-concurrency={{ $root.Values.compact.blockSyncConcurrency }}"
- "--compact.concurrency={{ $root.Values.compact.compactConcurrency }}"
- "--wait"
{{ with .Values.compact.extraArgs }}{{ toYaml . | indent 8 }}{{- end }}
{{- if $hashPartitioning }}
- |
--selector.relabel-config=
- action: hashmod
source_labels: [{{ $root.Values.compact.hashPartitioning.label }}]
target_label: shard
modulus: {{ $shards }}
- action: keep
source_labels: ["shard"]
regex: {{ $index }}
{{- end }}
{{ with $root.Values.compact.extraArgs }}{{ toYaml . | indent 8 }}{{- end }}
ports:
- name: http
containerPort: {{ .Values.compact.http.port }}
containerPort: {{ $root.Values.compact.http.port }}
volumeMounts:
- name: config-volume
mountPath: /etc/config
readOnly: true
- name: data-volume
mountPath: /var/thanos/compact
resources: {{ toYaml .Values.compact.resources | nindent 10 }}
resources: {{ toYaml $root.Values.compact.resources | nindent 10 }}
volumes:
- name: data-volume
{{- if .Values.compact.dataVolume.backend }}
{{ toYaml .Values.compact.dataVolume.backend | nindent 8 }}
{{- if $root.Values.compact.dataVolume.backend }}
{{- if $root.Values.compact.persistentVolumeClaim }}
persistentVolumeClaim:
claimName: {{ $root.Values.compact.dataVolume.backend.persistentVolumeClaim.claimName }}-{{ $index }}
{{- else }}
{{ toYaml $root.Values.compact.dataVolume.backend | nindent 8 }}
{{- end }}
{{- else }}
emptyDir: {}
{{- end }}
- name: config-volume
secret:
{{- if .Values.objstoreSecretOverride }}
secretName: "{{ .Values.objstoreSecretOverride }}"
{{- if $root.Values.objstoreSecretOverride }}
secretName: "{{ $root.Values.objstoreSecretOverride }}"
{{- else }}
secretName: {{ include "thanos.fullname" . }}
secretName: {{ include "thanos.fullname" $root }}
{{- end }}
{{- with .Values.compact.securityContext }}
{{- with $root.Values.compact.securityContext }}
securityContext: {{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.compact.nodeSelector }}
{{- with $root.Values.compact.nodeSelector }}
nodeSelector: {{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.compact.affinity }}
{{- with $root.Values.compact.affinity }}
affinity: {{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.compact.tolerations }}
{{- with $root.Values.compact.tolerations }}
tolerations: {{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.compact.serviceAccount }}
{{- with $root.Values.compact.serviceAccount }}
serviceAccountName: "{{ . }}"
{{- end }}
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName }}
{{- if $root.Values.priorityClassName }}
priorityClassName: {{ $root.Values.priorityClassName }}
{{- end }}
---
{{- end }}
{{- end }}
27 changes: 19 additions & 8 deletions thanos/templates/compact-persistentvolumeclaim.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
{{- $root := . }}
{{- if and .Values.compact.enabled .Values.compact.persistentVolumeClaim }}
{{- $pvc := .Values.compact.persistentVolumeClaim -}}

{{- $shards := int 0 }}

{{- if .Values.compact.hashPartitioning }}
{{- $shards = int .Values.compact.hashPartitioning.shards }}
{{- end }}

{{- range $index, $_ := until $shards }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ $pvc.name }}
name: {{ $pvc.name }}-{{ $index }}
labels:
app.kubernetes.io/name: {{ include "thanos.name" . }}
helm.sh/chart: {{ include "thanos.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/name: {{ include "thanos.name" $root }}
helm.sh/chart: {{ include "thanos.chart" $root }}
app.kubernetes.io/instance: {{ $root.Release.Name }}
app.kubernetes.io/managed-by: {{ $root.Release.Service }}
app.kubernetes.io/version: {{ $root.Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: compact
{{ with .Values.compact.deploymentLabels }}{{ toYaml . | indent 4 }}{{ end -}}
{{- with .Values.compact.deploymentAnnotations }}
{{ with $root.Values.compact.deploymentLabels }}{{ toYaml . | indent 4 }}{{ end -}}
{{- with $root.Values.compact.deploymentAnnotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
spec:
{{- toYaml $pvc.spec | nindent 2 }}
---
{{- end }}
{{- end }}