Skip to content

Commit bdf8164

Browse files
Merge pull request #111 from iExecBlockchainComputing/feature/expose-version-through-prometheus-endpoint
Feature/expose version through prometheus endpoint
2 parents 4b0be82 + 37cb6bb commit bdf8164

File tree

8 files changed

+220
-92
lines changed

8 files changed

+220
-92
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
## [[NEXT]](https://github.com/iExecBlockchainComputing/iexec-result-proxy/releases/tag/vNEXT) 2023
66

7+
### New Features
8+
9+
- Expose version through prometheus endpoint and through VersionController. (#111)
10+
711
### Bug Fixes
812

913
- Remove duplicated call to blockchain in `ProxyService`. (#110)
@@ -17,6 +21,7 @@ All notable changes to this project will be documented in this file.
1721
- Upgrade to `eclipse-temurin:11.0.21_9-jre-focal`. (#109)
1822
- Upgrade to Spring Boot 2.7.17. (#108)
1923
- Upgrade to Spring Dependency Management Plugin 1.1.4. (#108)
24+
- Upgrade to Spring Doc OpenAPI 1.7.0. (#111)
2025
- Upgrade to `jenkins-library` 2.7.4. (#107)
2126

2227
## [[8.2.0]](https://github.com/iExecBlockchainComputing/iexec-result-proxy/releases/tag/v8.2.0) 2023-09-28

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ dependencies {
6161
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
6262

6363
// Spring Doc
64-
implementation 'org.springdoc:springdoc-openapi-ui:1.6.3'
64+
implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'
6565

6666
// ipfs
6767
implementation 'com.github.ipfs:java-ipfs-http-client:1.4.0'
Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
1+
/*
2+
* Copyright 2023-2023 IEXEC BLOCKCHAIN TECH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.iexec.resultproxy;
217

3-
import com.iexec.resultproxy.version.VersionService;
418
import io.swagger.v3.oas.models.OpenAPI;
519
import io.swagger.v3.oas.models.info.Info;
20+
import org.springframework.boot.info.BuildProperties;
621
import org.springframework.context.annotation.Bean;
722
import org.springframework.context.annotation.Configuration;
823

924
@Configuration
1025
public class OpenApiConfig {
1126

12-
private final VersionService versionService;
27+
public static final String TITLE = "iExec Result Proxy";
1328

14-
public OpenApiConfig(VersionService versionService) {
15-
this.versionService = versionService;
29+
private final BuildProperties buildProperties;
30+
31+
public OpenApiConfig(BuildProperties buildProperties) {
32+
this.buildProperties = buildProperties;
1633
}
1734

1835
/*
@@ -22,8 +39,8 @@ public OpenApiConfig(VersionService versionService) {
2239
public OpenAPI api() {
2340
return new OpenAPI().info(
2441
new Info()
25-
.title("iExec Result Proxy")
26-
.version(versionService.getVersion())
42+
.title(TITLE)
43+
.version(buildProperties.getVersion())
2744
);
2845
}
29-
}
46+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2023-2023 IEXEC BLOCKCHAIN TECH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.iexec.resultproxy.version;
18+
19+
import io.micrometer.core.instrument.Gauge;
20+
import io.micrometer.core.instrument.Metrics;
21+
import org.springframework.boot.info.BuildProperties;
22+
import org.springframework.http.ResponseEntity;
23+
import org.springframework.web.bind.annotation.GetMapping;
24+
import org.springframework.web.bind.annotation.RestController;
25+
26+
import javax.annotation.PostConstruct;
27+
28+
@RestController
29+
public class VersionController {
30+
31+
public static final String METRIC_INFO_GAUGE_NAME = "iexec.version.info";
32+
public static final String METRIC_INFO_GAUGE_DESC = "A metric to expose version and application name.";
33+
public static final String METRIC_INFO_LABEL_APP_NAME = "iexecAppName";
34+
public static final String METRIC_INFO_LABEL_APP_VERSION = "iexecAppVersion";
35+
36+
private final BuildProperties buildProperties;
37+
38+
public VersionController(BuildProperties buildProperties) {
39+
this.buildProperties = buildProperties;
40+
}
41+
42+
@PostConstruct
43+
void initializeGaugeVersion() {
44+
Gauge.builder(METRIC_INFO_GAUGE_NAME, 1.0, n -> n)
45+
.description(METRIC_INFO_GAUGE_DESC)
46+
.tags(METRIC_INFO_LABEL_APP_VERSION, buildProperties.getVersion(),
47+
METRIC_INFO_LABEL_APP_NAME, buildProperties.getName())
48+
.register(Metrics.globalRegistry);
49+
}
50+
51+
@GetMapping("/version")
52+
public ResponseEntity<String> getVersion() {
53+
return ResponseEntity.ok(buildProperties.getVersion());
54+
}
55+
}

src/main/java/com/iexec/resultproxy/version/VersionService.java

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2023-2023 IEXEC BLOCKCHAIN TECH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.iexec.resultproxy;
17+
18+
import io.swagger.v3.oas.models.OpenAPI;
19+
import io.swagger.v3.oas.models.info.Info;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.extension.ExtendWith;
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration;
25+
import org.springframework.boot.info.BuildProperties;
26+
import org.springframework.context.annotation.Import;
27+
import org.springframework.test.context.junit.jupiter.SpringExtension;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
@ExtendWith(SpringExtension.class)
32+
@Import(ProjectInfoAutoConfiguration.class)
33+
class OpenApiConfigTests {
34+
35+
@Autowired
36+
private BuildProperties buildProperties;
37+
38+
private OpenApiConfig openApiConfig;
39+
40+
@BeforeEach
41+
void setUp() {
42+
openApiConfig = new OpenApiConfig(buildProperties);
43+
}
44+
45+
@Test
46+
void shouldReturnOpenAPIObjectWithCorrectInfo() {
47+
OpenAPI api = openApiConfig.api();
48+
assertThat(api).isNotNull().
49+
extracting(OpenAPI::getInfo).isNotNull().
50+
extracting(
51+
Info::getVersion,
52+
Info::getTitle
53+
)
54+
.containsExactly(buildProperties.getVersion(), OpenApiConfig.TITLE);
55+
}
56+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2023-2023 IEXEC BLOCKCHAIN TECH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.iexec.resultproxy.version;
17+
18+
import io.micrometer.core.instrument.Gauge;
19+
import io.micrometer.core.instrument.Metrics;
20+
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
21+
import org.junit.jupiter.api.AfterEach;
22+
import org.junit.jupiter.api.BeforeAll;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.extension.ExtendWith;
26+
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration;
28+
import org.springframework.boot.info.BuildProperties;
29+
import org.springframework.context.annotation.Import;
30+
import org.springframework.http.ResponseEntity;
31+
import org.springframework.test.context.junit.jupiter.SpringExtension;
32+
33+
import static org.assertj.core.api.Assertions.assertThat;
34+
import static org.junit.jupiter.api.Assertions.assertEquals;
35+
36+
@ExtendWith(SpringExtension.class)
37+
@Import(ProjectInfoAutoConfiguration.class)
38+
class VersionControllerTests {
39+
40+
private VersionController versionController;
41+
42+
@Autowired
43+
private BuildProperties buildProperties;
44+
45+
@BeforeAll
46+
static void initRegistry() {
47+
Metrics.globalRegistry.add(new SimpleMeterRegistry());
48+
}
49+
50+
@BeforeEach
51+
void init() {
52+
versionController = new VersionController(buildProperties);
53+
versionController.initializeGaugeVersion();
54+
}
55+
56+
@AfterEach
57+
void afterEach() {
58+
Metrics.globalRegistry.clear();
59+
}
60+
61+
@Test
62+
void testVersionController() {
63+
assertEquals(ResponseEntity.ok(buildProperties.getVersion()), versionController.getVersion());
64+
}
65+
66+
@Test
67+
void shouldReturnInfoGauge() {
68+
final Gauge info = Metrics.globalRegistry.find(VersionController.METRIC_INFO_GAUGE_NAME).gauge();
69+
assertThat(info)
70+
.isNotNull()
71+
.extracting(Gauge::getId)
72+
.isNotNull()
73+
.extracting(
74+
id -> id.getTag(VersionController.METRIC_INFO_LABEL_APP_NAME),
75+
id -> id.getTag(VersionController.METRIC_INFO_LABEL_APP_VERSION)
76+
)
77+
.containsExactly(buildProperties.getName(), buildProperties.getVersion());
78+
}
79+
}

src/test/java/com/iexec/resultproxy/version/VersionServiceTests.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)