Skip to content

Commit

Permalink
Redo config handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tjquinno committed Nov 4, 2024
1 parent 0c7acee commit 6ba516f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 30 deletions.
4 changes: 4 additions & 0 deletions health/health-checks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-mp</artifactId>
</dependency>
<dependency>
<!-- only needed for compilation, not required in runtime -->
<groupId>jakarta.enterprise</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

import io.helidon.config.Config;
import io.helidon.config.DeprecatedConfig;
import io.helidon.config.mp.MpConfig;
import io.helidon.health.HealthCheckException;
import io.helidon.health.common.BuiltInHealthCheck;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.inject.Inject;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
Expand Down Expand Up @@ -132,22 +132,10 @@ public class DiskSpaceHealthCheck implements HealthCheck {
}

@Inject
DiskSpaceHealthCheck() {
Config diskSpaceConfig = DeprecatedConfig.get(config(),
HealthChecks.CONFIG_KEY_BUILT_IN_HEALTH_CHECKS_PREFIX,
HealthChecks.DEPRECATED_CONFIG_KEY_BUILT_IN_HEALTH_CHECKS_PREFIX)
.get(CONFIG_KEY_DISKSPACE_PREFIX);
Path path = diskSpaceConfig.get(CONFIG_KEY_PATH_SUFFIX)
.as(Path.class)
.orElse(Paths.get("."));
thresholdPercent = diskSpaceConfig.get(CONFIG_KEY_THRESHOLD_PERCENT_SUFFIX)
.asDouble()
.orElse(99.999d);
try {
this.fileStore = Files.getFileStore(path);
} catch (IOException e) {
throw new HealthCheckException("Failed to obtain file store for path " + path, e);
}
DiskSpaceHealthCheck(org.eclipse.microprofile.config.Config mpConfig) {
this(builder().config(DeprecatedConfig.get(MpConfig.toHelidonConfig(mpConfig),
HealthChecks.CONFIG_KEY_BUILT_IN_HEALTH_CHECKS_PREFIX,
HealthChecks.DEPRECATED_CONFIG_KEY_BUILT_IN_HEALTH_CHECKS_PREFIX)));
}

private DiskSpaceHealthCheck(Builder builder) {
Expand Down Expand Up @@ -198,6 +186,31 @@ public static DiskSpaceHealthCheck create() {
return builder().build();
}

// private static FileStore path(Config config) {
// try {
// return Files.getFileStore(
// Path.of(DeprecatedConfig.get(MpConfig.toHelidonConfig(config),
// HealthChecks.CONFIG_KEY_BUILT_IN_HEALTH_CHECKS_PREFIX,
// HealthChecks.DEPRECATED_CONFIG_KEY_BUILT_IN_HEALTH_CHECKS_PREFIX)
// .get(CONFIG_KEY_DISKSPACE_PREFIX)
// .get(CONFIG_KEY_PATH_SUFFIX)
// .asString()
// .orElse(DEFAULT_PATH)));
// } catch (IOException ex) {
// throw new RuntimeException(ex);
// }
// }
//
// private static double thresholdPercent(Config config) {
// return DeprecatedConfig.get(MpConfig.toHelidonConfig(config),
// HealthChecks.CONFIG_KEY_BUILT_IN_HEALTH_CHECKS_PREFIX,
// HealthChecks.DEPRECATED_CONFIG_KEY_BUILT_IN_HEALTH_CHECKS_PREFIX)
// .get(CONFIG_KEY_DISKSPACE_PREFIX)
// .get(CONFIG_KEY_THRESHOLD_PERCENT_SUFFIX)
// .asDouble()
// .orElse(DEFAULT_THRESHOLD);
// }

@Override
public HealthCheckResponse call() {
long diskFreeInBytes;
Expand Down Expand Up @@ -315,8 +328,4 @@ public Builder config(Config config) {
return this;
}
}

private static Config config() {
return CDI.current().select(Config.class).get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import java.util.Formatter;
import java.util.Locale;

import io.helidon.config.Config;
import io.helidon.config.DeprecatedConfig;
import io.helidon.config.mp.MpConfig;
import io.helidon.health.common.BuiltInHealthCheck;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.inject.Inject;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Liveness;
Expand Down Expand Up @@ -85,8 +85,9 @@ public class HeapMemoryHealthCheck implements HealthCheck {
// this will be ignored if not within CDI
@Inject
HeapMemoryHealthCheck(
Config config,
Runtime runtime) {
this(runtime, DeprecatedConfig.get(config(),
this(runtime, DeprecatedConfig.get(MpConfig.toHelidonConfig(config),
HealthChecks.CONFIG_KEY_BUILT_IN_HEALTH_CHECKS_PREFIX,
HealthChecks.DEPRECATED_CONFIG_KEY_BUILT_IN_HEALTH_CHECKS_PREFIX)
.get(CONFIG_KEY_HEAP_PREFIX)
Expand All @@ -100,10 +101,6 @@ public class HeapMemoryHealthCheck implements HealthCheck {
this.thresholdPercent = thresholdPercent;
}

private static Config config() {
return CDI.current().select(Config.class).get();
}

private HeapMemoryHealthCheck(Builder builder) {
this.thresholdPercent = builder.threshold;
this.rt = Runtime.getRuntime();
Expand Down Expand Up @@ -199,7 +196,7 @@ public Builder thresholdPercent(double threshold) {
* @param config {@code Config} node for heap memory
* @return updated builder instance
*/
public Builder config(Config config) {
public Builder config(io.helidon.config.Config config) {
config.get(CONFIG_KEY_THRESHOLD_PERCENT_SUFFIX)
.asDouble()
.ifPresent(this::thresholdPercent);
Expand Down
3 changes: 2 additions & 1 deletion health/health-checks/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021 Oracle and/or its affiliates.
* Copyright (c) 2018, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,7 @@

requires io.helidon.common;
requires io.helidon.config;
requires io.helidon.config.mp;
requires io.helidon.health;
requires io.helidon.health.common;
requires static microprofile.config.api;
Expand Down

0 comments on commit 6ba516f

Please sign in to comment.