Skip to content

Commit cda0bda

Browse files
Fix NaN value for gauge version
1 parent e4f9b6d commit cda0bda

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.
88

99
- Share code between transaction types in `IexecHubService`. (#556)
1010
- Expose Pre, App & Post-Compute durations. (#559, #560, #561, #562, #563, #565)
11-
- Expose version through prometheus endpoint and through VersionController. (#569)
11+
- Expose version through prometheus endpoint and through VersionController. (#569 #570)
1212

1313
### Quality
1414

src/main/java/com/iexec/worker/version/VersionController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public class VersionController {
3232
public static final String METRIC_INFO_GAUGE_DESC = "A metric to expose version and application name.";
3333
public static final String METRIC_INFO_LABEL_APP_NAME = "iexecAppName";
3434
public static final String METRIC_INFO_LABEL_APP_VERSION = "iexecAppVersion";
35-
35+
// Must be static final to avoid garbage collect and side effect on gauge
36+
public static final int METRIC_VALUE = 1;
3637
private final BuildProperties buildProperties;
3738

3839
public VersionController(BuildProperties buildProperties) {
@@ -41,7 +42,7 @@ public VersionController(BuildProperties buildProperties) {
4142

4243
@PostConstruct
4344
void initializeGaugeVersion() {
44-
Gauge.builder(METRIC_INFO_GAUGE_NAME, 1.0, n -> n)
45+
Gauge.builder(METRIC_INFO_GAUGE_NAME, METRIC_VALUE, n -> METRIC_VALUE)
4546
.description(METRIC_INFO_GAUGE_DESC)
4647
.tags(METRIC_INFO_LABEL_APP_VERSION, buildProperties.getVersion(),
4748
METRIC_INFO_LABEL_APP_NAME, buildProperties.getName())

src/test/java/com/iexec/worker/version/VersionControllerTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ void shouldReturnInfoGauge() {
7575
id -> id.getTag(VersionController.METRIC_INFO_LABEL_APP_VERSION)
7676
)
7777
.containsExactly(buildProperties.getName(), buildProperties.getVersion());
78+
assertThat(info.value()).isEqualTo(VersionController.METRIC_VALUE);
7879
}
7980
}
8081

0 commit comments

Comments
 (0)