diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c61aa2..62bc6e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ We use *breaking* word for marking changes that are not backward compatible (rel ### Added +- [#142](https://github.com/thanos-io/kube-thanos/pull/142) query-frontend: Add thanos query frontend component. + ### Fixed [Full Changelog](https://github.com/thanos-io/kube-thanos/compare/master...v0.14.0) diff --git a/all.jsonnet b/all.jsonnet index bb0c970..c23dfd9 100644 --- a/all.jsonnet +++ b/all.jsonnet @@ -7,7 +7,7 @@ local commonConfig = { config+:: { local cfg = self, namespace: 'thanos', - version: 'v0.14.0', + version: 'master-2020-08-11-2ea2c2b7', image: 'quay.io/thanos/thanos:' + cfg.version, objectStorageConfig: { name: 'thanos-objectstorage', @@ -122,10 +122,34 @@ local finalRu = ru { }, }; +local qf = + t.queryFrontend + + t.queryFrontend.withServiceMonitor + + t.queryFrontend.withSplitInterval + + t.queryFrontend.withMaxRetries + + t.queryFrontend.withLogQueriesLongerThan + + t.queryFrontend.withInMemoryResponseCache + + commonConfig + { + config+:: { + name: 'thanos-query-frontend', + replicas: 1, + downstreamURL: 'http://%s.%s.svc.cluster.local.:%d' % [ + q.service.metadata.name, + q.service.metadata.namespace, + 9090, + ], + splitInterval: '24h', + maxRetries: 5, + logQueriesLongerThan: '5s', + }, + }; + + { ['thanos-bucket-' + name]: b[name] for name in std.objectFields(b) } + { ['thanos-compact-' + name]: c[name] for name in std.objectFields(c) } + { ['thanos-receive-' + name]: re[name] for name in std.objectFields(re) } + { ['thanos-rule-' + name]: finalRu[name] for name in std.objectFields(finalRu) } + { ['thanos-store-' + name]: s[name] for name in std.objectFields(s) } + { ['thanos-query-' + name]: q[name] for name in std.objectFields(q) } + +{ ['thanos-query-frontend-' + name]: qf[name] for name in std.objectFields(qf) } + { 'thanos-store-statefulSet-with-memcached': swm.statefulSet } diff --git a/examples/all/manifests/thanos-bucket-deployment.yaml b/examples/all/manifests/thanos-bucket-deployment.yaml index 43891c2..51994a4 100644 --- a/examples/all/manifests/thanos-bucket-deployment.yaml +++ b/examples/all/manifests/thanos-bucket-deployment.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: object-store-bucket-debugging app.kubernetes.io/instance: thanos-bucket app.kubernetes.io/name: thanos-bucket - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-bucket namespace: thanos spec: @@ -21,7 +21,7 @@ spec: app.kubernetes.io/component: object-store-bucket-debugging app.kubernetes.io/instance: thanos-bucket app.kubernetes.io/name: thanos-bucket - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 spec: containers: - args: @@ -36,7 +36,7 @@ spec: secretKeyRef: key: thanos.yaml name: thanos-objectstorage - image: quay.io/thanos/thanos:v0.14.0 + image: quay.io/thanos/thanos:master-2020-08-11-2ea2c2b7 livenessProbe: failureThreshold: 4 httpGet: diff --git a/examples/all/manifests/thanos-bucket-service.yaml b/examples/all/manifests/thanos-bucket-service.yaml index b6011d6..a213d29 100644 --- a/examples/all/manifests/thanos-bucket-service.yaml +++ b/examples/all/manifests/thanos-bucket-service.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: object-store-bucket-debugging app.kubernetes.io/instance: thanos-bucket app.kubernetes.io/name: thanos-bucket - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-bucket namespace: thanos spec: diff --git a/examples/all/manifests/thanos-compact-service.yaml b/examples/all/manifests/thanos-compact-service.yaml index 99f6a53..258baa8 100644 --- a/examples/all/manifests/thanos-compact-service.yaml +++ b/examples/all/manifests/thanos-compact-service.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: database-compactor app.kubernetes.io/instance: thanos-compact app.kubernetes.io/name: thanos-compact - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-compact namespace: thanos spec: diff --git a/examples/all/manifests/thanos-compact-serviceMonitor.yaml b/examples/all/manifests/thanos-compact-serviceMonitor.yaml index 3503d11..76fd60b 100644 --- a/examples/all/manifests/thanos-compact-serviceMonitor.yaml +++ b/examples/all/manifests/thanos-compact-serviceMonitor.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: database-compactor app.kubernetes.io/instance: thanos-compact app.kubernetes.io/name: thanos-compact - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-compact namespace: thanos spec: diff --git a/examples/all/manifests/thanos-compact-statefulSet.yaml b/examples/all/manifests/thanos-compact-statefulSet.yaml index fa49674..4e7c39e 100644 --- a/examples/all/manifests/thanos-compact-statefulSet.yaml +++ b/examples/all/manifests/thanos-compact-statefulSet.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: database-compactor app.kubernetes.io/instance: thanos-compact app.kubernetes.io/name: thanos-compact - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-compact namespace: thanos spec: @@ -22,7 +22,7 @@ spec: app.kubernetes.io/component: database-compactor app.kubernetes.io/instance: thanos-compact app.kubernetes.io/name: thanos-compact - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 spec: containers: - args: @@ -38,7 +38,7 @@ spec: secretKeyRef: key: thanos.yaml name: thanos-objectstorage - image: quay.io/thanos/thanos:v0.14.0 + image: quay.io/thanos/thanos:master-2020-08-11-2ea2c2b7 livenessProbe: failureThreshold: 4 httpGet: diff --git a/examples/all/manifests/thanos-query-deployment.yaml b/examples/all/manifests/thanos-query-deployment.yaml index e324f2d..0e1cff9 100644 --- a/examples/all/manifests/thanos-query-deployment.yaml +++ b/examples/all/manifests/thanos-query-deployment.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: query-layer app.kubernetes.io/instance: thanos-query app.kubernetes.io/name: thanos-query - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-query namespace: thanos spec: @@ -21,7 +21,7 @@ spec: app.kubernetes.io/component: query-layer app.kubernetes.io/instance: thanos-query app.kubernetes.io/name: thanos-query - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 spec: affinity: podAntiAffinity: @@ -49,7 +49,7 @@ spec: - --store=dnssrv+_grpc._tcp.thanos-rule.thanos.svc.cluster.local - --store=dnssrv+_grpc._tcp.thanos-store.thanos.svc.cluster.local - --query.timeout=5m - image: quay.io/thanos/thanos:v0.14.0 + image: quay.io/thanos/thanos:master-2020-08-11-2ea2c2b7 livenessProbe: failureThreshold: 4 httpGet: diff --git a/examples/all/manifests/thanos-query-frontend-deployment.yaml b/examples/all/manifests/thanos-query-frontend-deployment.yaml new file mode 100644 index 0000000..559ed37 --- /dev/null +++ b/examples/all/manifests/thanos-query-frontend-deployment.yaml @@ -0,0 +1,75 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app.kubernetes.io/component: query-cache + app.kubernetes.io/instance: thanos-query-frontend + app.kubernetes.io/name: thanos-query-frontend + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 + name: thanos-query-frontend + namespace: thanos +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/component: query-cache + app.kubernetes.io/instance: thanos-query-frontend + app.kubernetes.io/name: thanos-query-frontend + template: + metadata: + labels: + app.kubernetes.io/component: query-cache + app.kubernetes.io/instance: thanos-query-frontend + app.kubernetes.io/name: thanos-query-frontend + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 + spec: + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.kubernetes.io/name + operator: In + values: + - thanos-query-frontend + namespaces: + - thanos + topologyKey: kubernetes.io/hostname + weight: 100 + containers: + - args: + - query-frontend + - --query-frontend.compress-responses + - --http-address=0.0.0.0:9090 + - --query-frontend.downstream-url=http://thanos-query.thanos.svc.cluster.local.:9090 + - --query-range.split-interval=24h + - --query-range.max-retries-per-request=5 + - --query-frontend.log_queries_longer_than=5s + - |- + --query-range.response-cache-config="config": + "max_size": "0" + "max_size_items": 2048 + "validity": "6h" + "type": "in-memory" + image: quay.io/thanos/thanos:master-2020-08-11-2ea2c2b7 + livenessProbe: + failureThreshold: 4 + httpGet: + path: /-/healthy + port: 9090 + scheme: HTTP + periodSeconds: 30 + name: thanos-query-frontend + ports: + - containerPort: 9090 + name: http + readinessProbe: + failureThreshold: 20 + httpGet: + path: /-/ready + port: 9090 + scheme: HTTP + periodSeconds: 5 + terminationMessagePolicy: FallbackToLogsOnError + terminationGracePeriodSeconds: 120 diff --git a/examples/all/manifests/thanos-query-frontend-service.yaml b/examples/all/manifests/thanos-query-frontend-service.yaml new file mode 100644 index 0000000..b86c271 --- /dev/null +++ b/examples/all/manifests/thanos-query-frontend-service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/component: query-cache + app.kubernetes.io/instance: thanos-query-frontend + app.kubernetes.io/name: thanos-query-frontend + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 + name: thanos-query-frontend + namespace: thanos +spec: + ports: + - name: http + port: 9090 + targetPort: http + selector: + app.kubernetes.io/component: query-cache + app.kubernetes.io/instance: thanos-query-frontend + app.kubernetes.io/name: thanos-query-frontend diff --git a/examples/all/manifests/thanos-query-frontend-serviceMonitor.yaml b/examples/all/manifests/thanos-query-frontend-serviceMonitor.yaml new file mode 100644 index 0000000..be9510f --- /dev/null +++ b/examples/all/manifests/thanos-query-frontend-serviceMonitor.yaml @@ -0,0 +1,24 @@ +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/component: query-cache + app.kubernetes.io/instance: thanos-query-frontend + app.kubernetes.io/name: thanos-query-frontend + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 + name: thanos-query-frontend + namespace: thanos +spec: + endpoints: + - port: http + relabelings: + - separator: / + sourceLabels: + - namespace + - pod + targetLabel: instance + selector: + matchLabels: + app.kubernetes.io/component: query-cache + app.kubernetes.io/instance: thanos-query-frontend + app.kubernetes.io/name: thanos-query-frontend diff --git a/examples/all/manifests/thanos-query-service.yaml b/examples/all/manifests/thanos-query-service.yaml index 139ad00..35841d1 100644 --- a/examples/all/manifests/thanos-query-service.yaml +++ b/examples/all/manifests/thanos-query-service.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: query-layer app.kubernetes.io/instance: thanos-query app.kubernetes.io/name: thanos-query - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-query namespace: thanos spec: diff --git a/examples/all/manifests/thanos-query-serviceMonitor.yaml b/examples/all/manifests/thanos-query-serviceMonitor.yaml index 2f56ba6..4f8e368 100644 --- a/examples/all/manifests/thanos-query-serviceMonitor.yaml +++ b/examples/all/manifests/thanos-query-serviceMonitor.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: query-layer app.kubernetes.io/instance: thanos-query app.kubernetes.io/name: thanos-query - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-query namespace: thanos spec: diff --git a/examples/all/manifests/thanos-receive-service.yaml b/examples/all/manifests/thanos-receive-service.yaml index 94a118c..5984232 100644 --- a/examples/all/manifests/thanos-receive-service.yaml +++ b/examples/all/manifests/thanos-receive-service.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: database-write-hashring app.kubernetes.io/instance: thanos-receive app.kubernetes.io/name: thanos-receive - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-receive namespace: thanos spec: diff --git a/examples/all/manifests/thanos-receive-serviceMonitor.yaml b/examples/all/manifests/thanos-receive-serviceMonitor.yaml index 0076b6f..5610894 100644 --- a/examples/all/manifests/thanos-receive-serviceMonitor.yaml +++ b/examples/all/manifests/thanos-receive-serviceMonitor.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: database-write-hashring app.kubernetes.io/instance: thanos-receive app.kubernetes.io/name: thanos-receive - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-receive namespace: thanos spec: diff --git a/examples/all/manifests/thanos-receive-statefulSet.yaml b/examples/all/manifests/thanos-receive-statefulSet.yaml index 602d860..8c3fd73 100644 --- a/examples/all/manifests/thanos-receive-statefulSet.yaml +++ b/examples/all/manifests/thanos-receive-statefulSet.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: database-write-hashring app.kubernetes.io/instance: thanos-receive app.kubernetes.io/name: thanos-receive - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-receive namespace: thanos spec: @@ -22,7 +22,7 @@ spec: app.kubernetes.io/component: database-write-hashring app.kubernetes.io/instance: thanos-receive app.kubernetes.io/name: thanos-receive - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 spec: affinity: podAntiAffinity: @@ -84,7 +84,7 @@ spec: secretKeyRef: key: thanos.yaml name: thanos-objectstorage - image: quay.io/thanos/thanos:v0.14.0 + image: quay.io/thanos/thanos:master-2020-08-11-2ea2c2b7 livenessProbe: failureThreshold: 8 httpGet: diff --git a/examples/all/manifests/thanos-rule-service.yaml b/examples/all/manifests/thanos-rule-service.yaml index ed23289..3773742 100644 --- a/examples/all/manifests/thanos-rule-service.yaml +++ b/examples/all/manifests/thanos-rule-service.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: rule-evaluation-engine app.kubernetes.io/instance: thanos-rule app.kubernetes.io/name: thanos-rule - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-rule namespace: thanos spec: diff --git a/examples/all/manifests/thanos-rule-serviceMonitor.yaml b/examples/all/manifests/thanos-rule-serviceMonitor.yaml index a635d57..bc4a4ca 100644 --- a/examples/all/manifests/thanos-rule-serviceMonitor.yaml +++ b/examples/all/manifests/thanos-rule-serviceMonitor.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: rule-evaluation-engine app.kubernetes.io/instance: thanos-rule app.kubernetes.io/name: thanos-rule - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-rule namespace: thanos spec: diff --git a/examples/all/manifests/thanos-rule-statefulSet.yaml b/examples/all/manifests/thanos-rule-statefulSet.yaml index c7f40ca..08d5818 100644 --- a/examples/all/manifests/thanos-rule-statefulSet.yaml +++ b/examples/all/manifests/thanos-rule-statefulSet.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: rule-evaluation-engine app.kubernetes.io/instance: thanos-rule app.kubernetes.io/name: thanos-rule - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-rule namespace: thanos spec: @@ -22,7 +22,7 @@ spec: app.kubernetes.io/component: rule-evaluation-engine app.kubernetes.io/instance: thanos-rule app.kubernetes.io/name: thanos-rule - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 spec: containers: - args: @@ -45,7 +45,7 @@ spec: secretKeyRef: key: thanos.yaml name: thanos-objectstorage - image: quay.io/thanos/thanos:v0.14.0 + image: quay.io/thanos/thanos:master-2020-08-11-2ea2c2b7 livenessProbe: failureThreshold: 24 httpGet: diff --git a/examples/all/manifests/thanos-store-service.yaml b/examples/all/manifests/thanos-store-service.yaml index 296c7b7..a29503b 100644 --- a/examples/all/manifests/thanos-store-service.yaml +++ b/examples/all/manifests/thanos-store-service.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: object-store-gateway app.kubernetes.io/instance: thanos-store app.kubernetes.io/name: thanos-store - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-store namespace: thanos spec: diff --git a/examples/all/manifests/thanos-store-serviceMonitor.yaml b/examples/all/manifests/thanos-store-serviceMonitor.yaml index 769d686..3579f36 100644 --- a/examples/all/manifests/thanos-store-serviceMonitor.yaml +++ b/examples/all/manifests/thanos-store-serviceMonitor.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: object-store-gateway app.kubernetes.io/instance: thanos-store app.kubernetes.io/name: thanos-store - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-store namespace: thanos spec: diff --git a/examples/all/manifests/thanos-store-statefulSet-with-memcached.yaml b/examples/all/manifests/thanos-store-statefulSet-with-memcached.yaml index 2f015cc..1d7d687 100644 --- a/examples/all/manifests/thanos-store-statefulSet-with-memcached.yaml +++ b/examples/all/manifests/thanos-store-statefulSet-with-memcached.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: object-store-gateway app.kubernetes.io/instance: thanos-store app.kubernetes.io/name: thanos-store - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-store namespace: thanos spec: @@ -22,7 +22,7 @@ spec: app.kubernetes.io/component: object-store-gateway app.kubernetes.io/instance: thanos-store app.kubernetes.io/name: thanos-store - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 spec: affinity: podAntiAffinity: @@ -92,7 +92,7 @@ spec: secretKeyRef: key: thanos.yaml name: thanos-objectstorage - image: quay.io/thanos/thanos:v0.14.0 + image: quay.io/thanos/thanos:master-2020-08-11-2ea2c2b7 livenessProbe: failureThreshold: 8 httpGet: diff --git a/examples/all/manifests/thanos-store-statefulSet.yaml b/examples/all/manifests/thanos-store-statefulSet.yaml index a015773..9e80ac9 100644 --- a/examples/all/manifests/thanos-store-statefulSet.yaml +++ b/examples/all/manifests/thanos-store-statefulSet.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: object-store-gateway app.kubernetes.io/instance: thanos-store app.kubernetes.io/name: thanos-store - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 name: thanos-store namespace: thanos spec: @@ -22,7 +22,7 @@ spec: app.kubernetes.io/component: object-store-gateway app.kubernetes.io/instance: thanos-store app.kubernetes.io/name: thanos-store - app.kubernetes.io/version: v0.14.0 + app.kubernetes.io/version: master-2020-08-11-2ea2c2b7 spec: affinity: podAntiAffinity: @@ -56,7 +56,7 @@ spec: secretKeyRef: key: thanos.yaml name: thanos-objectstorage - image: quay.io/thanos/thanos:v0.14.0 + image: quay.io/thanos/thanos:master-2020-08-11-2ea2c2b7 livenessProbe: failureThreshold: 8 httpGet: diff --git a/jsonnet/kube-thanos/kube-thanos-query-frontend.libsonnet b/jsonnet/kube-thanos/kube-thanos-query-frontend.libsonnet new file mode 100644 index 0000000..688ab1e --- /dev/null +++ b/jsonnet/kube-thanos/kube-thanos-query-frontend.libsonnet @@ -0,0 +1,252 @@ +local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; + +{ + local tqf = self, + + config:: { + name: error 'must provide name', + namespace: error 'must provide namespace', + version: error 'must provide version', + image: error 'must provide image', + replicas: error 'must provide replicas', + downstreamURL: error 'must provide downstreamURL', + + commonLabels:: { + 'app.kubernetes.io/name': 'thanos-query-frontend', + 'app.kubernetes.io/instance': tqf.config.name, + 'app.kubernetes.io/version': tqf.config.version, + 'app.kubernetes.io/component': 'query-cache', + }, + + podLabelSelector:: { + [labelName]: tqf.config.commonLabels[labelName] + for labelName in std.objectFields(tqf.config.commonLabels) + if !std.setMember(labelName, ['app.kubernetes.io/version']) + }, + }, + + service: + local service = k.core.v1.service; + local ports = service.mixin.spec.portsType; + + service.new( + tqf.config.name, + tqf.config.podLabelSelector, + [ + ports.newNamed('http', 9090, 'http'), + ] + ) + + service.mixin.metadata.withNamespace(tqf.config.namespace) + + service.mixin.metadata.withLabels(tqf.config.commonLabels), + + deployment: + local deployment = k.apps.v1.deployment; + local container = deployment.mixin.spec.template.spec.containersType; + local affinity = deployment.mixin.spec.template.spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecutionType; + local matchExpression = affinity.mixin.podAffinityTerm.labelSelector.matchExpressionsType; + + local c = + container.new('thanos-query-frontend', tqf.config.image) + + container.withTerminationMessagePolicy('FallbackToLogsOnError') + + container.withArgs([ + 'query-frontend', + '--query-frontend.compress-responses', + '--http-address=0.0.0.0:%d' % tqf.service.spec.ports[0].port, + '--query-frontend.downstream-url=%s' % tqf.config.downstreamURL, + ]) + + container.withPorts([ + { name: 'http', containerPort: tqf.service.spec.ports[0].port }, + ]) + + container.mixin.livenessProbe + + container.mixin.livenessProbe.withPeriodSeconds(30) + + container.mixin.livenessProbe.withFailureThreshold(4) + + container.mixin.livenessProbe.httpGet.withPort(tqf.service.spec.ports[0].port) + + container.mixin.livenessProbe.httpGet.withScheme('HTTP') + + container.mixin.livenessProbe.httpGet.withPath('/-/healthy') + + container.mixin.readinessProbe + + container.mixin.readinessProbe.withPeriodSeconds(5) + + container.mixin.readinessProbe.withFailureThreshold(20) + + container.mixin.readinessProbe.httpGet.withPort(tqf.service.spec.ports[0].port) + + container.mixin.readinessProbe.httpGet.withScheme('HTTP') + + container.mixin.readinessProbe.httpGet.withPath('/-/ready'); + + deployment.new(tqf.config.name, tqf.config.replicas, c, tqf.config.commonLabels) + + deployment.mixin.metadata.withNamespace(tqf.config.namespace) + + deployment.mixin.metadata.withLabels(tqf.config.commonLabels) + + deployment.mixin.spec.selector.withMatchLabels(tqf.config.podLabelSelector) + + deployment.mixin.spec.template.spec.withTerminationGracePeriodSeconds(120) + + deployment.mixin.spec.template.spec.affinity.podAntiAffinity.withPreferredDuringSchedulingIgnoredDuringExecution([ + affinity.new() + + affinity.withWeight(100) + + affinity.mixin.podAffinityTerm.withNamespaces(tqf.config.namespace) + + affinity.mixin.podAffinityTerm.withTopologyKey('kubernetes.io/hostname') + + affinity.mixin.podAffinityTerm.labelSelector.withMatchExpressions([ + matchExpression.new() + + matchExpression.withKey('app.kubernetes.io/name') + + matchExpression.withOperator('In') + + matchExpression.withValues([tqf.deployment.metadata.labels['app.kubernetes.io/name']]), + ]), + ]), + + withServiceMonitor:: { + local tqf = self, + serviceMonitor: { + apiVersion: 'monitoring.coreos.com/v1', + kind: 'ServiceMonitor', + metadata+: { + name: tqf.config.name, + namespace: tqf.config.namespace, + labels: tqf.config.commonLabels, + }, + spec: { + selector: { + matchLabels: tqf.config.podLabelSelector, + }, + endpoints: [ + { + port: 'http', + relabelings: [{ + sourceLabels: ['namespace', 'pod'], + separator: '/', + targetLabel: 'instance', + }], + }, + ], + }, + }, + }, + + withResources:: { + local tqf = self, + config+:: { + resources: error 'must provide resources', + }, + + deployment+: { + spec+: { + template+: { + spec+: { + containers: [ + if c.name == 'thanos-query-frontend' then c { + resources: tqf.config.resources, + } else c + for c in super.containers + ], + }, + }, + }, + }, + }, + + withLogQueriesLongerThan:: { + local tqf = self, + config+:: { + logQueriesLongerThan: error 'must provide logQueriesLongerThan', + }, + + deployment+: { + spec+: { + template+: { + spec+: { + containers: [ + if c.name == 'thanos-query-frontend' then c { + args+: [ + '--query-frontend.log_queries_longer_than=' + tqf.config.logQueriesLongerThan, + ], + } else c + for c in super.containers + ], + }, + }, + }, + }, + }, + + withMaxRetries:: { + local tqf = self, + config+:: { + maxRetries: error 'must provide maxRetries', + }, + + deployment+: { + spec+: { + template+: { + spec+: { + containers: [ + if c.name == 'thanos-query-frontend' then c { + args+: [ + '--query-range.max-retries-per-request=' + tqf.config.maxRetries, + ], + } else c + for c in super.containers + ], + }, + }, + }, + }, + }, + + withSplitInterval:: { + local tqf = self, + config+:: { + splitInterval: error 'must provide splitInterval', + }, + + deployment+: { + spec+: { + template+: { + spec+: { + containers: [ + if c.name == 'thanos-query-frontend' then c { + args+: [ + '--query-range.split-interval=' + tqf.config.splitInterval, + ], + } else c + for c in super.containers + ], + }, + }, + }, + }, + }, + + local fifoCacheDefaults = { + // Don't limit maximum item size. + maxSize: '0', + maxSizeItems: 2048, + validity: '6h', + }, + + withInMemoryResponseCache:: { + local tqf = self, + config+:: { + fifoCache: fifoCacheDefaults, + }, + local m = tqf.config.fifoCache, + local cfg = + { + type: 'in-memory', + config: { + max_size: m.maxSize, + max_size_items: m.maxSizeItems, + validity: m.validity, + }, + }, + deployment+: { + spec+: { + template+: { + spec+: { + containers: [ + if c.name == 'thanos-query-frontend' then c { + args+: if m != {} then [ + '--query-range.response-cache-config=' + std.manifestYamlDoc(cfg), + ] else [], + } else c + for c in super.containers + ], + }, + }, + }, + }, + }, +} diff --git a/jsonnet/kube-thanos/thanos.libsonnet b/jsonnet/kube-thanos/thanos.libsonnet index 755cf65..be1646f 100644 --- a/jsonnet/kube-thanos/thanos.libsonnet +++ b/jsonnet/kube-thanos/thanos.libsonnet @@ -5,4 +5,5 @@ receive: (import 'kube-thanos-receive.libsonnet'), rule: (import 'kube-thanos-rule.libsonnet'), store: (import 'kube-thanos-store.libsonnet'), + queryFrontend: (import 'kube-thanos-query-frontend.libsonnet'), }