Skip to content

Commit

Permalink
feat: add env to disable metrics operation when it is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
boodyvo committed Sep 6, 2024
1 parent 8dcc1e1 commit 2f3b6aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Config struct {
MetricPruningRoutineInterval time.Duration
MetricPruningRoutineDelayFirstRun time.Duration
MetricPruningMaxRequestMetricsHistoryDays int
MetricOperationsEnabled bool
CacheEnabled bool
RedisEndpointURL string
RedisPassword string
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
17 changes: 15 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 2f3b6aa

Please sign in to comment.