|
| 1 | +{ |
| 2 | + local container = $.core.v1.container, |
| 3 | + local pvc = $.core.v1.persistentVolumeClaim, |
| 4 | + local statefulSet = $.apps.v1.statefulSet, |
| 5 | + local volumeMount = $.core.v1.volumeMount, |
| 6 | + |
| 7 | + // The compactor runs a statefulset with a single replica, because |
| 8 | + // it does not support horizontal scalability yet. |
| 9 | + local compactor_data_pvc = |
| 10 | + pvc.new() + |
| 11 | + pvc.mixin.spec.resources.withRequests({ storage: $._config.cortex_compactor_data_disk_size }) + |
| 12 | + pvc.mixin.spec.withAccessModes(['ReadWriteOnce']) + |
| 13 | + pvc.mixin.spec.withStorageClassName($._config.cortex_compactor_data_disk_class) + |
| 14 | + pvc.mixin.metadata.withName('compactor-data'), |
| 15 | + |
| 16 | + compactor_args:: |
| 17 | + $._config.grpcConfig + |
| 18 | + $._config.blocksStorageConfig + |
| 19 | + $._config.compactorLimitsConfig + |
| 20 | + { |
| 21 | + target: 'compactor', |
| 22 | + |
| 23 | + // Compactor config. |
| 24 | + 'compactor.block-ranges': '2h,12h,24h', |
| 25 | + 'compactor.data-dir': '/data', |
| 26 | + 'compactor.compaction-interval': '30m', |
| 27 | + 'compactor.compaction-concurrency': $._config.cortex_compactor_max_concurrency, |
| 28 | + 'compactor.cleanup-interval': $._config.cortex_compactor_cleanup_interval, |
| 29 | + |
| 30 | + // Enable sharding. |
| 31 | + 'compactor.sharding-enabled': true, |
| 32 | + 'compactor.ring.store': 'consul', |
| 33 | + 'compactor.ring.consul.hostname': 'consul.%s.svc.cluster.local:8500' % $._config.namespace, |
| 34 | + 'compactor.ring.prefix': '', |
| 35 | + |
| 36 | + // Limits config. |
| 37 | + 'runtime-config.file': '/etc/cortex/overrides.yaml', |
| 38 | + }, |
| 39 | + |
| 40 | + compactor_ports:: $.util.defaultPorts, |
| 41 | + |
| 42 | + compactor_container:: |
| 43 | + container.new('compactor', $._images.compactor) + |
| 44 | + container.withPorts($.compactor_ports) + |
| 45 | + container.withArgsMixin($.util.mapToFlags($.compactor_args)) + |
| 46 | + container.withVolumeMountsMixin([volumeMount.new('compactor-data', '/data')]) + |
| 47 | + // Do not limit compactor CPU and request enough cores to honor configured max concurrency. |
| 48 | + $.util.resourcesRequests($._config.cortex_compactor_max_concurrency, '6Gi') + |
| 49 | + $.util.resourcesLimits(null, '6Gi') + |
| 50 | + $.util.readinessProbe + |
| 51 | + $.jaeger_mixin, |
| 52 | + |
| 53 | + newCompactorStatefulSet(name, container):: |
| 54 | + statefulSet.new(name, 1, [container], compactor_data_pvc) + |
| 55 | + statefulSet.mixin.spec.withServiceName(name) + |
| 56 | + statefulSet.mixin.metadata.withNamespace($._config.namespace) + |
| 57 | + statefulSet.mixin.metadata.withLabels({ name: name }) + |
| 58 | + statefulSet.mixin.spec.template.metadata.withLabels({ name: name }) + |
| 59 | + statefulSet.mixin.spec.selector.withMatchLabels({ name: name }) + |
| 60 | + statefulSet.mixin.spec.template.spec.securityContext.withRunAsUser(0) + |
| 61 | + statefulSet.mixin.spec.updateStrategy.withType('RollingUpdate') + |
| 62 | + statefulSet.mixin.spec.template.spec.withTerminationGracePeriodSeconds(900) + |
| 63 | + // Parallelly scale up/down compactor instances instead of starting them |
| 64 | + // one by one. This does NOT affect rolling updates: they will continue to be |
| 65 | + // rolled out one by one (the next pod will be rolled out once the previous is |
| 66 | + // ready). |
| 67 | + statefulSet.mixin.spec.withPodManagementPolicy('Parallel') + |
| 68 | + $.util.configVolumeMount($._config.overrides_configmap, '/etc/cortex'), |
| 69 | + |
| 70 | + compactor_statefulset: |
| 71 | + $.newCompactorStatefulSet('compactor', $.compactor_container), |
| 72 | +} |
0 commit comments