This guide explains how to adjust the custom metrics that Config Sync exports to Prometheus, Cloud Monitoring (formerly known as Stackdriver), and Cloud Monarch (Google's internal metrics aggregator).
This solution is provided for convenience and is not maintained by Config Sync.
Custom configurations override the default settings and persist between upgrades. Config Sync tries to maintain the consistency of metrics. When you upgrade Config Sync to a new version, if you created a otel-collector-custom ConfigMap for a previous version, your custom settings might not be compatible with the new version of Config Sync. For example, metrics names, labels, and attributes can change between Config Sync versions.
When changes are made to Config Sync metrics, they are announced in the release notes. These changes might require you to update your custom otel-collector configuration.
When Config Sync is installed on a GKE cluster where a default service account is available, or on a GKE cluster that has Workload Identity enabled and IAM is correctly setup, Config Sync will try to apply the Open Telemetry Collector ConfigMap that contains googlecloud exporter to write metrics into Cloud Monitoring. The default configuration contains a bare minimum list of metrics, but some customers might want to configure different backends or fine tune the metric list for better monitoring solutions.
The otel-collector deployment in Config Sync accepts three types of ConfigMap
when configuring pipelines:
-
otel-collectorThis is the default configuration that Config Sync deploys in a non-GKE environment, which only exports the metrics through Prometheus exporter
-
otel-collector-googlecloudConfig Sync automatically deploys this configuration when Workload Identity is configured, usually on a GKE cluster.
-
otel-collector-customUsers can apply this ConfigMap and configure their own metric pipelines. Use this ConfigMap instead of modifying the others in-place, to ensure modifications don't get reverted by Config Sync.
For more details on the ConfigMaps and instructions, please refer to the monitoring doc.
This guide includes instructions for how to adjust filters, modify exporters, or opt out of exporting metrics all together.
Config Sync will check for the default credential in the environment when starting up. For a GKE cluster which always have a default service account, Config Sync will deploy the following Open Telemetry Collector configuration to enable the Google Cloud monitoring pipelines.
A pipeline consist of:
- receivers: receives metrics from all reconcilers inside Config Sync
- processors: filters or transforms metrics before sending out
- exporters: various backend endpoints and their configurations
Config Sync uses filter processor to control the exclusive list of metrics that goes into each monitoring backend.
Config Sync uses two major exporters: googlecloud exporter prometheus exporter
googlecloudstands for the configuration that exports to the Cloud Monitoring backend.googlecloud/kubernetesstands for the configuration that exports to the Cloud Monarch backendprometheusstands for the configuration that exports metrics in Prometheus format and later can be scraped by a prometheus server following this guide
Config Sync exports the following metrics that can be customized:
reconciler_errors- Number of reconciler errorspipeline_error_observed- Pipeline errors observeddeclared_resources- Number of declared resourcesapply_operations_total- Total apply operationsresource_fights_total- Total resource fightsinternal_errors_total- Total internal errorskcc_resource_count- KCC resource countresource_count- Total resource countready_resource_count- Ready resource countcluster_scoped_resource_count- Cluster-scoped resource countresource_ns_count- Resource namespace countapi_duration_seconds- API call durationapply_duration_seconds- Apply operation durationreconcile_duration_seconds- Reconcile durationrg_reconcile_duration_seconds- Resource group reconcile durationlast_sync_timestamp- Last sync timestamp
kustomize_resource_count- Kustomize resource countkustomize_field_count- Kustomize field countkustomize_deprecating_field_count- Kustomize deprecating field countkustomize_simplification_adoption_count- Kustomize simplification adoption countkustomize_builtin_transformers- Kustomize builtin transformerskustomize_helm_inflator_count- Kustomize Helm inflator countkustomize_base_count- Kustomize base countkustomize_patch_count- Kustomize patch countkustomize_ordered_top_tier_metrics- Kustomize ordered top tier metricskustomize_build_latency- Kustomize build latency
parser_duration_seconds- Parser durationremediate_duration_seconds- Remediate durationresource_conflicts_total- Resource conflicts total
kubectl get cm otel-collector-googlecloud -n config-management-monitoring -o yaml > otel-collector-config.yamlChange the .metadata.name to otel-collector-custom:
metadata:
name: otel-collector-custom
namespace: config-management-monitoringTo add or drop metrics from the available metrics list, modify the include section under the
filter processor
configuration:
processors:
filter/cloudmonitoring:
metrics:
include:
match_type: strict
metric_names:
- reconciler_errors
...
- api_duration_seconds
- crd_count # <-- Add your custom metric hereYou can also use exclude filters to remove specific metrics:
processors:
filter/cloudmonitoring:
metrics:
exclude:
match_type: regexp
metric_names:
- kustomize.* # Exclude all Kustomize metricsTo turn off the custom metrics in Cloud Monitoring, remove this section:
# Remove this entire section
metrics/cloudmonitoring:
receivers: [otlp]
processors: [batch, filter/cloudmonitoring, metricstransform/cloudmonitoring, resourcedetection]
exporters: [googlecloud]To turn off the report to Cloud Monarch, remove this section:
# Remove this entire section
metrics/kubernetes:
receivers: [otlp]
processors: [batch, filter/kubernetes, metricstransform/kubernetes, resourcedetection]
exporters: [googlecloud/kubernetes]kubectl apply -f otel-collector-config.yamlThis step spawns a new ConfigMap with name otel-collector-custom that is recognized by Config Sync, which overrides the otel-collector-googlecloud ConfigMap.
The otel-collector Pod should automatically restart when the ConfigMap is updated. If the otel-collector deployment does not restart automatically, manually restart the OpenTelemetry Collector Pod to apply the new configuration:
kubectl rollout restart deployment otel-collector -n config-management-monitoringCheck that everything is running correctly:
# Check all objects are running
kubectl get all -n config-management-monitoring
# Verify the custom ConfigMap exists
kubectl get cm -n config-management-monitoring | grep otel-collector-custom
# Check the collector logs for any errors
kubectl logs -n config-management-monitoring deployment/otel-collectorHere is a bare minimum custom ConfigMap example:
# otel-collector-custom-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: otel-collector-custom
namespace: config-management-monitoring
labels:
app: opentelemetry
component: otel-collector
data:
otel-collector-config.yaml: |
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
exporters:
debug:
verbosity: detailed
sampling_initial: 5
sampling_thereafter: 200
processors:
batch:
pipelines:
metrics:
receivers: [otlp]
processors: [batch]
exporters: [debug]- Collector not restarting:
Ensure there is exactly one Pod with status
Runningin theconfig-management-monitoringnamespace. If not, investigate and resolve issues such as resource constraints or ConfigMap configuration errors.Expected output likekubectl get pods -n config-management-monitoringIf a new Pod is stuck in an error state, review its logs to diagnose the issue.NAME READY STATUS RESTARTS AGE otel-collector-54c688bff8-swn7s 1/1 Running 0 18hkubectl logs deployment/otel-collector -n config-management-monitoring - Metrics not appearing:
a. Check the collector logs for configuration errors
b. Use the debug exporter to output detailed metric logs within the container, which can help diagnose issues.
kubectl logs deployment/otel-collector -n config-management-monitoring" - Permission issues: Verify permission is properly configured
# Check if the custom ConfigMap exists
kubectl get cm otel-collector-custom -n config-management-monitoring
# View the ConfigMap content
kubectl get cm otel-collector-custom -n config-management-monitoring -o yaml
# Check collector logs
kubectl logs -n config-management-monitoring deployment/otel-collector
# Check collector status
kubectl get pods -n config-management-monitoring -l app=opentelemetry
# Test metrics endpoint
kubectl port-forward -n config-management-monitoring svc/otel-collector 8675:8675
curl http://localhost:8675/metrics- Config Sync v1.12.0+: Uses
googlecloudexporter (recommended) - Config Sync v1.11.x and earlier: Uses
stackdriverexporter (deprecated) - Config Sync v1.8+: Custom monitoring support available
Starting in Config Sync v1.25, users can opt out of metric collection to save resource consumption (CPU/memory) and reduce telemetry overheads.
You can turn off monitoring for individual RootSync or RepoSync objects by setting spec.monitoring.enabled: false in their specification:
Note: The default
RootSyncobject namedroot-synccreated by Google Cloud management tools (like the Google Cloud console, Google Cloud CLI, or Terraform) does not support thespec.monitoring.enabledfield. Any changes to the defaultroot-syncobject will be automatically reverted by the management controller. You can setspec.monitoring.enabled: falseon customRootSyncobjects (with names other thanroot-sync) or anyRepoSyncobject.
apiVersion: configsync.gke.io/v1beta1
kind: RootSync # or RepoSync
metadata:
name: SYNC_NAME
namespace: SYNC_NAMESPACE
spec:
monitoring:
enabled: falseWhen spec.monitoring.enabled: false is set:
- The
otel-agentsidecar container is omitted from the reconciler Pod, saving container memory and CPU requests/limits. - Metric collection and exporting for that reconciler are turned off.
If an open-source cluster administrator wants to safely delete the config-management-monitoring namespace entirely and stop all OpenTelemetry controller activity:
- Set the
DISABLE_MONITORING=trueenvironment variable on bothreconciler-managerandresource-group-controller-managerDeployments usingkubectl set env(or by updating their Deployment manifests):
kubectl set env deployment/reconciler-manager -n config-management-system DISABLE_MONITORING=true
kubectl set env deployment/resource-group-controller-manager -n resource-group-system DISABLE_MONITORING=trueAlternatively, inject the environment variable directly into the Deployment manifests:
env:
- name: DISABLE_MONITORING
value: "true"- Delete the monitoring namespace:
Note: Before deleting the
config-management-monitoringnamespace, verify that theDISABLE_MONITORING=truerollout has completed on the manager controllers (so that active reconciler Pods no longer contain theotel-agentcontainer) to ensure no reconcilers attempt to export metrics to the deleted monitoring namespace.
kubectl delete ns config-management-monitoringThe following benchmark measures the memory savings from disabling the OpenTelemetry (otel-agent) sidecar on a cluster with 500 RepoSync objects across 500 namespaces on an 8-node GKE cluster:
| Metric / Scope | Monitoring Enabled (Baseline) | Monitoring Disabled (Optimized) | Total Memory Saved | Average Savings per RepoSync |
|---|---|---|---|---|
Total Memory (config-management-system) |
42,187 Mi (~41.20 GiB) | 25,542 Mi (~24.94 GiB) | 16,645 Mi (~16.25 GiB) | ~33.29 MiB (-39.5%) |
| Containers per Reconciler Pod | 3/3 (reconciler, git-sync, otel-agent) |
2/2 (reconciler, git-sync) |
-1 Sidecar Container | -100% Sidecar Overhead |
| Telemetry Network Overhead | Active gRPC to :4317 |
None (Noop) | Zero Exporter Overhead | 100% Telemetry Offloaded |
- Environment: 8-node GKE cluster running 500 active
RepoSyncinstances across 500 namespaces (test-ns-1throughtest-ns-500). - Measurement: Raw aggregated Pod memory footprint measured via
kubectl top pods -n config-management-system. - Key Finding: Disabling the OpenTelemetry sidecar across 500
RepoSyncreconcilers reclaims 16,645 Mi (~16.25 GiB) of memory back to the cluster (saving ~33.29 MiB per reconciler Pod).