Repository navigation
[system] Fix telemetry collection in cozystack-operator - #1918
Conversation
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]>
📝 WalkthroughWalkthroughThe 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
Summary of ChangesHello 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
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()
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
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.