From 2f3b6aabf2839143b765dd9adc64d08c3eac9094 Mon Sep 17 00:00:00 2001 From: Vladyslav Budichenko Date: Fri, 6 Sep 2024 15:58:16 -0400 Subject: [PATCH] feat: add env to disable metrics operation when it is disabled --- config/config.go | 4 ++++ main.go | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 3adcff8..46ec3c2 100644 --- a/config/config.go +++ b/config/config.go @@ -48,6 +48,7 @@ type Config struct { MetricPruningRoutineInterval time.Duration MetricPruningRoutineDelayFirstRun time.Duration MetricPruningMaxRequestMetricsHistoryDays int + MetricOperationsEnabled bool CacheEnabled bool RedisEndpointURL string RedisPassword string @@ -101,6 +102,8 @@ const ( DEFAULT_METRIC_PRUNING_ENABLED = true METRIC_PRUNING_ROUTINE_INTERVAL_SECONDS_ENVIRONMENT_KEY = "METRIC_PRUNING_ROUTINE_INTERVAL_SECONDS" // 60 seconds * 60 minutes * 24 hours = 1 day + METRIC_OPERATIONS_ENABLED_ENVIRONMENT_KEY = "METRIC_OPERATIONS_ENABLED" + DEFAULT_METRIC_OPERATIONS_ENABLED = true DEFAULT_METRIC_PRUNING_ROUTINE_INTERVAL_SECONDS = 86400 METRIC_PRUNING_ROUTINE_DELAY_FIRST_RUN_SECONDS_ENVIRONMENT_KEY = "METRIC_PRUNING_ROUTINE_DELAY_FIRST_RUN_SECONDS" DEFAULT_METRIC_PRUNING_ROUTINE_DELAY_FIRST_RUN_SECONDS = 10 @@ -380,6 +383,7 @@ func ReadConfig() Config { MetricPruningRoutineInterval: time.Duration(time.Duration(EnvOrDefaultInt(METRIC_PRUNING_ROUTINE_INTERVAL_SECONDS_ENVIRONMENT_KEY, DEFAULT_METRIC_PRUNING_ROUTINE_INTERVAL_SECONDS)) * time.Second), MetricPruningRoutineDelayFirstRun: time.Duration(time.Duration(EnvOrDefaultInt(METRIC_PRUNING_ROUTINE_DELAY_FIRST_RUN_SECONDS_ENVIRONMENT_KEY, DEFAULT_METRIC_PRUNING_ROUTINE_DELAY_FIRST_RUN_SECONDS)) * time.Second), MetricPruningMaxRequestMetricsHistoryDays: EnvOrDefaultInt(METRIC_PRUNING_MAX_REQUEST_METRICS_HISTORY_DAYS_ENVIRONMENT_KEY, DEFAULT_METRIC_PRUNING_MAX_REQUEST_METRICS_HISTORY_DAYS), + MetricOperationsEnabled: EnvOrDefaultBool(METRIC_OPERATIONS_ENABLED_ENVIRONMENT_KEY, DEFAULT_METRIC_OPERATIONS_ENABLED), CacheEnabled: EnvOrDefaultBool(CACHE_ENABLED_ENVIRONMENT_KEY, false), RedisEndpointURL: os.Getenv(REDIS_ENDPOINT_URL_ENVIRONMENT_KEY), RedisPassword: os.Getenv(REDIS_PASSWORD_ENVIRONMENT_KEY), diff --git a/main.go b/main.go index 62733b2..3b16bba 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,12 @@ func init() { } func startMetricPartitioningRoutine(serviceConfig config.Config, service service.ProxyService, serviceLogger logging.ServiceLogger) <-chan error { + if !serviceConfig.MetricOperationsEnabled { + serviceLogger.Info().Msg("skipping starting metric partitioning routine since it is disabled via config") + + return nil + } + metricPartitioningRoutineConfig := routines.MetricPartitioningRoutineConfig{ Interval: serviceConfig.MetricPartitioningRoutineInterval, DelayFirstRun: serviceConfig.MetricPartitioningRoutineDelayFirstRun, @@ -67,6 +73,12 @@ func startMetricPartitioningRoutine(serviceConfig config.Config, service service } func startMetricCompactionRoutine(serviceConfig config.Config, service service.ProxyService, serviceLogger logging.ServiceLogger) <-chan error { + if !serviceConfig.MetricOperationsEnabled { + serviceLogger.Info().Msg("skipping starting metric compaction routine since it is disabled via config") + + return nil + } + metricCompactionRoutineConfig := routines.MetricCompactionRoutineConfig{ Interval: serviceConfig.MetricCompactionRoutineInterval, Database: service.Database, @@ -95,9 +107,10 @@ func startMetricCompactionRoutine(serviceConfig config.Config, service service.P } func startMetricPruningRoutine(serviceConfig config.Config, service service.ProxyService, serviceLogger logging.ServiceLogger) <-chan error { - if !serviceConfig.MetricPruningEnabled { + if !serviceConfig.MetricPruningEnabled || !serviceConfig.MetricOperationsEnabled { serviceLogger.Info().Msg("skipping starting metric pruning routine since it is disabled via config") - return make(<-chan error) + + return nil } metricPruningRoutineConfig := routines.MetricPruningRoutineConfig{