Skip to content

[system] Fix telemetry collection in cozystack-operator - #1918

Merged
Andrei Kvapil (kvaps) merged 2 commits into
mainfrom
fix/telemetry-use-api-reader
Jan 27, 2026
Merged

Andrei Kvapil (kvaps) merged 2 commits into
mainfrom
fix/telemetry-use-api-reader

Conversation

@kvaps

@kvaps Andrei Kvapil (kvaps) commented Jan 27, 2026 •

Copy link
Copy Markdown
Member

What this PR does

Fixes telemetry collection in cozystack-operator which was failing because the manager's cache is filtered and doesn't include resources needed for telemetry (kube-system namespace, nodes, services, PVs).

Switches to using mgr.GetAPIReader() which bypasses the cache.

Release note

[system] Fix telemetry collection in cozystack-operator

Summary by CodeRabbit

Release Notes

  • Chores
    • Updated Docker image versions from 1.5.0 to 1.6.1 for platform migrations and testing environments.
    • Enhanced telemetry collection system with improved data access patterns.

✏️ Tip: You can customize this high-level summary in your review settings.

Andrei Kvapil (kvaps) and others added 2 commits January 27, 2026 16:44
Signed-off-by: Andrei Kvapil <[email protected]>
The cozystack-operator's manager cache is filtered to only include
specific secrets and namespaces with certain labels. This caused
telemetry collection to fail because resources like kube-system
namespace, nodes, services, and PVs were not in the cache.

Switch to using mgr.GetAPIReader() which bypasses the cache and
queries the API server directly. This is appropriate for telemetry
since it only runs every 15 minutes.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Andrei Kvapil <[email protected]>
@coderabbitai

coderabbitai Bot commented Jan 27, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The operator telemetry collector transitions from using a full client to a read-only client reader to access filtered cache resources, accompanied by CozyHR version bumps from 1.5.0 to 1.6.1 in two Docker images.

Changes

Cohort / File(s) Summary
Telemetry Client Refactoring
cmd/cozystack-operator/main.go, internal/telemetry/operator_collector.go
Changed OperatorCollector to use client.Reader instead of client.Client. Updated main.go to pass mgr.GetAPIReader() instead of mgr.GetClient() to NewOperatorCollector. All internal read operations (Get, List) now use the reader interface.
Dependency Version Updates
packages/core/platform/images/migrations/Dockerfile, packages/core/testing/images/e2e-sandbox/Dockerfile
Bumped CozyHR version from 1.5.0 to 1.6.1 in both Dockerfiles via ARG COZYHR\_VERSION.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A reader now, not a client grand,
The telemetry hops through filtered land,
With versions bumped to 1.6.1,
The API Reader's reign has begun! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main change: fixing telemetry collection in cozystack-operator by switching to API reader.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello Andrei Kvapil (@kvaps), 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 resolves a critical issue preventing the cozystack-operator from accurately collecting telemetry data. The problem stemmed from the operator's telemetry component using a cached client that inadvertently filtered out essential Kubernetes resources. By transitioning to a non-cached API reader, the operator can now access all necessary cluster information, ensuring reliable and complete telemetry reporting. Additionally, this PR includes a minor version bump for the cozyhr dependency in development and migration images.

Highlights

  • Telemetry Collection Fix: Addressed an issue where telemetry collection in cozystack-operator was failing due to the manager's cached client not providing access to necessary resources like kube-system namespace, nodes, services, and Persistent Volumes.
  • API Client Usage: Switched the OperatorCollector to use mgr.GetAPIReader() instead of mgr.GetClient() to bypass the filtered cache and ensure all required resources are accessible for telemetry.
  • Dependency Version Update: Updated the COZYHR_VERSION from 1.5.0 to 1.6.1 in two Dockerfiles (migrations and e2e-sandbox).

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 (@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 (@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. ↩

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request correctly fixes an issue with telemetry collection by using mgr.GetAPIReader() to bypass the manager's filtered cache. The changes in the Go code are consistent and well-implemented, replacing client.Client with client.Reader where appropriate to reflect that only read operations are needed. I've also noted a potential improvement in one of the Dockerfiles for better security and reproducibility. Overall, this is a good fix.

FROM alpine:3.22

RUN wget -O- https://github.com/cozystack/cozyhr/raw/refs/heads/main/hack/install.sh | sh -s -- -v 1.5.0
RUN wget -O- https://github.com/cozystack/cozyhr/raw/refs/heads/main/hack/install.sh | sh -s -- -v 1.6.1

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.

security-medium medium

For better security and build reproducibility, it's recommended to avoid executing scripts directly from a URL, especially when pointing to a mutable reference like main. This can introduce unexpected changes or security vulnerabilities. A safer pattern is to download the script, verify its integrity (e.g., using a checksum), and then execute it. Also, consider pinning the script's URL to a specific commit hash or tag instead of main.

@dosubot dosubot Bot added size/S This PR changes 10-29 lines, ignoring generated files kind/bug Categorizes issue or PR as related to a bug labels Jan 27, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/core/platform/images/migrations/Dockerfile`:
- Line 3: The Dockerfile currently pipes an external install script (the RUN
wget ... | sh -s -- -v 1.6.1 line) which violates the packages/core/**
Helm-chart vendoring guideline; replace this by vendoring the cozyhr v1.6.1 Helm
chart into the repository's charts/ directory and change the Dockerfile to
install via Helm (e.g., helm dependency update && helm upgrade --install cozyhr
./charts/cozyhr --version 1.6.1 or similar), removing any wget|sh invocation;
ensure the Dockerfile uses the vendored chart path (./charts/cozyhr) and
standard Helm commands so installation follows the umbrella vendoring pattern.
🧹 Nitpick comments (1)
internal/telemetry/operator_collector.go (1)

109-239: Add a per-collection timeout to prevent indefinite API hangs.

The collect() method makes multiple sequential API calls without timeout protection. If the API server becomes unresponsive, these calls could hang indefinitely, blocking subsequent collection cycles. Adding a per-collection timeout following controller-runtime best practices ensures the telemetry collection fails gracefully within 30 seconds rather than blocking indefinitely.

♻️ Suggested change
 func (c *OperatorCollector) collect(ctx context.Context) {
 	logger := log.FromContext(ctx).V(1)
+	ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
+	defer cancel()

Comment thread packages/core/platform/images/migrations/Dockerfile
@kvaps
Andrei Kvapil (kvaps) merged commit 9de268f into main Jan 27, 2026
10 checks passed
@kvaps
Andrei Kvapil (kvaps) deleted the fix/telemetry-use-api-reader branch January 27, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug size/S This PR changes 10-29 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant