Skip to content

Add Metrics and pusher to unstable#475

Merged
Hmnt39 merged 19 commits intomasterfrom
DOG-5996-Implement-metrics
Sep 23, 2025
Merged

Add Metrics and pusher to unstable#475
Hmnt39 merged 19 commits intomasterfrom
DOG-5996-Implement-metrics

Conversation

@Hmnt39
Copy link
Copy Markdown
Contributor

@Hmnt39 Hmnt39 commented Sep 5, 2025

This PR introduces the metrics and pusher manager for Cognite extractors, enabling flexible metrics collection, singleton enforcement, and reliable pushing to Prometheus and Cognite Data Fusion (CDF).

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 5, 2025

Codecov Report

❌ Patch coverage is 87.80488% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.67%. Comparing base (fc5aedb) to head (ac2a117).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...te/extractorutils/unstable/configuration/models.py 90.76% 6 Missing ⚠️
cognite/extractorutils/unstable/core/runtime.py 40.00% 3 Missing ⚠️
cognite/extractorutils/unstable/core/base.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #475      +/-   ##
==========================================
+ Coverage   80.47%   80.67%   +0.19%     
==========================================
  Files          43       43              
  Lines        4046     4124      +78     
==========================================
+ Hits         3256     3327      +71     
- Misses        790      797       +7     
Files with missing lines Coverage Δ
cognite/extractorutils/unstable/core/base.py 79.06% <91.66%> (+0.91%) ⬆️
cognite/extractorutils/unstable/core/runtime.py 69.49% <40.00%> (-0.34%) ⬇️
...te/extractorutils/unstable/configuration/models.py 85.76% <90.76%> (+1.55%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Hmnt39 Hmnt39 marked this pull request as ready for review September 8, 2025 08:09
@Hmnt39 Hmnt39 requested a review from a team as a code owner September 8, 2025 08:09
@einarmo
Copy link
Copy Markdown
Contributor

einarmo commented Sep 9, 2025

Is the metrics module just copied? Do you need to change it? Any reason why you can't just reuse the one already in the stable part of the utils?

@Hmnt39
Copy link
Copy Markdown
Contributor Author

Hmnt39 commented Sep 9, 2025

Is the metrics module just copied? Do you need to change it? Any reason why you can't just reuse the one already in the stable part of the utils?

Aren't we moving everything to unstable ? Should I use the stable configtools and metrics in unstable?

@einarmo
Copy link
Copy Markdown
Contributor

einarmo commented Sep 9, 2025

Is the metrics module just copied? Do you need to change it? Any reason why you can't just reuse the one already in the stable part of the utils?

Aren't we moving everything to unstable ? Should I use the stable configtools and metrics in unstable?

So long as you haven't changed them. You can definitely use metrics. Not configtools though, because those have changed.

Try to think about why we're doing this unstable thing.

host: str
job_name: str
username: str | None
password: str | None
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.

Won't the lack of defaults here means that these config objects will need an explicit username: null in config?

Could you write a test that actually loads these types from YAML?

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.

Nice catch, as best practices suggest we should have default value defined here. Fix the default value and also added the test case to if a config variable is missing then it doesn't break.

@Hmnt39 Hmnt39 requested a review from einarmo September 16, 2025 06:08
],
"cognite": None,
"server": None,
}
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.

Are you dumping a struct as YAML then reading it back? This doesn't really verify that None values aren't still required. Instead, you should write out the yaml and just load it directly from a string in the test.

clear_after: null
username: null
cognite: null
server: null
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.

The thing I wanted to verify was that this works without explicitly setting x: null, so leave those out. We generally don't encourage explicitly setting things to null in yaml configs.

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.

Here, password is not set explicitly to null, so this is working (I want to verify if explicitly setting to null is also working i.e. username).

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.

Then add another test where you don't set them to null explicitly. Setting them to null is the exception, not the rule, and I would prefer if tests verified the intended usage as well as any corner cases.

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.

The thing I wanted to verify was that this works without explicitly setting x: null, so leave those out. We generally don't encourage explicitly setting things to null in yaml configs.

Made the changes, I got your point why we do require to set the defaults and not passing null explicitly.

einarmo
einarmo previously approved these changes Sep 17, 2025
@Hmnt39 Hmnt39 added the waiting-for-risk-review Waiting for a member of the risk review team to take an action label Sep 17, 2025
@arnels arnels self-assigned this Sep 19, 2025
@arnels arnels added the risk-review-ongoing Risk review is in progress label Sep 19, 2025
if push_gateway.clear_after is not None:
self.clear_on_stop[prometheus_pusher] = push_gateway.clear_after.seconds

if self.metrics_config.cognite:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please add testing for this option too

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.

Added the tests

@arnels arnels added waiting-for-team Waiting for the submitter or reviewer of the PR to take an action and removed waiting-for-risk-review Waiting for a member of the risk review team to take an action labels Sep 19, 2025
Copy link
Copy Markdown

@arnels arnels left a comment

Choose a reason for hiding this comment

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

risk review ok

@Hmnt39 Hmnt39 merged commit 67ffc88 into master Sep 23, 2025
6 checks passed
@Hmnt39 Hmnt39 deleted the DOG-5996-Implement-metrics branch September 23, 2025 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk-review-ongoing Risk review is in progress waiting-for-team Waiting for the submitter or reviewer of the PR to take an action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants