- 
                Notifications
    You must be signed in to change notification settings 
- Fork 50
Migrate from OpenCensus library #1909
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
Migrate from OpenCensus library #1909
Conversation
| Summary of ChangesHello @tiffanny29631, 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 completes a significant migration by replacing the existing OpenCensus metrics implementation with OpenTelemetry. The core purpose is to standardize on OpenTelemetry for observability, ensuring that the system continues to collect and export metrics consistently to various destinations. The changes involve updating core metric definitions, initialization routines, and exporter configurations across multiple components, along with corresponding adjustments to documentation and test utilities. Highlights
 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 successfully migrates the project from OpenCensus to OpenTelemetry for metrics. The changes are comprehensive, covering library dependencies, metric instrumentation, recording patterns, and exporter configurations across the codebase. The test suite has also been updated to validate the new OpenTelemetry metrics. My review focuses on improving the robustness of the new implementation, particularly around shutdown contexts and resource attribute configuration.
| @tiffanny29631 will you be responding/incorporating the feedback from #1881? | 
25f0018    to
    44c34df      
    Compare
  
    | 
 Working on it now | 
44c34df    to
    7598e6d      
    Compare
  
    0b90260    to
    c6402fc      
    Compare
  
    046ef0b    to
    4b548e3      
    Compare
  
    0bc7f6b    to
    9ed8f5d      
    Compare
  
    Change is meant to be transparent to user. Using OTel SDK for metric composing in: kmetrics, core metrics, resource group metrics; Using otlp receiver in otel-agent and otel-collector; Configured deployment for new ports and component; Refactor metric composing and recording; Metric prefix remain the same to minimize breaking change. Tests updated.
9ed8f5d    to
    f73c10a      
    Compare
  
    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.
Pull Request Overview
This PR migrates Config Sync from OpenCensus to OpenTelemetry (OTLP) for metrics collection and export, while preserving metric names, types, descriptions, and export destinations. The migration updates library dependencies, metric instrument types, recording patterns, and exporter configurations.
Key Changes
- Replaced OpenCensus libraries with OpenTelemetry SDK and OTLP exporters
- Migrated metric instruments from stats.Int64/stats.Float64to OpenTelemetryCounter,Gauge, andHistogramtypes
- Updated OTEL collector configurations to use OTLP receiver on ports 4317 (gRPC) and 4318 (HTTP) instead of OpenCensus receiver on port 55678
- Refactored test infrastructure to work with OpenTelemetry metrics collection
Reviewed Changes
Copilot reviewed 53 out of 247 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description | 
|---|---|
| test/kustomization/expected.yaml | Updated OTLP receiver endpoints and processor order | 
| pkg/testing/testmetrics/testexporter.go | Complete rewrite to collect and validate OpenTelemetry metrics | 
| pkg/metrics/*.go | Migrated metric definitions and recording to OpenTelemetry | 
| pkg/resourcegroup/controllers/metrics/*.go | Migrated resource group metrics to OpenTelemetry | 
| pkg/kmetrics/*.go | Migrated kustomize metrics to OpenTelemetry | 
| manifests/*.yaml | Updated OTLP receiver configurations and container ports | 
| cmd/**/main.go | Updated exporter initialization and shutdown logic | 
| go.mod | Replaced OpenCensus dependencies with OpenTelemetry packages | 
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Pull Request Overview
Copilot reviewed 53 out of 247 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
pkg/metrics/tagkeys.go:1
- The comment on line 96 is misaligned with the variable it describes. The comment should be on its own line above the ResourceKeyPodName declaration, not sharing line 96 with the variable declaration.
// Copyright 2022 Google LLC
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
751b797    to
    e26b25b      
    Compare
  
    | // os.Exit(1) does not run deferred functions so explicitly stopping the OC Agent exporter. | ||
| if err := oce.Stop(); err != nil { | ||
| setupLog.Error(err, "failed to stop the OC Agent exporter") | ||
| // os.Exit(1) does not run deferred functions so explicitly stopping the OTLP metrics exporter. | 
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.
I'd suggest refactoring this so that the main function calls out to a helper function that returns an int, e.g.
func main() {
    os.Exit(runMain())
}
func runMain() int {
    ...
}or alternatively for an error instead of int:
func main() {
    if err := runMain(); err != nil {
        ...
        os.Exit(1)
    }
}
func runMain() error {
    ...
}That can be done as a separate change but just making a note of it
0093213    to
    4168cd9      
    Compare
  
    4168cd9    to
    48ab83e      
    Compare
  
    48ab83e    to
    a130ca8      
    Compare
  
    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.
/lgtm
| [APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sdowell The full list of commands accepted by this bot can be found here. The pull request process is described here 
Needs approval from an approver in each of these files:
 
 Approvers can indicate their approval by writing  | 
3c81962
      into
      
  
    GoogleContainerTools:main
  
    
Earlier discussions #1881
The migration replaces OpenCensus libraries with OpenTelemetry SDK while preserving:
Key Changes
1. Library Dependencies
Before (OpenCensus):
After (OpenTelemetry):
2. Metric Instrument Types
stats.Int64metric.Int64Counterstats.Int64metric.Int64Gaugestats.Float64metric.Float64Histogram3. Recording Patterns
Before (OpenCensus):
After (OpenTelemetry):
4. Tag/Attribute System
Before (OpenCensus):
After (OpenTelemetry):
5. Exporter Configuration
Before (OpenCensus):
After (OpenTelemetry):