Skip to content

Commit

Permalink
Fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
onukristo committed Oct 30, 2024
1 parent ff2e225 commit 037e5df
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 85 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ topics configurations. Could refactor the properties to more hierarhical structu

23. Start using Avro or other binary messages for triggering queue. This Json crap is expensive?

24. Add local extremums for most gauges.

25. Check automatically if the concurrency policy returned is the same instance.
Unfortunately, it is quite common for services to create a new instance everytime we ask it, for let's say SimpleConcurrencyPolicy, and with
doing that, losing any concurrency control.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.transferwise.tasks.core.autoconfigure;

import com.transferwise.tasks.helpers.CoreMetricsTemplate;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;

@Slf4j
public class TwTasksEnvironmentPostProcessor implements EnvironmentPostProcessor {

private static final String PROPERTY_SOURCE_KEY = TwTasksEnvironmentPostProcessor.class.getName();
static final String TW_OBS_BASE_EXTREMUM_CONFIG_PATH = "transferwise.observability.base.metrics.local-extremum-gauge-names.tw-tasks";

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
PropertySource<?> propertySource = environment.getPropertySources().get(PROPERTY_SOURCE_KEY);
if (propertySource == null) {
final HashMap<String, Object> map = new HashMap<>();

// Calculate last minute min/max using tw-observability-base local extremums.
Set<String> gaugeNames = new HashSet<>();
gaugeNames.add(CoreMetricsTemplate.GAUGE_METRIC_PROCESSING_ONGOING_TASKS_GRABBINGS_COUNT);
gaugeNames.add(CoreMetricsTemplate.GAUGE_PROCESSING_RUNNING_TASKS_COUNT);
gaugeNames.add(CoreMetricsTemplate.GAUGE_PROCESSING_IN_PROGRESS_TASKS_GRABBING_COUNT);
gaugeNames.add(CoreMetricsTemplate.GAUGE_TASKS_ONGOING_PROCESSINGS_COUNT);

map.put(TW_OBS_BASE_EXTREMUM_CONFIG_PATH, gaugeNames);

MapPropertySource mapPropertySource = new MapPropertySource(PROPERTY_SOURCE_KEY, map);
environment.getPropertySources().addLast(mapPropertySource);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.transferwise.tasks.core.autoconfigure.TwTasksCoreAutoConfiguration
org.springframework.context.ApplicationListener=com.transferwise.tasks.TwTasksApplicationListener
org.springframework.boot.env.EnvironmentPostProcessor=com.transferwise.tasks.core.autoconfigure.TwTasksEnvironmentPostProcessor
Loading

0 comments on commit 037e5df

Please sign in to comment.