Skip to content

Conversation

@tiffanny29631
Copy link
Contributor

@tiffanny29631 tiffanny29631 commented Oct 21, 2025

Earlier discussions #1881

The migration replaces OpenCensus libraries with OpenTelemetry SDK while preserving:

  • Metric names, type, resource type and descriptions
  • Recording patterns
  • Pipeline architecture and data flow
  • Sidecar configurations
  • Export destinations (Prometheus, Cloud Monitoring, Cloud Monarch)

Key Changes

1. Library Dependencies

Before (OpenCensus):

import (
    "go.opencensus.io/stats"
    "go.opencensus.io/stats/view"
    "go.opencensus.io/tag"
    "contrib.go.opencensus.io/exporter/ocagent"
)

After (OpenTelemetry):

import (
    "go.opentelemetry.io/otel"
    "go.opentelemetry.io/otel/metric"
    "go.opentelemetry.io/otel/attribute"
    "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
    "go.opentelemetry.io/otel/sdk/metric"
    "go.opentelemetry.io/otel/sdk/resource"
)

2. Metric Instrument Types

OpenCensus OpenTelemetry Description
stats.Int64 metric.Int64Counter Counter metrics
stats.Int64 metric.Int64Gauge Gauge metrics
stats.Float64 metric.Float64Histogram Histogram metrics

3. Recording Patterns

Before (OpenCensus):

stats.Record(ctx, measurement)

After (OpenTelemetry):

instrument.Record(ctx, value, metric.WithAttributes(attrs...))

4. Tag/Attribute System

Before (OpenCensus):

tagCtx, _ := tag.New(ctx, tag.Upsert(KeyStatus, "success"))

After (OpenTelemetry):

attrs := []attribute.KeyValue{
    attribute.String("status", "success"),
}

5. Exporter Configuration

Before (OpenCensus):

oce, err := ocagent.NewExporter(ocagent.WithInsecure())

After (OpenTelemetry):

exporter, err := otlpmetricgrpc.New(
    context.Background(),
    otlpmetricgrpc.WithInsecure(),
    otlpmetricgrpc.WithEndpoint("otel-collector:4317"),
)

@gemini-code-assist
Copy link

Summary of Changes

Hello @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

  • Migration to OpenTelemetry SDK: The codebase has been migrated from using OpenCensus libraries to the OpenTelemetry SDK for metrics collection. This change preserves existing metric names, types, descriptions, recording patterns, pipeline architecture, data flow, sidecar configurations, and export destinations (Prometheus, Cloud Monitoring, Cloud Monarch).
  • Updated Metric Initialization and Recording: All components (hydration-controller, reconciler-manager, reconciler, resourcegroup) now use new OpenTelemetry initialization functions (InitializeOTelKustomizeMetrics, InitializeOTelMetrics, InitializeOTelResourceGroupMetrics) and record metrics using the OpenTelemetry API (metric.Int64Gauge, metric.Float64Histogram, metric.Int64Counter) with attribute.KeyValue for labels.
  • OTLP Exporter Configuration: The metric exporters have been updated to use the OTLP gRPC exporter (otlpmetricgrpc.New) instead of the OpenCensus Agent exporter. This includes changes to how exporters are registered and shut down, and updates to related configuration files (otel-collector-config.yaml, otel-agent-cm.yaml, otel-agent-reconciler-cm.yaml) to use otlp receivers and endpoints.
  • Dependency Updates: The go.mod and go.sum files have been updated to remove OpenCensus dependencies (contrib.go.opencensus.io/exporter/ocagent, go.opencensus.io) and introduce OpenTelemetry dependencies (go.opentelemetry.io/otel, go.opentelemetry.io/otel/metric, go.opentelemetry.io/otel/sdk, go.opentelemetry.io/otel/sdk/metric, go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc). The github.com/cenkalti/backoff/v5 library has also been added.
  • Test Infrastructure Modernization: The testing framework has been updated to use testmetrics.NewTestExporter() and testmetrics.ResetGlobalMetrics() for metric validation, replacing the OpenCensus-specific testmetrics.RegisterMetrics() and view.RegisterExporter() calls. This ensures compatibility with the new OpenTelemetry metric system.
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 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.

@sdowell
Copy link
Contributor

sdowell commented Oct 21, 2025

@tiffanny29631 will you be responding/incorporating the feedback from #1881?

@tiffanny29631 tiffanny29631 force-pushed the oc-migration branch 3 times, most recently from 25f0018 to 44c34df Compare October 21, 2025 23:59
@tiffanny29631
Copy link
Contributor Author

@tiffanny29631 will you be responding/incorporating the feedback from #1881?

Working on it now

@tiffanny29631
Copy link
Contributor Author

@sdowell comments in #1881 addressed.

@tiffanny29631 tiffanny29631 force-pushed the oc-migration branch 3 times, most recently from 046ef0b to 4b548e3 Compare October 23, 2025 20:49
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.
- pass on context in register
- constify conext shutdonw timeout
- restore header
- remove unnecessary metric attribute on exporter setup
- restore test coverage from rebase conflict
@mikebz mikebz requested a review from Copilot October 25, 2025 02:43
Copy link

Copilot AI left a 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.Float64 to OpenTelemetry Counter, Gauge, and Histogram types
  • 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.

@mikebz mikebz requested a review from Copilot October 27, 2025 18:01
Copy link

Copilot AI left a 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.

// 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.
Copy link
Contributor

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

- restore kmetrics record.go header
- pass on rg manager container name from register
Copy link
Contributor

@sdowell sdowell left a comment

Choose a reason for hiding this comment

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

/lgtm

@google-oss-prow
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit 3c81962 into GoogleContainerTools:main Oct 27, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants