From 9a45201d1cfd60a007f5fe6c0f380dd1e00f232d Mon Sep 17 00:00:00 2001 From: Owen Diehl Date: Wed, 26 Aug 2020 14:17:42 -0400 Subject: [PATCH 1/2] ruler jsonnet --- production/ksonnet/loki/config.libsonnet | 26 +++++++++++++++++ production/ksonnet/loki/images.libsonnet | 1 + production/ksonnet/loki/loki.libsonnet | 1 + production/ksonnet/loki/ruler.libsonnet | 37 ++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 production/ksonnet/loki/ruler.libsonnet diff --git a/production/ksonnet/loki/config.libsonnet b/production/ksonnet/loki/config.libsonnet index d00fc6e80a1b..7887514cdc68 100644 --- a/production/ksonnet/loki/config.libsonnet +++ b/production/ksonnet/loki/config.libsonnet @@ -41,6 +41,8 @@ table_prefix: $._config.namespace, index_period_hours: 168, // 1 week + ruler_enabled: false, + // Bigtable variables bigtable_instance: error 'must specify bigtable instance', bigtable_project: error 'must specify bigtable project', @@ -308,6 +310,30 @@ }, }, }, + + ruler: { + rule_path: '/tmp/rules', + enable_api: true, + alertmanager_url: ['http://alertmanager.%s.svc.cluster.local/alertmanager' % $._config.namespace,], + enable_alertmanager_discovery: true, + enable_sharding: true, + enable_alertmanager_v2: true, + ring: { + kvstore: { + store: 'consul', + consul: { + host: 'consul.%ss.svc.cluster.local:8500' % $._config.namespace, + }, + }, + }, + storage+: { + type: 'gcs', + gcs+: { + bucket_name: '%(cluster)s-%(namespace)s-ruler' % $._config, + }, + }, + }, + }, }, diff --git a/production/ksonnet/loki/images.libsonnet b/production/ksonnet/loki/images.libsonnet index 71e3030d036b..fa7188c492fe 100644 --- a/production/ksonnet/loki/images.libsonnet +++ b/production/ksonnet/loki/images.libsonnet @@ -11,5 +11,6 @@ querier: self.loki, tableManager: self.loki, query_frontend: self.loki, + ruler: self.loki, }, } diff --git a/production/ksonnet/loki/loki.libsonnet b/production/ksonnet/loki/loki.libsonnet index 7714b6ee4300..141a2f8e073e 100644 --- a/production/ksonnet/loki/loki.libsonnet +++ b/production/ksonnet/loki/loki.libsonnet @@ -12,6 +12,7 @@ (import 'querier.libsonnet') + (import 'table-manager.libsonnet') + (import 'query-frontend.libsonnet') + +(import 'ruler.libsonnet') + // Supporting services (import 'memcached.libsonnet') diff --git a/production/ksonnet/loki/ruler.libsonnet b/production/ksonnet/loki/ruler.libsonnet new file mode 100644 index 000000000000..838f8cc93bc8 --- /dev/null +++ b/production/ksonnet/loki/ruler.libsonnet @@ -0,0 +1,37 @@ +{ + local container = $.core.v1.container, + + ruler_args:: { + target: 'ruler', + }, + + ruler_container:: + if $._config.ruler_enabled then + container.new('ruler', $._images.ruler) + + container.withPorts($.util.defaultPorts) + + container.withArgsMixin($.util.mapToFlags($.ruler_args)) + + $.util.resourcesRequests('1', '6Gi') + + $.util.resourcesLimits('16', '16Gi') + + $.util.readinessProbe + + $.jaeger_mixin + else {}, + + local deployment = $.apps.v1.deployment, + + ruler_deployment: + if $._config.ruler_enabled then + deployment.new('ruler', 2, [$.ruler_container]) + + deployment.mixin.spec.template.spec.withTerminationGracePeriodSeconds(600) + + $.config_hash_mixin + + $.util.configVolumeMount('loki', '/etc/loki/config') + + $.util.configVolumeMount('overrides', '/etc/cortex') + + $.util.antiAffinity + + else {}, + + local service = $.core.v1.service, + + ruler_service: + if $._config.ruler_enabled then + $.util.serviceFor($.ruler_deployment) + else {}, +} From 8dbd0f3026e5b9c3ef8253851bdf5b81d7421d36 Mon Sep 17 00:00:00 2001 From: Owen Diehl Date: Wed, 26 Aug 2020 15:27:33 -0400 Subject: [PATCH 2/2] jsonnet fixes --- production/ksonnet/loki/common.libsonnet | 8 ++++++++ production/ksonnet/loki/config.libsonnet | 9 ++++----- production/ksonnet/loki/ruler.libsonnet | 6 +++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/production/ksonnet/loki/common.libsonnet b/production/ksonnet/loki/common.libsonnet index eefc8c9e0dfa..f233a0c1eb3d 100644 --- a/production/ksonnet/loki/common.libsonnet +++ b/production/ksonnet/loki/common.libsonnet @@ -4,11 +4,19 @@ util+:: { local containerPort = $.core.v1.containerPort, + local container = $.core.v1.container, defaultPorts:: [ containerPort.new(name='http-metrics', port=$._config.http_listen_port), containerPort.new(name='grpc', port=9095), ], + + readinessProbe:: + container.mixin.readinessProbe.httpGet.withPath('/ready') + + container.mixin.readinessProbe.httpGet.withPort($._config.http_listen_port) + + container.mixin.readinessProbe.withInitialDelaySeconds(15) + + container.mixin.readinessProbe.withTimeoutSeconds(1), + }, } diff --git a/production/ksonnet/loki/config.libsonnet b/production/ksonnet/loki/config.libsonnet index 7887514cdc68..5389bdd697bc 100644 --- a/production/ksonnet/loki/config.libsonnet +++ b/production/ksonnet/loki/config.libsonnet @@ -311,18 +311,17 @@ }, }, - ruler: { + ruler: if $._config.ruler_enabled then { rule_path: '/tmp/rules', enable_api: true, - alertmanager_url: ['http://alertmanager.%s.svc.cluster.local/alertmanager' % $._config.namespace,], - enable_alertmanager_discovery: true, + alertmanager_url: 'http://alertmanager.%s.svc.cluster.local/alertmanager' % $._config.namespace, enable_sharding: true, enable_alertmanager_v2: true, ring: { kvstore: { store: 'consul', consul: { - host: 'consul.%ss.svc.cluster.local:8500' % $._config.namespace, + host: 'consul.%s.svc.cluster.local:8500' % $._config.namespace, }, }, }, @@ -332,7 +331,7 @@ bucket_name: '%(cluster)s-%(namespace)s-ruler' % $._config, }, }, - }, + } else {}, }, }, diff --git a/production/ksonnet/loki/ruler.libsonnet b/production/ksonnet/loki/ruler.libsonnet index 838f8cc93bc8..f769d2fd09bb 100644 --- a/production/ksonnet/loki/ruler.libsonnet +++ b/production/ksonnet/loki/ruler.libsonnet @@ -1,7 +1,7 @@ { local container = $.core.v1.container, - ruler_args:: { + ruler_args:: $._config.commonArgs { target: 'ruler', }, @@ -24,8 +24,8 @@ deployment.mixin.spec.template.spec.withTerminationGracePeriodSeconds(600) + $.config_hash_mixin + $.util.configVolumeMount('loki', '/etc/loki/config') + - $.util.configVolumeMount('overrides', '/etc/cortex') + - $.util.antiAffinity + + $.util.configVolumeMount('overrides', '/etc/loki/overrides') + + $.util.antiAffinity else {}, local service = $.core.v1.service,