Add Thanos Query Frontend component (#142)

* add thanos query frontend component

Signed-off-by: Ben Ye <yb532204897@gmail.com>

* add changelog

Signed-off-by: Ben Ye <yb532204897@gmail.com>
This commit is contained in:
Ben Ye 2020-08-12 07:47:04 -04:00 committed by GitHub
parent 683c533e7e
commit 1c19d6ec9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 430 additions and 33 deletions

View File

@ -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)

View File

@ -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 }

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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
],
},
},
},
},
},
}

View File

@ -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'),
}