Skip to content

Add functions to implement Thanos Receive split functionality #244

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

Merged
merged 6 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tmp
vendor/
jsonnet/kube-thanos/jsonnetfile.lock.json
.idea/
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel
- [#226](https://github.com/thanos-io/kube-thanos/pull/226) Only schedule thanos components on linux nodes.

### Added

- [#244](https://github.com/thanos-io/kube-thanos/pull/244) Add functions to implement Thanos Receive split proposal.
- [#228](https://github.com/thanos-io/kube-thanos/pull/228) Allow configuring `--web.prefix-header` of query.

[Full Changelog](https://github.com/thanos-io/kube-thanos/compare/v0.20.0...v0.21.0)
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,30 @@ local s = t.store(commonConfig.config {
serviceMonitor: true,
});

local split = t.receiveSplit(commonConfig.config {
replicas: 1,
replicaLabels: ['receive_replica'],
replicationFactor: 1,
// Disable shipping to object storage for the purposes of this example
objectStorageConfig: null,
});

local q = t.query(commonConfig.config {
replicas: 1,
replicaLabels: ['prometheus_replica', 'rule_replica'],
serviceMonitor: true,
stores: split.ingestorStores,
});

{ ['thanos-store-' + name]: s[name] for name in std.objectFields(s) } +
{ ['thanos-query-' + name]: q[name] for name in std.objectFields(q) }
{ ['thanos-query-' + name]: q[name] for name in std.objectFields(q) } +
{
['thanos-receive-' + hashring + '-' + resource]: split.ingestors[hashring][resource]
for hashring in std.objectFields(split.ingestors)
for resource in std.objectFields(split.ingestors[hashring])
if split.ingestors[hashring][resource] != null
}
{ ['thanos-receive-' + resource]: split[resource] for resource in std.objectFields(split) if resource != 'ingestors' }
```

And here's the [build.sh](build.sh) script (which uses `vendor/` to render all manifests in a json structure of `{filename: manifest-content}`):
Expand Down
18 changes: 17 additions & 1 deletion example.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,27 @@ local s = t.store(commonConfig.config {
serviceMonitor: true,
});

local split = t.receiveSplit(commonConfig.config {
replicas: 1,
replicaLabels: ['receive_replica'],
replicationFactor: 1,
// Disable shipping to object storage for the purposes of this example
objectStorageConfig: null,
});

local q = t.query(commonConfig.config {
replicas: 1,
replicaLabels: ['prometheus_replica', 'rule_replica'],
serviceMonitor: true,
stores: split.ingestorStores,
});

{ ['thanos-store-' + name]: s[name] for name in std.objectFields(s) } +
{ ['thanos-query-' + name]: q[name] for name in std.objectFields(q) }
{ ['thanos-query-' + name]: q[name] for name in std.objectFields(q) } +
{
['thanos-receive-' + hashring + '-' + resource]: split.ingestors[hashring][resource]
for hashring in std.objectFields(split.ingestors)
for resource in std.objectFields(split.ingestors[hashring])
if split.ingestors[hashring][resource] != null
}
{ ['thanos-receive-' + resource]: split[resource] for resource in std.objectFields(split) if resource != 'ingestors' }
12 changes: 6 additions & 6 deletions examples/all/manifests/thanos-receive-default-statefulSet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ spec:
- --http-address=0.0.0.0:10902
- --remote-write.address=0.0.0.0:19291
- --receive.replication-factor=2
- --objstore.config=$(OBJSTORE_CONFIG)
- --tsdb.path=/var/thanos/receive
- --tsdb.retention=15d
- --receive.local-endpoint=$(NAME).thanos-receive-default.$(NAMESPACE).svc.cluster.local:10901
- --label=replica="$(NAME)"
- --label=receive="true"
- --objstore.config=$(OBJSTORE_CONFIG)
- --receive.local-endpoint=$(NAME).thanos-receive-default.$(NAMESPACE).svc.cluster.local:10901
- --receive.hashrings-file=/var/lib/thanos-receive/hashrings.json
- |-
--tracing.config="config":
Expand All @@ -92,15 +92,15 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: HOST_IP_ADDRESS
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: OBJSTORE_CONFIG
valueFrom:
secretKeyRef:
key: thanos.yaml
name: thanos-objectstorage
- name: HOST_IP_ADDRESS
valueFrom:
fieldRef:
fieldPath: status.hostIP
image: quay.io/thanos/thanos:v0.22.0
livenessProbe:
failureThreshold: 8
Expand Down
12 changes: 6 additions & 6 deletions examples/all/manifests/thanos-receive-region-1-statefulSet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ spec:
- --http-address=0.0.0.0:10902
- --remote-write.address=0.0.0.0:19291
- --receive.replication-factor=2
- --objstore.config=$(OBJSTORE_CONFIG)
- --tsdb.path=/var/thanos/receive
- --tsdb.retention=15d
- --receive.local-endpoint=$(NAME).thanos-receive-region-1.$(NAMESPACE).svc.cluster.local:10901
- --label=replica="$(NAME)"
- --label=receive="true"
- --objstore.config=$(OBJSTORE_CONFIG)
- --receive.local-endpoint=$(NAME).thanos-receive-region-1.$(NAMESPACE).svc.cluster.local:10901
- --receive.hashrings-file=/var/lib/thanos-receive/hashrings.json
- |-
--tracing.config="config":
Expand All @@ -92,15 +92,15 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: HOST_IP_ADDRESS
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: OBJSTORE_CONFIG
valueFrom:
secretKeyRef:
key: thanos.yaml
name: thanos-objectstorage
- name: HOST_IP_ADDRESS
valueFrom:
fieldRef:
fieldPath: status.hostIP
image: quay.io/thanos/thanos:v0.22.0
livenessProbe:
failureThreshold: 8
Expand Down
12 changes: 6 additions & 6 deletions examples/all/manifests/thanos-receive-statefulSet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ spec:
- --http-address=0.0.0.0:10902
- --remote-write.address=0.0.0.0:19291
- --receive.replication-factor=1
- --objstore.config=$(OBJSTORE_CONFIG)
- --tsdb.path=/var/thanos/receive
- --tsdb.retention=15d
- --receive.local-endpoint=$(NAME).thanos-receive.$(NAMESPACE).svc.cluster.local:10901
- --label=replica="$(NAME)"
- --label=receive="true"
- --objstore.config=$(OBJSTORE_CONFIG)
- --receive.local-endpoint=$(NAME).thanos-receive.$(NAMESPACE).svc.cluster.local:10901
- --receive.hashrings-file=/var/lib/thanos-receive/hashrings.json
- |-
--tracing.config="config":
Expand All @@ -88,15 +88,15 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: HOST_IP_ADDRESS
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: OBJSTORE_CONFIG
valueFrom:
secretKeyRef:
key: thanos.yaml
name: thanos-objectstorage
- name: HOST_IP_ADDRESS
valueFrom:
fieldRef:
fieldPath: status.hostIP
image: quay.io/thanos/thanos:v0.22.0
livenessProbe:
failureThreshold: 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
objectStorageConfig: error 'must provide objectStorageConfig',
podDisruptionBudgetMaxUnavailable: (std.floor(defaults.replicationFactor / 2)),
hashringConfigMapName: '',
enableLocalEndpoint: true,
volumeClaimTemplate: {},
retention: '15d',
logLevel: 'info',
Expand Down
160 changes: 160 additions & 0 deletions jsonnet/kube-thanos/kube-thanos-receive-split.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
local receiveConfigDefaults = import 'kube-thanos/kube-thanos-receive-default-params.libsonnet';
local receiveHashring = import 'kube-thanos/kube-thanos-receive-hashrings.libsonnet';

local defaults = receiveConfigDefaults {
hashrings: [{
hashring: 'default',
tenants: [],
}],
hashringConfigmapName: 'hashring-config',
routerReplicas: 1,
};

function(params) {
local tr = self,
// Combine the defaults and the passed params to make the component's config.
config:: defaults + params,

local ingestors = receiveHashring(tr.config { name: tr.config.name + '-ingestor' }),

ingestors: {
['ingestor-' + name]: ingestors.hashrings[name]
for name in std.objectFields(ingestors.hashrings)
},

ingestorStores:: [
'dnssrv+_grpc._tcp.%s.%s.svc.cluster.local:%d' % [ingestors.hashrings[name.hashring].service.metadata.name, tr.config.namespace, tr.config.ports.grpc]
for name in tr.config.hashrings
],

ingestorEndpoints:: {
[name.hashring]: [
'%s-%d.%s.%s.svc.cluster.local:%d' % [
ingestors.hashrings[name.hashring].service.metadata.name,
i,
ingestors.hashrings[name.hashring].service.metadata.name,
tr.config.namespace,
tr.config.ports.grpc,
]
// Replica specification is 1-based, but statefulSets are named 0-based.
for i in std.range(0, tr.config.replicas - 1)
]
for name in tr.config.hashrings
},

routerLabels:: tr.config.commonLabels {
'app.kubernetes.io/component': tr.config.name + '-router',
},

'router-service': {
apiVersion: 'v1',
kind: 'Service',
metadata: {
name: tr.config.name + '-router',
namespace: tr.config.namespace,
},
spec: {
ports: [{ name: name, port: tr.config.ports[name] } for name in std.objectFields(tr.config.ports)],
selector: tr.routerLabels,
},
},

'router-configmap': {
apiVersion: 'v1',
kind: 'ConfigMap',
metadata: {
name: tr.config.hashringConfigMapName,
namespace: tr.config.namespace,
},
data: {
'hashrings.json': std.toString([hashring { endpoints: tr.ingestorEndpoints[hashring.hashring] } for hashring in tr.config.hashrings]),
},
},

// Create the deployment that acts as a router to the ingestor backends
'router-deployment': {
apiVersion: 'apps/v1',
kind: 'Deployment',
metadata: {
name: tr.config.name + '-router',
namespace: tr.config.namespace,
labels: tr.routerLabels,
},
spec: {
replicas: tr.config.routerReplicas,
selector: { matchLabels: tr.routerLabels },
template: {
metadata: {
labels: tr.routerLabels,
},
spec: {
serviceAccountName: ingestors.serviceAccount.metadata.name,
securityContext: tr.config.securityContext,
containers: [{
name: 'thanos-receive',
image: tr.config.image,
args: [
'receive',
'--log.level=' + tr.config.logLevel,
'--log.format=' + tr.config.logFormat,
'--grpc-address=0.0.0.0:%d' % tr.config.ports.grpc,
'--http-address=0.0.0.0:%d' % tr.config.ports.http,
'--remote-write.address=0.0.0.0:%d' % tr.config.ports['remote-write'],
'--receive.replication-factor=%d' % tr.config.replicationFactor,
'--receive.hashrings-file=/var/lib/thanos-receive/hashrings.json',
] + [
'--label=%s' % label
for label in tr.config.labels
] + (
if tr.config.tenantLabelName != null then [
'--receive.tenant-label-name=%s' % tr.config.tenantLabelName,
] else []
) + (
if std.length(tr.config.tracing) > 0 then [
'--tracing.config=' + std.manifestYamlDoc(
{ config+: { service_name: defaults.name } } + tr.config.tracing
),
] else []
),
env: [
{ name: 'NAME', valueFrom: { fieldRef: { fieldPath: 'metadata.name' } } },
{ name: 'NAMESPACE', valueFrom: { fieldRef: { fieldPath: 'metadata.namespace' } } },
{
// Inject the host IP to make configuring tracing convenient.
name: 'HOST_IP_ADDRESS',
valueFrom: {
fieldRef: {
fieldPath: 'status.hostIP',
},
},
},
],
ports: [{ name: name, containerPort: tr.config.ports[name] } for name in std.objectFields(tr.config.ports)],
volumeMounts: [{ name: 'hashring-config', mountPath: '/var/lib/thanos-receive' }],
livenessProbe: { failureThreshold: 8, periodSeconds: 30, httpGet: {
scheme: 'HTTP',
port: tr.config.ports.http,
path: '/-/healthy',
} },
readinessProbe: { failureThreshold: 20, periodSeconds: 5, httpGet: {
scheme: 'HTTP',
port: tr.config.ports.http,
path: '/-/ready',
} },
resources: if tr.config.resources != {} then tr.config.resources else {},
terminationMessagePolicy: 'FallbackToLogsOnError',
}],
volumes: [{
name: 'hashring-config',
configMap: { name: tr.config.hashringConfigMapName },
}],
terminationGracePeriodSeconds: 30,
nodeSelector: {
'beta.kubernetes.io/os': 'linux',
},
},
},
},
},
serviceAccount: ingestors.serviceAccount,
}
24 changes: 17 additions & 7 deletions jsonnet/kube-thanos/kube-thanos-receive.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ function(params) {
'--http-address=0.0.0.0:%d' % tr.config.ports.http,
'--remote-write.address=0.0.0.0:%d' % tr.config.ports['remote-write'],
'--receive.replication-factor=%d' % tr.config.replicationFactor,
'--objstore.config=$(OBJSTORE_CONFIG)',
'--tsdb.path=/var/thanos/receive',
'--tsdb.retention=' + tr.config.retention,
localEndpointFlag,
] + [
'--label=%s' % label
for label in tr.config.labels
] + (
if tr.config.objectStorageConfig != null then [
'--objstore.config=$(OBJSTORE_CONFIG)',
] else []
) + (
if tr.config.enableLocalEndpoint then [
localEndpointFlag,
] else []
) + (
if tr.config.tenantLabelName != null then [
'--receive.tenant-label-name=%s' % tr.config.tenantLabelName,
] else []
Expand All @@ -90,10 +96,6 @@ function(params) {
env: [
{ name: 'NAME', valueFrom: { fieldRef: { fieldPath: 'metadata.name' } } },
{ name: 'NAMESPACE', valueFrom: { fieldRef: { fieldPath: 'metadata.namespace' } } },
{ name: 'OBJSTORE_CONFIG', valueFrom: { secretKeyRef: {
key: tr.config.objectStorageConfig.key,
name: tr.config.objectStorageConfig.name,
} } },
{
// Inject the host IP to make configuring tracing convenient.
name: 'HOST_IP_ADDRESS',
Expand All @@ -103,7 +105,15 @@ function(params) {
},
},
},
],
] + (
if tr.config.objectStorageConfig != null then [{
name: 'OBJSTORE_CONFIG',
valueFrom: { secretKeyRef: {
key: tr.config.objectStorageConfig.key,
name: tr.config.objectStorageConfig.name,
} },
}] else []
),
ports: [
{ name: name, containerPort: tr.config.ports[name] }
for name in std.objectFields(tr.config.ports)
Expand Down
Loading