Skip to content

Conversation

@devendra-lohar
Copy link
Contributor

This PR solves the bug where CognitePusher fails to create timeseries for Prometheus default GC/python_info metrics registered after startup, causing “Time series not found” during shutdown push.

The changes now uses TimeSeriesUploadQueue to register metrics timeseries to upload queue with custom missing factory which creates the timeseries when needed i.e on shutdown or when push is called explicitly. This ensures any metrics registered after CognitePusher initialization are also tracked and missing timeseries are created for them too.

The PR also adds relevant integration tests to support multiple scenarios.

https://cognitedata.atlassian.net/jira/software/c/projects/DOG/boards/686?selectedIssue=DOG-6528

@devendra-lohar devendra-lohar requested a review from a team as a code owner December 4, 2025 05:14
@gemini-code-assist
Copy link

Summary of Changes

Hello @devendra-lohar, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness of the CognitePusher by addressing a critical issue where it failed to handle Prometheus metrics registered after its initial setup. By integrating the TimeSeriesUploadQueue and implementing a dynamic time series creation factory, the system can now seamlessly accommodate metrics that appear at any point during its lifecycle, preventing data loss and improving overall reliability. The changes are backed by new integration tests to ensure correct functionality across various scenarios.

Highlights

  • Bug Fix: Resolves a bug in CognitePusher where time series for Prometheus metrics registered after startup (e.g., GC/python_info metrics) were not created, leading to 'Time series not found' errors during shutdown pushes.
  • Dynamic Time Series Creation: The CognitePusher now utilizes the TimeSeriesUploadQueue with a custom factory function (_create_missing_timeseries_factory) to dynamically create time series when datapoints are added to the upload queue. This ensures that any metrics registered after CognitePusher's initialization are properly tracked and their corresponding time series are created on demand.
  • Refactored Initialization and Push Logic: The initialization logic (_init_cdf) no longer pre-creates time series, focusing only on assets and datasets. The _push_to_server method now interacts with the TimeSeriesUploadQueue for adding and uploading datapoints, simplifying the push mechanism.
  • New Integration Tests: Comprehensive integration tests have been added to validate the new behavior, covering scenarios such as early and late-registered metrics, proper shutdown uploads, and multiple push cycles with dynamically appearing metrics.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a bug where metrics registered after CognitePusher initialization were not being handled, leading to errors on shutdown. The change to use TimeSeriesUploadQueue with a factory for creating missing timeseries is a robust solution. The new integration tests are comprehensive and cover various scenarios, including late registration and shutdown pushes. My review focuses on improving the robustness of the new integration tests to prevent potential flakiness.

@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.98%. Comparing base (0da864e) to head (84071e0).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
cognite/extractorutils/metrics.py 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #495      +/-   ##
==========================================
+ Coverage   80.89%   80.98%   +0.09%     
==========================================
  Files          43       43              
  Lines        4197     4203       +6     
==========================================
+ Hits         3395     3404       +9     
+ Misses        802      799       -3     
Files with missing lines Coverage Δ
cognite/extractorutils/metrics.py 94.48% <95.45%> (+0.95%) ⬆️

... 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.

nithinb
nithinb previously approved these changes Dec 4, 2025
Copy link
Contributor

@nithinb nithinb left a comment

Choose a reason for hiding this comment

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

The changes LGTM

@devendra-lohar devendra-lohar added the waiting-for-risk-review Waiting for a member of the risk review team to take an action label Dec 4, 2025
@polomani
Copy link

polomani commented Dec 5, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses a bug where metrics registered after CognitePusher initialization were not being handled, by refactoring the push logic to use TimeSeriesUploadQueue with a factory for on-demand timeseries creation. The changes are well-supported by new integration tests. My review focuses on improving the robustness of these new tests and strengthening the unit test coverage for the new error handling path.

@polomani polomani added the risk-review-ongoing Risk review is in progress label Dec 5, 2025
@polomani polomani self-assigned this Dec 5, 2025
@polomani
Copy link

polomani commented Dec 5, 2025

I think this comment from gemini (about flaky tests) makes sense: #495 (comment)

the other (about unit tests) is up to you

@polomani polomani 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 Dec 5, 2025
@devendra-lohar devendra-lohar added waiting-for-risk-review Waiting for a member of the risk review team to take an action and removed waiting-for-team Waiting for the submitter or reviewer of the PR to take an action labels Dec 5, 2025
@polomani
Copy link

polomani commented Dec 5, 2025

🦄

@polomani polomani 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 Dec 5, 2025
@devendra-lohar devendra-lohar merged commit 4311e2d into master Dec 5, 2025
6 checks passed
@devendra-lohar devendra-lohar deleted the dev/cognitepusher-metrics-fix branch December 5, 2025 14:49
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.

5 participants