-
Notifications
You must be signed in to change notification settings - Fork 136
refactor(telemetry): split telemetry between operator and controller #1869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Split telemetry collection between cozystack-operator and cozystack-controller: cozystack-operator now collects cluster-level metrics: - cozy_cluster_info (cozystack_version, kubernetes_version) - cozy_nodes_count (os, kernel) - cozy_cluster_capacity (cpu, memory, nvidia.com/* resources) - cozy_loadbalancers_count - cozy_pvs_count (driver, size) - cozy_package_info (name, variant) cozystack-controller now collects application-level metrics: - cozy_application_count (kind) - counts HelmReleases per ApplicationDefinition Other changes: - Add pkg/version for build-time version injection via ldflags - Remove --cozystack-version flag (version now embedded at build time) - Remove bundle/oidc configuration from telemetry (replaced by package_info) - Remove cozy_workloads_count metric (replaced by cozy_application_count) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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 @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 significantly refactors the telemetry system within Cozystack to provide a more granular and accurate view of both cluster infrastructure and application deployments. By separating telemetry responsibilities between the operator and controller, the system can now collect more relevant data for each component. Additionally, the change streamlines version reporting through build-time injection and updates several metric definitions to better reflect the system's state. 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-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.
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 refactors the telemetry collection by splitting responsibilities between the operator and the controller, which improves modularity. The change to inject the version at build time using ldflags is a good improvement over runtime flags. My review includes a high-severity suggestion to address significant code duplication between the new telemetry collectors, which would improve long-term maintainability. I've also included medium-severity comments to encourage the use of structured logging for better observability. Overall, this is a great set of changes that improves the telemetry architecture.
| func (c *OperatorCollector) Start(ctx context.Context) error { | ||
| if c.config.Disabled { | ||
| return nil | ||
| } | ||
|
|
||
| c.ticker = time.NewTicker(c.config.Interval) | ||
| c.stopCh = make(chan struct{}) | ||
|
|
||
| // Initial collection | ||
| c.collect(ctx) | ||
|
|
||
| for { | ||
| select { | ||
| case <-ctx.Done(): | ||
| c.ticker.Stop() | ||
| close(c.stopCh) | ||
| return nil | ||
| case <-c.ticker.C: | ||
| c.collect(ctx) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is significant code duplication between OperatorCollector in this file and Collector in internal/telemetry/collector.go. The Start, NeedLeaderElection, and sendMetrics methods are identical, and the struct definitions are very similar. This makes the code harder to maintain.
I recommend refactoring to use a common baseCollector that can be embedded by both OperatorCollector and Collector to hold the shared logic. This would centralize the common functionality, making it easier to manage.
| // Get cluster ID from kube-system namespace | ||
| var kubeSystemNS corev1.Namespace | ||
| if err := c.client.Get(ctx, types.NamespacedName{Name: "kube-system"}, &kubeSystemNS); err != nil { | ||
| logger.Info(fmt.Sprintf("Failed to get kube-system namespace: %v", err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throughout this file and internal/telemetry/collector.go, log messages are constructed using fmt.Sprintf. It is a best practice to use structured logging with key-value pairs for variable data. This makes logs more machine-readable and easier to query.
For example, this line could be improved.
| logger.Info(fmt.Sprintf("Failed to get kube-system namespace: %v", err)) | |
| logger.Info("Failed to get kube-system namespace", "error", err) |
Summary
Metrics
cozystack-operator:
cozy_cluster_info- cluster version infocozy_nodes_count- nodes by OS/kernelcozy_cluster_capacity- total cpu, memory, GPU resourcescozy_loadbalancers_count- LoadBalancer services countcozy_pvs_count- PVs by driver and sizecozy_package_info- installed packages with variantscozystack-controller:
cozy_application_count- application instances per ApplicationDefinition kindTest plan