Skip to content

Commit

Permalink
fix: avoid spring loading issue with vertx and k8s client
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaeyaert authored and gaetanmaisse committed Mar 13, 2023
1 parent 42792da commit 4ff1b8b
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;

Expand Down Expand Up @@ -210,21 +211,22 @@ private void loadMetricLabels() {
}

private Map<String, Set<Label>> readConfiguredLabelsByCategory(final String type) {
return Arrays
.stream(MetricsDomain.values())
.map(MetricsDomain::toCategory)
.flatMap(category ->
EnvironmentUtils
.getPropertiesStartingWith((ConfigurableEnvironment) environment, "services.metrics." + type + "." + category)
.entrySet()
.stream()
)
.collect(
Collectors.groupingBy(
e -> e.getKey().replaceAll("^services\\.metrics\\." + type + "\\." + "(.*)\\[\\d+]$", "$1"),
Collectors.mapping(e -> toLabel((String) e.getValue()), Collectors.<Label, Set<Label>>toCollection(HashSet::new))
)
);
final Map<String, Set<Label>> labelsByCategory = new HashMap<>();

for (MetricsDomain metricsDomain : MetricsDomain.values()) {
final String category = metricsDomain.toCategory();
final Set<Label> labels = new HashSet<>();

String value;
int counter = 0;
labelsByCategory.put(category, labels);

while ((value = environment.getProperty("services.metrics." + type + "." + category + "[" + (counter++) + "]")) != null) {
labels.add(toLabel(value));
}
}

return labelsByCategory;
}

private Label toLabel(String label) {
Expand Down

0 comments on commit 4ff1b8b

Please sign in to comment.