Skip to content

Add metrics for prometheus observability - #661

Open
daniel-heppner-ibigroup wants to merge 7 commits into
devfrom
metrics-endpoint
Open

Add metrics for prometheus observability#661
daniel-heppner-ibigroup wants to merge 7 commits into
devfrom
metrics-endpoint

Conversation

@daniel-heppner-ibigroup

@daniel-heppner-ibigroup daniel-heppner-ibigroup commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Checklist

  • Appropriate branch selected (all PRs must first be merged to dev before they can be merged to master)
  • Any modified or new methods or classes have helpful JavaDoc and code is thoroughly commented
  • The description lists all applicable issues this PR seeks to resolve
  • The description lists any configuration setting(s) that differ from the default settings
  • All tests and CI builds passing
  • The description lists all relevant PRs included in this release (remove this if not merging to master)
  • e2e tests are all passing (remove this if not merging to master)

Description

I'm adding a /metrics endpoint and tracking a bunch of metrics with micrometer gauges and counters. We also get a bunch of JVM stats built in from micrometer.

note it's unauthenticated, so users will need to make sure to filter that url in their reverse proxy if they feel like the data contained is sensitive.

example of metrics here: https://gist.github.com/daniel-heppner-ibigroup/3efda5ac5238337727af09009d84b9a1

@daniel-heppner-ibigroup

Copy link
Copy Markdown
Contributor Author

do we have a formatter?

@miles-grant-ibigroup miles-grant-ibigroup left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Haven't had a chance to test it yet, but looks solid

}

public static void register() {
get("/metrics", MetricsController::getMetrics);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there no way to throw in a key param here? And that key could be set in the config

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah we could do that. I don't think it's really conventional but it's a reasonable approach.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure which would be easier so I added both query param and header based API key support!!

@miles-grant-ibigroup miles-grant-ibigroup left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Working great! I adore it

@binh-dam-ibigroup binh-dam-ibigroup left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please move secrets from server.yml to env.yml.

* A method to initialize all scheduled tasks upon server startup.
*/
public static void initialize() {
if(DataManager.isModuleEnabled("metrics")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Insert space after if.

Comment on lines +82 to +85
* Schedules a task to refresh the metrics inventory on a regular interval
* @param period refresh interval
* @param unit unit for the refresh interval
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fix indent

enabled: true
# If set, this API key must be passed to access the /metrics endpoint.
# Pass via header "X-API-Key" or query parameter "api_key".
# api_key: your-secret-api-key

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Secrets should be stored in env.yml instead of server.yml.

import static spark.Spark.get;

public class MetricsController {
private static final String METRICS_API_KEY_CONFIG = "modules.metrics.api_key";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Secrets should be from env.yml. All properties are stored flat in env.yml (no hierarchy or categories).

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.

4 participants