From ea89505a8b51451fba89870d36cc2319e2ee974f Mon Sep 17 00:00:00 2001 From: Karsten Jeschkies Date: Thu, 5 Aug 2021 15:35:45 +0200 Subject: [PATCH 1/2] Define ksonnet definition for query scheduler. --- .../ksonnet/loki/query-scheduler.libsonnet | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 production/ksonnet/loki/query-scheduler.libsonnet diff --git a/production/ksonnet/loki/query-scheduler.libsonnet b/production/ksonnet/loki/query-scheduler.libsonnet new file mode 100644 index 0000000000000..1265f3f918763 --- /dev/null +++ b/production/ksonnet/loki/query-scheduler.libsonnet @@ -0,0 +1,58 @@ + +local k = import 'ksonnet-util/kausal.libsonnet'; + +{ + local container = k.core.v1.container, + + // Override frontend and querier configuration + local override = { + frontend: { + scheduler_address: 'query-scheduler.%s.svc.cluster.local:9095' % $._config.namespace, + }, + frontend_worker: { + frontend_address: '', + scheduler_address: 'query-scheduler.%s.svc.cluster.local:9095' % $._config.namespace, + }, + }, + _config +: { + loki: std.mergePatch($._config.loki, override), + }, + + query_scheduler_args:: + $._config.commonArgs { + target: 'query-scheduler', + 'log.level': 'debug', + }, + + query_scheduler_container:: + container.new('query-scheduler', $._images.query_frontend) + + container.withPorts($.util.defaultPorts) + + container.withArgsMixin(k.util.mapToFlags($.query_frontend_args)) + + $.jaeger_mixin + + // sharded queries may need to do a nonzero amount of aggregation on the frontend. + if $._config.queryFrontend.sharded_queries_enabled then + k.util.resourcesRequests('2', '2Gi') + + k.util.resourcesLimits(null, '6Gi') + + container.withEnvMap({ + JAEGER_REPORTER_MAX_QUEUE_SIZE: '5000', + }) + else k.util.resourcesRequests('2', '600Mi') + + k.util.resourcesLimits(null, '1200Mi'), + + local deployment = k.apps.v1.deployment, + + query_scheduler_deployment: + deployment.new('query-scheduler', 1, [$.query_scheduler_container]) + + $.config_hash_mixin + + k.util.configVolumeMount('loki', '/etc/loki/config') + + k.util.configVolumeMount( + $._config.overrides_configmap_mount_name, + $._config.overrides_configmap_mount_path, + ) + + k.util.antiAffinity, + + local service = k.core.v1.service, + + query_scheduler_service: + k.util.serviceFor($.query_schduler_deployment) +} From 9941eb50701e03a2700d3e0755de0df245d75aea Mon Sep 17 00:00:00 2001 From: Karsten Jeschkies Date: Tue, 10 Aug 2021 17:14:23 +0200 Subject: [PATCH 2/2] Enable query scheduler based on config flag. --- production/ksonnet/loki/config.libsonnet | 1 + production/ksonnet/loki/loki.libsonnet | 4 ++ .../ksonnet/loki/query-scheduler.libsonnet | 55 ++++++++----------- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/production/ksonnet/loki/config.libsonnet b/production/ksonnet/loki/config.libsonnet index d82c6280bf8ab..006143db7c909 100644 --- a/production/ksonnet/loki/config.libsonnet +++ b/production/ksonnet/loki/config.libsonnet @@ -13,6 +13,7 @@ using_boltdb_shipper: true, wal_enabled: false, + query_scheduler_enabled: false, // flags for running ingesters/queriers as a statefulset instead of deployment type. stateful_ingesters: false, diff --git a/production/ksonnet/loki/loki.libsonnet b/production/ksonnet/loki/loki.libsonnet index 0dc308acc44ef..db311f304297d 100644 --- a/production/ksonnet/loki/loki.libsonnet +++ b/production/ksonnet/loki/loki.libsonnet @@ -13,6 +13,10 @@ (import 'query-frontend.libsonnet') + (import 'ruler.libsonnet') + +// Query scheduler support +// must be mixed in after frontend and querier so it can override their configuration. +(import 'query-scheduler.libsonnet') + + // Supporting services (import 'memcached.libsonnet') + diff --git a/production/ksonnet/loki/query-scheduler.libsonnet b/production/ksonnet/loki/query-scheduler.libsonnet index 1265f3f918763..fbab6129b6a43 100644 --- a/production/ksonnet/loki/query-scheduler.libsonnet +++ b/production/ksonnet/loki/query-scheduler.libsonnet @@ -2,57 +2,50 @@ local k = import 'ksonnet-util/kausal.libsonnet'; { - local container = k.core.v1.container, - // Override frontend and querier configuration - local override = { - frontend: { - scheduler_address: 'query-scheduler.%s.svc.cluster.local:9095' % $._config.namespace, + _config +:: { + loki+: if $._config.query_scheduler_enabled then { + frontend+: { + scheduler_address: 'query-scheduler.%s.svc.cluster.local:9095' % $._config.namespace, }, - frontend_worker: { - frontend_address: '', - scheduler_address: 'query-scheduler.%s.svc.cluster.local:9095' % $._config.namespace, + frontend_worker+: { + frontend_address: '', + scheduler_address: 'query-scheduler.%s.svc.cluster.local:9095' % $._config.namespace, }, - }, - _config +: { - loki: std.mergePatch($._config.loki, override), + } else {}, }, - query_scheduler_args:: + query_scheduler_args:: if $._config.query_scheduler_enabled then $._config.commonArgs { target: 'query-scheduler', 'log.level': 'debug', - }, + } + else {}, - query_scheduler_container:: + local container = k.core.v1.container, + query_scheduler_container:: if $._config.query_scheduler_enabled then container.new('query-scheduler', $._images.query_frontend) + container.withPorts($.util.defaultPorts) + - container.withArgsMixin(k.util.mapToFlags($.query_frontend_args)) + + container.withArgsMixin(k.util.mapToFlags($.query_scheduler_args)) + $.jaeger_mixin + - // sharded queries may need to do a nonzero amount of aggregation on the frontend. - if $._config.queryFrontend.sharded_queries_enabled then - k.util.resourcesRequests('2', '2Gi') + - k.util.resourcesLimits(null, '6Gi') + - container.withEnvMap({ - JAEGER_REPORTER_MAX_QUEUE_SIZE: '5000', - }) - else k.util.resourcesRequests('2', '600Mi') + - k.util.resourcesLimits(null, '1200Mi'), + k.util.resourcesRequests('2', '600Mi') + + k.util.resourcesLimits(null, '1200Mi') + else {}, local deployment = k.apps.v1.deployment, - - query_scheduler_deployment: - deployment.new('query-scheduler', 1, [$.query_scheduler_container]) + + query_scheduler_deployment: if $._config.query_scheduler_enabled then + deployment.new('query-scheduler', 2, [$.query_scheduler_container]) + $.config_hash_mixin + k.util.configVolumeMount('loki', '/etc/loki/config') + k.util.configVolumeMount( $._config.overrides_configmap_mount_name, $._config.overrides_configmap_mount_path, ) + - k.util.antiAffinity, + k.util.antiAffinity + else {}, local service = k.core.v1.service, - - query_scheduler_service: - k.util.serviceFor($.query_schduler_deployment) + query_scheduler_service: if $._config.query_scheduler_enabled then + k.util.serviceFor($.query_scheduler_deployment) + else {}, }