Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose version through prometheus endpoint #637

Merged

Conversation

thewhitewizard
Copy link
Contributor

No description provided.

@thewhitewizard thewhitewizard marked this pull request as ready for review December 1, 2023 09:56
ObservabilityConfiguration(@Autowired BuildProperties buildProperties) {

Gauge.builder(METRIC_INFO_GAUGE_NAME, 1.0, n -> n)
.strongReference(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this strong reference required?

Comment on lines 42 to 50
@AfterEach
void afterEach() {
Metrics.globalRegistry.clear();
}

@BeforeEach
void init() {
MockitoAnnotations.openMocks(this);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reorder these methods? I would use the following order:

@BeforeAll
@BeforeEach
@AfterEach
@AfterAll

Comment on lines 62 to 65
Assertions.assertThat(info).isNotNull();
Assertions.assertThat(info.getId()).isNotNull();
Assertions.assertThat(info.getId().getTag(ObservabilityConfiguration.METRIC_INFO_LABEL_APP_NAME)).isEqualTo(name);
Assertions.assertThat(info.getId().getTag(ObservabilityConfiguration.METRIC_INFO_LABEL_APP_VERSION)).isEqualTo(version);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use an assertAll?

Copy link
Contributor Author

@thewhitewizard thewhitewizard Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as one of the great president said, yes we can

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to mock things here ?
Why not simply assert we have BuildProperties with correct values ?

Copy link
Contributor Author

@thewhitewizard thewhitewizard Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I succeeded in working without the mock. I had to add 2 annotations to the class.

@ExtendWith(SpringExtension.class)
@Import(ProjectInfoAutoConfiguration.class)
class ObservabilityConfigurationTest

Copy link
Contributor Author

@thewhitewizard thewhitewizard Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcornaton
to deal with nullpointer, i propose

        assertThat(info).isNotNull();
        assertAll(
                () -> assertThat(observabilityConfiguration).isNotNull(),
                () -> assertThat(info.getId()).isNotNull(),
                () -> assertThat(info.getId().getTag(ObservabilityConfiguration.METRIC_INFO_LABEL_APP_NAME)).isEqualTo(buildProperties.getName()),
                () -> assertThat(info.getId().getTag(ObservabilityConfiguration.METRIC_INFO_LABEL_APP_VERSION)).isEqualTo(buildProperties.getVersion())
        );

import org.springframework.context.annotation.Configuration;

@Configuration
public class ObservabilityConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global question here.
Would it be meaningful to merge ObservabilityConfiguration + VersionController + VersionService in a single class exposing both metric registry and rest endpoint ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, I can:

Add a getAppName in VersionService and add a postConstruct in the Controller to create the metric (by calling VersionService).

OR

Keep only the controller (delete the service which is a bit too much here)

But I liked the idea of managing this metric independently in a Config class because it can be replicated in all projects (we don't necessarily have the controller everywhere).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea for me is to have the controller everywhere.
It will be more work but every app should have the version controller and the version metric endpoint in my opinion.

Copy link
Contributor

@jbern0rd jbern0rd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to try to update springdoc-openapi dependency to the highest possible version (1.7.0 as we still use Spring Boot 2.x https://springdoc.org/) ?

Copy link

sonarqubecloud bot commented Dec 4, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@thewhitewizard thewhitewizard merged commit ec547b4 into develop Dec 4, 2023
@thewhitewizard thewhitewizard deleted the feature/expose-version-through-prometheus-endpoint branch December 4, 2023 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants