Skip to content

Commit

Permalink
*: Refactor to not mutate global objects
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic Branczyk <fbranczyk@gmail.com>
  • Loading branch information
brancz committed Feb 3, 2020
1 parent 14ecdd5 commit f808152
Show file tree
Hide file tree
Showing 43 changed files with 1,423 additions and 982 deletions.
112 changes: 82 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,90 @@ Here's [example.jsonnet](example.jsonnet):
local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
local sts = k.apps.v1.statefulSet;
local deployment = k.apps.v1.deployment;
local kt =
(import 'kube-thanos/kube-thanos-querier.libsonnet') +
(import 'kube-thanos/kube-thanos-store.libsonnet') +
// (import 'kube-thanos/kube-thanos-pvc.libsonnet') + // Uncomment this line to enable PVCs
// (import 'kube-thanos/kube-thanos-receive.libsonnet') +
// (import 'kube-thanos/kube-thanos-sidecar.libsonnet') +
// (import 'kube-thanos/kube-thanos-servicemonitors.libsonnet') +
{
thanos+:: {
// This is just an example image, set what you need
image:: 'quay.io/thanos/thanos:v0.9.0',
objectStorageConfig+:: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
querier+: {
replicas:: 3,
},
store+: {
replicas:: 1,
local t = (import 'kube-thanos/thanos.libsonnet');
local commonConfig = {
config+:: {
namespace: 'thanos',
version: '0.10.1',
image: 'quay.io/thanos/thanos:v0.10.1',
objectStorageConfig: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
volumeClaimTemplate: {
spec: {
accessModes: ['ReadWriteOnce'],
resources: {
requests: {
storage: '10Gi',
},
},
},
},
};
{ ['thanos-querier-' + name]: kt.thanos.querier[name] for name in std.objectFields(kt.thanos.querier) } +
{ ['thanos-store-' + name]: kt.thanos.store[name] for name in std.objectFields(kt.thanos.store) }
// { ['thanos-receive-' + name]: kt.thanos.receive[name] for name in std.objectFields(kt.thanos.receive) }
},
};
//local b = t.bucket + commonConfig + {
// config+:: {
// name: 'thanos-bucket',
// replicas: 1,
// },
//};
//
//local c = t.compactor + t.compactor.withVolumeClaimTemplate + t.compactor.withServiceMonitor + commonConfig + {
// config+:: {
// name: 'thanos-compactor',
// replicas: 1,
// },
//};
//
//local re = t.receive + t.receive.withVolumeClaimTemplate + t.receive.withServiceMonitor + commonConfig + {
// config+:: {
// name: 'thanos-receive',
// replicas: 1,
// replicationFactor: 1,
// },
//};
//
//local ru = t.ruler + t.ruler.withVolumeClaimTemplate + t.ruler.withServiceMonitor + commonConfig + {
// config+:: {
// name: 'thanos-ruler',
// replicas: 1,
// },
//};
local s = t.store + t.store.withVolumeClaimTemplate + t.store.withServiceMonitor + commonConfig + {
config+:: {
name: 'thanos-store',
replicas: 1,
},
};
local q = t.querier + t.querier.withServiceMonitor + commonConfig + {
config+:: {
name: 'thanos-query',
replicas: 1,
stores: [
'dnssrv+_grpc._tcp.%s.%s.svc.cluster.local' % [service.metadata.name, service.metadata.namespace]
for service in [s.service]
],
replicaLabels: ['prometheus_replica', 'ruler_replica'],
},
};
//local finalRu = ru {
// config+:: {
// queriers: ['dnssrv+_http._tcp.%s.%s.svc.cluster.local' % [q.service.metadata.name, q.service.metadata.namespace]],
// },
//};
//{ ['thanos-bucket-' + name]: b[name] for name in std.objectFields(b) } +
//{ ['thanos-compactor-' + name]: c[name] for name in std.objectFields(c) } +
//{ ['thanos-receive-' + name]: re[name] for name in std.objectFields(re) } +
//{ ['thanos-ruler-' + name]: finalRu[name] for name in std.objectFields(finalRu) } +
{ ['thanos-store-' + name]: s[name] for name in std.objectFields(s) } +
{ ['thanos-querier-' + name]: q[name] for name in std.objectFields(q) }
```

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
142 changes: 98 additions & 44 deletions all.jsonnet
Original file line number Diff line number Diff line change
@@ -1,48 +1,102 @@
local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
local sts = k.apps.v1.statefulSet;
local deployment = k.apps.v1.deployment;

local kt =
(import 'kube-thanos/kube-thanos-compactor.libsonnet') +
(import 'kube-thanos/kube-thanos-querier.libsonnet') +
(import 'kube-thanos/kube-thanos-store.libsonnet') +
(import 'kube-thanos/kube-thanos-store-pvc.libsonnet') +
(import 'kube-thanos/kube-thanos-receive.libsonnet') +
(import 'kube-thanos/kube-thanos-receive-pvc.libsonnet') +
(import 'kube-thanos/kube-thanos-sidecar.libsonnet') +
(import 'kube-thanos/kube-thanos-servicemonitors.libsonnet') +
(import 'kube-thanos/kube-thanos-bucket.libsonnet') +
(import 'kube-thanos/kube-thanos-ruler.libsonnet') +
{
thanos+:: {
// This is just an example image, set what you need
image:: 'quay.io/thanos/thanos:v0.9.0',
objectStorageConfig+:: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
local t = (import 'kube-thanos/thanos.libsonnet');

querier+: {
replicas:: 3,
},
store+: {
replicas:: 1,
pvc+:: {
size: '50Gi',
},
{
local obs = self,
config+:: {
namespace: error 'must provide namespace',
thanosVersion: error 'must provide thanosVersion',
thanosImage: error 'must provide thanosImage',
objectStorageConfig: error 'must provide objectStorageConfig',
hashrings: error 'must provide hashring configuration',
},

compactor:
t.compactor +
t.compactor.withVolumeClaimTemplate +
t.compactor.withRetention +
t.compactor.withDownsamplingDisabled +
t.compactor.withServiceMonitor +
obs.config + {
config+:: {
name: 'thanos-compactor',
replicas: 1,
retentionResolutionRaw: '14d',
retentionResolution5m: '1s',
retentionResolution1h: '1s',
},
receive+: {
replicas:: 3,
pvc+:: {
size: '50Gi',
},

'thanos-receive-controller': (import 'thanos-receive-controller/thanos-receive-controller.libsonnet') + {
config+:: {
name: 'thanos-receive-controller',
namespace: obs.config.namespace,
version: 'latest',
image: 'quay.io/observatorium/thanos-receive-controller:latest',
replicas: 1,
hashrings: hashrings,
},
},

receivers: {
[hashring]:
t.receive +
t.receive.withVolumeClaimTemplate +
t.receive.withRetention +
t.receive.withHashringConfigMap +
t.receive.withServiceMonitor +
obs.config + {
config+:: {
name: 'thanos-receive-' + hashring,
replicas: 3,
replicationFactor: 3,
retention: '6h',
hashringConfigMapName: '%s-generated' % trc.configmap.metadata.name,
volumeClaimTemplate: {
spec: {
accessModes: ['ReadWriteOnce'],
resources: {
requests: {
storage: '50Gi',
},
},
},
},
},
},
}
for hashring in hashrings
},

ruler: t.ruler + t.ruler.withVolumeClaimTemplate + t.ruler.withServiceMonitor + obs.config + {
config+:: {
name: 'thanos-ruler',
replicas: 2,
},
},

store: t.store + t.store.withVolumeClaimTemplate + t.store.withServiceMonitor + obs.config + {
config+:: {
name: 'thanos-store',
replicas: 1,
},
},

querier: t.querier + t.querier.withServiceMonitor + obs.config + {
config+:: {
name: 'thanos-query',
replicas: 1,
stores: [
'dnssrv+_grpc._tcp.%s.%s.svc.cluster.local' % [service.metadata.name, service.metadata.namespace]
for service in [obs.ruler.service, obs.store.service] + [receiver.service for receiver in obs.receivers]
],
replicaLabels: ['prometheus_replica', 'ruler_replica'],
},
},
} + {
local obs = self,

ruler+: {
config+:: {
queriers: ['dnssrv+_http._tcp.%s.%s.svc.cluster.local' % [obs.querier.service.metadata.name, obs.querier.service.metadata.namespace]],
},
};

{ ['thanos-compactor-' + name]: kt.thanos.compactor[name] for name in std.objectFields(kt.thanos.compactor) } +
{ ['thanos-querier-' + name]: kt.thanos.querier[name] for name in std.objectFields(kt.thanos.querier) } +
{ ['thanos-receive-' + name]: kt.thanos.receive[name] for name in std.objectFields(kt.thanos.receive) } +
{ ['thanos-bucket-' + name]: kt.thanos.bucket[name] for name in std.objectFields(kt.thanos.bucket) } +
{ ['thanos-store-' + name]: kt.thanos.store[name] for name in std.objectFields(kt.thanos.store) } +
{ ['thanos-ruler-' + name]: kt.thanos.ruler[name] for name in std.objectFields(kt.thanos.ruler) }
},
}
102 changes: 77 additions & 25 deletions example.jsonnet
Original file line number Diff line number Diff line change
@@ -1,35 +1,87 @@
local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
local sts = k.apps.v1.statefulSet;
local deployment = k.apps.v1.deployment;
local t = (import 'kube-thanos/thanos.libsonnet');

local kt =
(import 'kube-thanos/kube-thanos-querier.libsonnet') +
(import 'kube-thanos/kube-thanos-store.libsonnet') +
// (import 'kube-thanos/kube-thanos-pvc.libsonnet') + // Uncomment this line to enable PVCs
// (import 'kube-thanos/kube-thanos-receive.libsonnet') +
// (import 'kube-thanos/kube-thanos-sidecar.libsonnet') +
// (import 'kube-thanos/kube-thanos-servicemonitors.libsonnet') +
{
thanos+:: {
// This is just an example image, set what you need
image:: 'quay.io/thanos/thanos:v0.9.0',
objectStorageConfig+:: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},

querier+: {
replicas:: 3,
},
store+: {
replicas:: 1,
local commonConfig = {
config+:: {
namespace: 'thanos',
version: '0.10.1',
image: 'quay.io/thanos/thanos:v0.10.1',
objectStorageConfig: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
volumeClaimTemplate: {
spec: {
accessModes: ['ReadWriteOnce'],
resources: {
requests: {
storage: '10Gi',
},
},
},
},
};
},
};

//local b = t.bucket + commonConfig + {
// config+:: {
// name: 'thanos-bucket',
// replicas: 1,
// },
//};
//
//local c = t.compactor + t.compactor.withVolumeClaimTemplate + t.compactor.withServiceMonitor + commonConfig + {
// config+:: {
// name: 'thanos-compactor',
// replicas: 1,
// },
//};
//
//local re = t.receive + t.receive.withVolumeClaimTemplate + t.receive.withServiceMonitor + commonConfig + {
// config+:: {
// name: 'thanos-receive',
// replicas: 1,
// replicationFactor: 1,
// },
//};
//
//local ru = t.ruler + t.ruler.withVolumeClaimTemplate + t.ruler.withServiceMonitor + commonConfig + {
// config+:: {
// name: 'thanos-ruler',
// replicas: 1,
// },
//};

{ ['thanos-querier-' + name]: kt.thanos.querier[name] for name in std.objectFields(kt.thanos.querier) } +
{ ['thanos-store-' + name]: kt.thanos.store[name] for name in std.objectFields(kt.thanos.store) }
// { ['thanos-receive-' + name]: kt.thanos.receive[name] for name in std.objectFields(kt.thanos.receive) }
local s = t.store + t.store.withVolumeClaimTemplate + t.store.withServiceMonitor + commonConfig + {
config+:: {
name: 'thanos-store',
replicas: 1,
},
};

local q = t.querier + t.querier.withServiceMonitor + commonConfig + {
config+:: {
name: 'thanos-query',
replicas: 1,
stores: [
'dnssrv+_grpc._tcp.%s.%s.svc.cluster.local' % [service.metadata.name, service.metadata.namespace]
for service in [s.service]
],
replicaLabels: ['prometheus_replica', 'ruler_replica'],
},
};

//local finalRu = ru {
// config+:: {
// queriers: ['dnssrv+_http._tcp.%s.%s.svc.cluster.local' % [q.service.metadata.name, q.service.metadata.namespace]],
// },
//};

//{ ['thanos-bucket-' + name]: b[name] for name in std.objectFields(b) } +
//{ ['thanos-compactor-' + name]: c[name] for name in std.objectFields(c) } +
//{ ['thanos-receive-' + name]: re[name] for name in std.objectFields(re) } +
//{ ['thanos-ruler-' + name]: finalRu[name] for name in std.objectFields(finalRu) } +
{ ['thanos-store-' + name]: s[name] for name in std.objectFields(s) } +
{ ['thanos-querier-' + name]: q[name] for name in std.objectFields(q) }
Loading

0 comments on commit f808152

Please sign in to comment.