From f1bc179e3d8beeaa0c91606c6e1905b5f79ac117 Mon Sep 17 00:00:00 2001 From: Rafael Westphal Date: Wed, 6 May 2026 18:12:20 +0000 Subject: [PATCH 01/19] Initial Implementation of global knob for otlp_exporter --- cmd/google_cloud_ops_agent_engine/main.go | 8 +- cmd/ops_agent_uap_plugin/service_windows.go | 21 +- cmd/ops_agent_windows/run_windows.go | 13 +- confgenerator/confgenerator.go | 4 + confgenerator/config.go | 17 + confgenerator/config_global.go | 8 + confgenerator/confmerger.go | 3 + confgenerator/feature_tracking.go | 2 + confgenerator/files.go | 2 + .../EXPERIMENTAL_FEATURES | 2 +- .../input.yaml | 3 + .../EXPERIMENTAL_FEATURES | 2 +- .../input.yaml | 3 + .../EXPERIMENTAL_FEATURES | 1 - .../input.yaml | 3 + .../EXPERIMENTAL_FEATURES | 1 - .../input.yaml | 3 + .../0f15dbe303dc7122d43443c9a4c31632.lua | 28 + .../4d6012ff003886818fb9b9285b4af962.lua | 19 + .../5fc5f42c16c9e1ab8292e3d42f74f3be.lua | 49 + .../b4a0dead382dce7b4fe011d3f59fdb6d.lua | 17 + .../linux-gpu/enabled_receivers_otlp.json | 1 + .../linux-gpu/feature_tracking_otlp.json | 1 + .../golden/linux-gpu/features.yaml | 24 + .../golden/linux-gpu/fluent_bit_main.conf | 153 ++ .../golden/linux-gpu/fluent_bit_parser.conf | 13 + .../golden/linux-gpu/otel.yaml | 1127 ++++++++++++ .../0f15dbe303dc7122d43443c9a4c31632.lua | 28 + .../4d6012ff003886818fb9b9285b4af962.lua | 19 + .../5fc5f42c16c9e1ab8292e3d42f74f3be.lua | 49 + .../b4a0dead382dce7b4fe011d3f59fdb6d.lua | 17 + .../golden/linux/enabled_receivers_otlp.json | 1 + .../golden/linux/feature_tracking_otlp.json | 1 + .../golden/linux/features.yaml | 24 + .../golden/linux/fluent_bit_main.conf | 153 ++ .../golden/linux/fluent_bit_parser.conf | 13 + .../golden/linux/otel.yaml | 1067 +++++++++++ .../0f15dbe303dc7122d43443c9a4c31632.lua | 28 + .../4d6012ff003886818fb9b9285b4af962.lua | 19 + .../5fc5f42c16c9e1ab8292e3d42f74f3be.lua | 49 + .../b4a0dead382dce7b4fe011d3f59fdb6d.lua | 17 + .../windows-2012/enabled_receivers_otlp.json | 1 + .../windows-2012/feature_tracking_otlp.json | 1 + .../golden/windows-2012/features.yaml | 24 + .../golden/windows-2012/fluent_bit_main.conf | 153 ++ .../windows-2012/fluent_bit_parser.conf | 13 + .../golden/windows-2012/otel.yaml | 1614 +++++++++++++++++ .../0f15dbe303dc7122d43443c9a4c31632.lua | 28 + .../4d6012ff003886818fb9b9285b4af962.lua | 19 + .../5fc5f42c16c9e1ab8292e3d42f74f3be.lua | 49 + .../b4a0dead382dce7b4fe011d3f59fdb6d.lua | 17 + .../windows/enabled_receivers_otlp.json | 1 + .../golden/windows/feature_tracking_otlp.json | 1 + .../golden/windows/features.yaml | 24 + .../golden/windows/fluent_bit_main.conf | 153 ++ .../golden/windows/fluent_bit_parser.conf | 13 + .../golden/windows/otel.yaml | 1614 +++++++++++++++++ .../otlp_exporter_global_config/input.yaml | 2 + .../EXPERIMENTAL_FEATURES | 1 - .../test-otlp-exporter-only/input.yaml | 3 + integration_test/agents/agents.go | 16 + .../third_party_apps_test/main_test.go | 18 +- internal/experiments/experiments.go | 6 +- internal/healthchecks/api_check.go | 26 +- internal/healthchecks/healthchecks.go | 5 +- internal/self_metrics/self_metrics.go | 2 + 66 files changed, 6776 insertions(+), 41 deletions(-) delete mode 100644 confgenerator/testdata/goldens/invalid-metrics-exporter_otlphttp_invalid_processor/EXPERIMENTAL_FEATURES delete mode 100644 confgenerator/testdata/goldens/metrics-exporter_prometheus_otlp/EXPERIMENTAL_FEATURES create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/0f15dbe303dc7122d43443c9a4c31632.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/4d6012ff003886818fb9b9285b4af962.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/5fc5f42c16c9e1ab8292e3d42f74f3be.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/b4a0dead382dce7b4fe011d3f59fdb6d.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/enabled_receivers_otlp.json create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/feature_tracking_otlp.json create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/features.yaml create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/fluent_bit_main.conf create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/fluent_bit_parser.conf create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/otel.yaml create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux/0f15dbe303dc7122d43443c9a4c31632.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux/4d6012ff003886818fb9b9285b4af962.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux/5fc5f42c16c9e1ab8292e3d42f74f3be.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux/b4a0dead382dce7b4fe011d3f59fdb6d.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux/enabled_receivers_otlp.json create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux/feature_tracking_otlp.json create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux/features.yaml create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux/fluent_bit_main.conf create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux/fluent_bit_parser.conf create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux/otel.yaml create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows-2012/0f15dbe303dc7122d43443c9a4c31632.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows-2012/4d6012ff003886818fb9b9285b4af962.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows-2012/5fc5f42c16c9e1ab8292e3d42f74f3be.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows-2012/b4a0dead382dce7b4fe011d3f59fdb6d.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows-2012/enabled_receivers_otlp.json create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows-2012/feature_tracking_otlp.json create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows-2012/features.yaml create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows-2012/fluent_bit_main.conf create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows-2012/fluent_bit_parser.conf create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows-2012/otel.yaml create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows/0f15dbe303dc7122d43443c9a4c31632.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows/4d6012ff003886818fb9b9285b4af962.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows/5fc5f42c16c9e1ab8292e3d42f74f3be.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows/b4a0dead382dce7b4fe011d3f59fdb6d.lua create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows/enabled_receivers_otlp.json create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows/feature_tracking_otlp.json create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows/features.yaml create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows/fluent_bit_main.conf create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows/fluent_bit_parser.conf create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/golden/windows/otel.yaml create mode 100644 confgenerator/testdata/goldens/otlp_exporter_global_config/input.yaml delete mode 100644 confgenerator/testdata/goldens/test-otlp-exporter-only/EXPERIMENTAL_FEATURES diff --git a/cmd/google_cloud_ops_agent_engine/main.go b/cmd/google_cloud_ops_agent_engine/main.go index 6fce0c5916..db5c8eb6a8 100644 --- a/cmd/google_cloud_ops_agent_engine/main.go +++ b/cmd/google_cloud_ops_agent_engine/main.go @@ -36,12 +36,12 @@ var ( healthChecks = flag.Bool("healthchecks", false, "run health checks and exit") ) -func runHealthChecks() { +func runHealthChecks(ctx context.Context) { logger := healthchecks.CreateHealthChecksLogger(*logsDir) defaultLogger := logs.NewSimpleLogger() - healthCheckResults := healthchecks.HealthCheckRegistryFactory().RunAllHealthChecks(logger) + healthCheckResults := healthchecks.HealthCheckRegistryFactory(ctx).RunAllHealthChecks(logger) healthchecks.LogHealthCheckResults(healthCheckResults, defaultLogger) } @@ -60,6 +60,8 @@ func run() error { return err } + ctx = uc.ContextWithExperiments(ctx) + // Log the built-in and merged config files to STDOUT. These are then written // by journald to var/log/syslog and so to Cloud Logging once the ops-agent is // running. @@ -68,7 +70,7 @@ func run() error { switch *service { case "": - runHealthChecks() + runHealthChecks(ctx) log.Println("Startup checks finished") if *healthChecks { // If healthchecks is set, stop here diff --git a/cmd/ops_agent_uap_plugin/service_windows.go b/cmd/ops_agent_uap_plugin/service_windows.go index f6a62616dc..82444d9d35 100644 --- a/cmd/ops_agent_uap_plugin/service_windows.go +++ b/cmd/ops_agent_uap_plugin/service_windows.go @@ -112,7 +112,8 @@ func (ps *OpsAgentPluginServer) Start(ctx context.Context, msg *pb.StartRequest) } // Subagents config validation and generation. - if err := generateSubAgentConfigs(ctx, OpsAgentConfigLocationWindows, pluginStateDir); err != nil { + uc, err := generateSubAgentConfigs(ctx, OpsAgentConfigLocationWindows, pluginStateDir) + if err != nil { ps.cancelAndSetPluginError(&OpsAgentPluginError{ Message: fmt.Sprintf("Start() failed to validate the custom Ops Agent config, and generate sub-agents config: %s", err), ShouldRestart: false, @@ -120,9 +121,11 @@ func (ps *OpsAgentPluginServer) Start(ctx context.Context, msg *pb.StartRequest) return &pb.StartResponse{}, nil } + ctx = uc.ContextWithExperiments(ctx) + // Trigger Healthchecks. healthCheckFileLogger := healthchecks.CreateHealthChecksLogger(filepath.Join(pluginStateDir, LogsDirectory)) - runHealthChecks(healthCheckFileLogger) + runHealthChecks(ctx, healthCheckFileLogger) // Create a Windows Job object and stores its handle, to ensure that all child processes are killed when the parent process exits. _, err = createWindowsJobHandle() @@ -206,10 +209,10 @@ func findPreExistentAgents(mgr serviceManager, agentWindowsServiceNames []string return alreadyInstalledAgentServiceNames, nil } -func generateSubAgentConfigs(ctx context.Context, userConfigPath string, pluginStateDir string) error { +func generateSubAgentConfigs(ctx context.Context, userConfigPath string, pluginStateDir string) (*confgenerator.UnifiedConfig, error) { uc, err := confgenerator.MergeConfFiles(ctx, userConfigPath) if err != nil { - return err + return nil, err } log.Printf("Built-in config:\n%s\n", confgenerator.BuiltInConfStructs["windows"]) @@ -217,7 +220,7 @@ func generateSubAgentConfigs(ctx context.Context, userConfigPath string, pluginS // The generated otlp metric json files are used only by the otel service. if err = self_metrics.GenerateOpsAgentSelfMetricsOTLPJSON(ctx, userConfigPath, filepath.Join(pluginStateDir, GeneratedConfigsOutDir, "otel")); err != nil { - return err + return nil, err } for _, subagent := range []string{ @@ -230,14 +233,14 @@ func generateSubAgentConfigs(ctx context.Context, userConfigPath string, pluginS filepath.Join(pluginStateDir, LogsDirectory), filepath.Join(pluginStateDir, RuntimeDirectory), filepath.Join(pluginStateDir, GeneratedConfigsOutDir, subagent)); err != nil { - return err + return nil, err } } - return nil + return uc, nil } -func runHealthChecks(healthCheckFileLogger logs.StructuredLogger) { - gceHealthChecks := healthchecks.HealthCheckRegistryFactory() +func runHealthChecks(ctx context.Context, healthCheckFileLogger logs.StructuredLogger) { + gceHealthChecks := healthchecks.HealthCheckRegistryFactory(ctx) // Log health check results to health-checks.log log file. gceHealthChecks.RunAllHealthChecks(healthCheckFileLogger) diff --git a/cmd/ops_agent_windows/run_windows.go b/cmd/ops_agent_windows/run_windows.go index 17b3df7206..17b9b3256d 100644 --- a/cmd/ops_agent_windows/run_windows.go +++ b/cmd/ops_agent_windows/run_windows.go @@ -53,6 +53,7 @@ type service struct { log debug.Log userConf string outDirectory string + uc *confgenerator.UnifiedConfig } func (s *service) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) { @@ -75,7 +76,8 @@ func (s *service) Execute(args []string, r <-chan svc.ChangeRequest, changes cha return false, 2 } s.log.Info(EngineEventID, "generated configuration files") - s.runHealthChecks() + ctx = s.uc.ContextWithExperiments(ctx) + s.runHealthChecks(ctx) changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} if err := s.startSubagents(); err != nil { @@ -141,16 +143,16 @@ func (s *service) checkForStandaloneAgents(unified *confgenerator.UnifiedConfig) return nil } -func getHealthCheckResults() []healthchecks.HealthCheckResult { +func getHealthCheckResults(ctx context.Context) []healthchecks.HealthCheckResult { logsDir := filepath.Join(os.Getenv("PROGRAMDATA"), dataDirectory, "log") - gceHealthChecks := healthchecks.HealthCheckRegistryFactory() + gceHealthChecks := healthchecks.HealthCheckRegistryFactory(ctx) logger := healthchecks.CreateHealthChecksLogger(logsDir) return gceHealthChecks.RunAllHealthChecks(logger) } -func (srv *service) runHealthChecks() { - healthCheckResults := getHealthCheckResults() +func (srv *service) runHealthChecks(ctx context.Context) { + healthCheckResults := getHealthCheckResults(ctx) logger := logs.WindowsServiceLogger{EventID: EngineEventID, Logger: srv.log} healthchecks.LogHealthCheckResults(healthCheckResults, logger) srv.log.Info(EngineEventID, "Startup checks finished") @@ -162,6 +164,7 @@ func (s *service) generateConfigs(ctx context.Context) error { if err != nil { return err } + s.uc = uc s.log.Info(EngineEventID, fmt.Sprintf("Built-in config:\n%s\n", confgenerator.BuiltInConfStructs["windows"])) s.log.Info(EngineEventID, fmt.Sprintf("Merged config:\n%s\n", uc)) diff --git a/confgenerator/confgenerator.go b/confgenerator/confgenerator.go index 9c9e0e1f78..44da1f6693 100644 --- a/confgenerator/confgenerator.go +++ b/confgenerator/confgenerator.go @@ -207,7 +207,9 @@ func fileStorageExtension(stateDir string) otel.Component { } func (uc *UnifiedConfig) GenerateOtelConfig(ctx context.Context, outDir, stateDir string) (string, error) { + ctx = uc.ContextWithExperiments(ctx) p := platform.FromContext(ctx) + userAgent, _ := p.UserAgent("Google-Cloud-Ops-Agent-Metrics") metricVersionLabel, _ := p.VersionLabel("google-cloud-ops-agent-metrics") loggingVersionLabel, _ := p.VersionLabel("google-cloud-ops-agent-logging") @@ -485,7 +487,9 @@ func (uc *UnifiedConfig) generateOtelPipelines(ctx context.Context) (map[string] // GenerateFluentBitConfigs generates configuration file(s) for Fluent Bit. // It returns a map of filenames to file contents. func (uc *UnifiedConfig) GenerateFluentBitConfigs(ctx context.Context, logsDir string, stateDir string) (map[string]string, error) { + ctx = uc.ContextWithExperiments(ctx) userAgent, _ := platform.FromContext(ctx).UserAgent("Google-Cloud-Ops-Agent-Logging") + components, err := uc.generateFluentbitComponents(ctx, userAgent) if err != nil { return nil, err diff --git a/confgenerator/config.go b/confgenerator/config.go index 7845e039fa..5c10e2ad78 100644 --- a/confgenerator/config.go +++ b/confgenerator/config.go @@ -72,6 +72,21 @@ func (uc *UnifiedConfig) HasCombined() bool { return uc.Combined != nil } +func (uc *UnifiedConfig) ContextWithExperiments(ctx context.Context) context.Context { + if uc == nil { + return ctx + } + enabledExperiments := experiments.FromContext(ctx) + newExperiments := map[string]bool{} + for k, v := range enabledExperiments { + newExperiments[k] = v + } + if uc.Global.GetOtlpExporter() { + newExperiments["otlp_exporter"] = true + } + return experiments.ContextWithExperiments(ctx, newExperiments) +} + const ( ExperimentalFluentBitMetricsPortEnv = "EXPERIMENTAL_OPS_AGENT_FLUENT_BIT_METRICS_PORT" ExperimentalOtelMetricsPortEnv = "EXPERIMENTAL_OPS_AGENT_OTEL_METRICS_PORT" @@ -875,7 +890,9 @@ type TracesService struct { } func (uc *UnifiedConfig) Validate(ctx context.Context) error { + ctx = uc.ContextWithExperiments(ctx) if uc.Logging != nil { + if err := uc.ValidateLogging(); err != nil { return err } diff --git a/confgenerator/config_global.go b/confgenerator/config_global.go index 3aaeb8ac9d..ca24fafe4e 100644 --- a/confgenerator/config_global.go +++ b/confgenerator/config_global.go @@ -17,6 +17,14 @@ package confgenerator type Global struct { DefaultSelfLogFileCollection *bool `yaml:"default_self_log_file_collection,omitempty"` DefaultLogFileRotation *LogFileRotation `yaml:"default_self_log_file_rotation,omitempty"` + OtlpExporter *bool `yaml:"otlp_exporter,omitempty"` +} + +func (g *Global) GetOtlpExporter() bool { + if g != nil && g.OtlpExporter != nil { + return *g.OtlpExporter + } + return false } // Get whether self log collection should be enabled. Defaults to true if unset. diff --git a/confgenerator/confmerger.go b/confgenerator/confmerger.go index 9369e51cb7..5be1fd3701 100644 --- a/confgenerator/confmerger.go +++ b/confgenerator/confmerger.go @@ -42,6 +42,8 @@ func MergeConfFiles(ctx context.Context, userConfPath string) (*UnifiedConfig, e mergeConfigs(result, overrides) } + ctx = result.ContextWithExperiments(ctx) + if err := result.Validate(ctx); err != nil { return nil, err } @@ -49,6 +51,7 @@ func MergeConfFiles(ctx context.Context, userConfPath string) (*UnifiedConfig, e // Ensure the merged config struct fields are valid. v := newValidator() if err := v.StructCtx(ctx, result); err != nil { + log.Fatalf("merged config failed to validate: %v", err) } return result, nil diff --git a/confgenerator/feature_tracking.go b/confgenerator/feature_tracking.go index 2480b553f4..50271fc13d 100644 --- a/confgenerator/feature_tracking.go +++ b/confgenerator/feature_tracking.go @@ -75,7 +75,9 @@ type CustomFeatures interface { // Automatic collection of bool or int fields. Any value that exists on tracking // tag will be used instead of value from UnifiedConfig. func ExtractFeatures(ctx context.Context, userUc, mergedUc *UnifiedConfig) ([]Feature, error) { + ctx = mergedUc.ContextWithExperiments(ctx) allFeatures := getOverriddenDefaultPipelines(userUc) + allFeatures = append(allFeatures, getSelfLogCollection(userUc)) allFeatures = append(allFeatures, getOTelLoggingSupportedConfig(ctx, mergedUc)) allFeatures = append(allFeatures, getOtlpExporterExperimentConfig(ctx)...) diff --git a/confgenerator/files.go b/confgenerator/files.go index 23afc6b715..8ab982a8e7 100644 --- a/confgenerator/files.go +++ b/confgenerator/files.go @@ -45,7 +45,9 @@ func ReadUnifiedConfigFromFile(ctx context.Context, path string) (*UnifiedConfig } func (uc *UnifiedConfig) GenerateFilesFromConfig(ctx context.Context, service, logsDir, stateDir, outDir string) error { + ctx = uc.ContextWithExperiments(ctx) switch service { + case "": // Validate-only. return nil case "fluentbit": diff --git a/confgenerator/testdata/goldens/combined-receiver_otlp_otel_logging_otlpgrpc_exporter/EXPERIMENTAL_FEATURES b/confgenerator/testdata/goldens/combined-receiver_otlp_otel_logging_otlpgrpc_exporter/EXPERIMENTAL_FEATURES index 1254b2789d..96e7b5fd45 100644 --- a/confgenerator/testdata/goldens/combined-receiver_otlp_otel_logging_otlpgrpc_exporter/EXPERIMENTAL_FEATURES +++ b/confgenerator/testdata/goldens/combined-receiver_otlp_otel_logging_otlpgrpc_exporter/EXPERIMENTAL_FEATURES @@ -1 +1 @@ -otlp_exporter,otlp_logging,otel_logging +otlp_logging,otel_logging diff --git a/confgenerator/testdata/goldens/combined-receiver_otlp_otel_logging_otlpgrpc_exporter/input.yaml b/confgenerator/testdata/goldens/combined-receiver_otlp_otel_logging_otlpgrpc_exporter/input.yaml index e8aec4319d..0becbc05f4 100644 --- a/confgenerator/testdata/goldens/combined-receiver_otlp_otel_logging_otlpgrpc_exporter/input.yaml +++ b/confgenerator/testdata/goldens/combined-receiver_otlp_otel_logging_otlpgrpc_exporter/input.yaml @@ -12,7 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +global: + otlp_exporter: true combined: + receivers: otlp: type: otlp diff --git a/confgenerator/testdata/goldens/combined-receiver_otlp_otlpgrpc_exporter/EXPERIMENTAL_FEATURES b/confgenerator/testdata/goldens/combined-receiver_otlp_otlpgrpc_exporter/EXPERIMENTAL_FEATURES index 91babc70cd..515983c71a 100644 --- a/confgenerator/testdata/goldens/combined-receiver_otlp_otlpgrpc_exporter/EXPERIMENTAL_FEATURES +++ b/confgenerator/testdata/goldens/combined-receiver_otlp_otlpgrpc_exporter/EXPERIMENTAL_FEATURES @@ -1 +1 @@ -otlp_exporter,otlp_logging +otlp_logging diff --git a/confgenerator/testdata/goldens/combined-receiver_otlp_otlpgrpc_exporter/input.yaml b/confgenerator/testdata/goldens/combined-receiver_otlp_otlpgrpc_exporter/input.yaml index 7567f69f2b..34127212dd 100644 --- a/confgenerator/testdata/goldens/combined-receiver_otlp_otlpgrpc_exporter/input.yaml +++ b/confgenerator/testdata/goldens/combined-receiver_otlp_otlpgrpc_exporter/input.yaml @@ -12,7 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +global: + otlp_exporter: true combined: + receivers: otlp: type: otlp diff --git a/confgenerator/testdata/goldens/invalid-metrics-exporter_otlphttp_invalid_processor/EXPERIMENTAL_FEATURES b/confgenerator/testdata/goldens/invalid-metrics-exporter_otlphttp_invalid_processor/EXPERIMENTAL_FEATURES deleted file mode 100644 index 9d450f37a8..0000000000 --- a/confgenerator/testdata/goldens/invalid-metrics-exporter_otlphttp_invalid_processor/EXPERIMENTAL_FEATURES +++ /dev/null @@ -1 +0,0 @@ -otlp_exporter diff --git a/confgenerator/testdata/goldens/invalid-metrics-exporter_otlphttp_invalid_processor/input.yaml b/confgenerator/testdata/goldens/invalid-metrics-exporter_otlphttp_invalid_processor/input.yaml index 5474eeab87..38dd2450fc 100644 --- a/confgenerator/testdata/goldens/invalid-metrics-exporter_otlphttp_invalid_processor/input.yaml +++ b/confgenerator/testdata/goldens/invalid-metrics-exporter_otlphttp_invalid_processor/input.yaml @@ -12,7 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +global: + otlp_exporter: true metrics: + processors: metrics_filter: type: exclude_metrics diff --git a/confgenerator/testdata/goldens/metrics-exporter_prometheus_otlp/EXPERIMENTAL_FEATURES b/confgenerator/testdata/goldens/metrics-exporter_prometheus_otlp/EXPERIMENTAL_FEATURES deleted file mode 100644 index 9d450f37a8..0000000000 --- a/confgenerator/testdata/goldens/metrics-exporter_prometheus_otlp/EXPERIMENTAL_FEATURES +++ /dev/null @@ -1 +0,0 @@ -otlp_exporter diff --git a/confgenerator/testdata/goldens/metrics-exporter_prometheus_otlp/input.yaml b/confgenerator/testdata/goldens/metrics-exporter_prometheus_otlp/input.yaml index b9a8c4f33a..99cdcae53c 100644 --- a/confgenerator/testdata/goldens/metrics-exporter_prometheus_otlp/input.yaml +++ b/confgenerator/testdata/goldens/metrics-exporter_prometheus_otlp/input.yaml @@ -12,7 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +global: + otlp_exporter: true metrics: + receivers: prometheus: type: prometheus diff --git a/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/0f15dbe303dc7122d43443c9a4c31632.lua b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/0f15dbe303dc7122d43443c9a4c31632.lua new file mode 100644 index 0000000000..dda27aee97 --- /dev/null +++ b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/0f15dbe303dc7122d43443c9a4c31632.lua @@ -0,0 +1,28 @@ + +function process(tag, timestamp, record) +local v = "ops-agent"; +(function(value) +if record["logging.googleapis.com/labels"] == nil +then +record["logging.googleapis.com/labels"] = {} +end +record["logging.googleapis.com/labels"]["agent.googleapis.com/health/agentKind"] = value +end)(v) +local v = "latest"; +(function(value) +if record["logging.googleapis.com/labels"] == nil +then +record["logging.googleapis.com/labels"] = {} +end +record["logging.googleapis.com/labels"]["agent.googleapis.com/health/agentVersion"] = value +end)(v) +local v = "v1"; +(function(value) +if record["logging.googleapis.com/labels"] == nil +then +record["logging.googleapis.com/labels"] = {} +end +record["logging.googleapis.com/labels"]["agent.googleapis.com/health/schemaVersion"] = value +end)(v) +return 2, timestamp, record +end diff --git a/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/4d6012ff003886818fb9b9285b4af962.lua b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/4d6012ff003886818fb9b9285b4af962.lua new file mode 100644 index 0000000000..c225be24d5 --- /dev/null +++ b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/4d6012ff003886818fb9b9285b4af962.lua @@ -0,0 +1,19 @@ + +function process(tag, timestamp, record) +local __field_0 = (function() +return record["severity"] +end)(); +(function(value) +record["severity"] = value +end)(nil); +local v = __field_0; +if v == "debug" then v = "DEBUG" +elseif v == "error" then v = "ERROR" +elseif v == "info" then v = "INFO" +elseif v == "warn" then v = "WARNING" +end +(function(value) +record["logging.googleapis.com/severity"] = value +end)(v) +return 2, timestamp, record +end diff --git a/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/5fc5f42c16c9e1ab8292e3d42f74f3be.lua b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/5fc5f42c16c9e1ab8292e3d42f74f3be.lua new file mode 100644 index 0000000000..c5465182b5 --- /dev/null +++ b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/5fc5f42c16c9e1ab8292e3d42f74f3be.lua @@ -0,0 +1,49 @@ + + function shallow_merge(record, parsedRecord) + -- If no exiting record exists + if (record == nil) then + return parsedRecord + end + + for k, v in pairs(parsedRecord) do + record[k] = v + end + + return record +end + +function merge(record, parsedRecord) + -- If no exiting record exists + if record == nil then + return parsedRecord + end + + -- Potentially overwrite or merge the original records. + for k, v in pairs(parsedRecord) do + -- If there is no conflict + if k == "logging.googleapis.com/logName" then + -- Ignore the parsed payload since the logName is controlled + -- by the OpsAgent. + elseif k == "logging.googleapis.com/labels" then + -- LogEntry.labels are basically a map[string]string and so only require a + -- shallow merge (one level deep merge). + record[k] = shallow_merge(record[k], v) + else + record[k] = v + end + end + + return record +end + +function parser_merge_record(tag, timestamp, record) + originalPayload = record["logging.googleapis.com/__tmp"] + if originalPayload == nil then + return 0, timestamp, record + end + + -- Remove original payload + record["logging.googleapis.com/__tmp"] = nil + record = merge(originalPayload, record) + return 2, timestamp, record +end diff --git a/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/b4a0dead382dce7b4fe011d3f59fdb6d.lua b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/b4a0dead382dce7b4fe011d3f59fdb6d.lua new file mode 100644 index 0000000000..6263563b66 --- /dev/null +++ b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/b4a0dead382dce7b4fe011d3f59fdb6d.lua @@ -0,0 +1,17 @@ + +function parser_nest(tag, timestamp, record) + local nestedRecord = {} + local parseKey = "message" + for k, v in pairs(record) do + if k ~= parseKey then + nestedRecord[k] = v + end + end + + local result = {} + result[parseKey] = record[parseKey] + result["logging.googleapis.com/__tmp"] = nestedRecord + + return 2, timestamp, result +end + diff --git a/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/enabled_receivers_otlp.json b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/enabled_receivers_otlp.json new file mode 100644 index 0000000000..9cf0a64e2d --- /dev/null +++ b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/enabled_receivers_otlp.json @@ -0,0 +1 @@ +{"resourceMetrics":[{"resource":{"attributes":[{"key":"k","value":{"stringValue":"v"}}]},"scopeMetrics":[{"scope":{},"metrics":[{"name":"agent.googleapis.com/agent/ops_agent/enabled_receivers","gauge":{"dataPoints":[{"attributes":[{"key":"telemetry_type","value":{"stringValue":"metrics"}},{"key":"receiver_type","value":{"stringValue":"hostmetrics"}}],"asInt":"1"},{"attributes":[{"key":"telemetry_type","value":{"stringValue":"logs"}},{"key":"receiver_type","value":{"stringValue":"files"}}],"asInt":"1"}]}}]}]}]} \ No newline at end of file diff --git a/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/feature_tracking_otlp.json b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/feature_tracking_otlp.json new file mode 100644 index 0000000000..919ccdd5c6 --- /dev/null +++ b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/feature_tracking_otlp.json @@ -0,0 +1 @@ +{"resourceMetrics":[{"resource":{"attributes":[{"key":"k","value":{"stringValue":"v"}}]},"scopeMetrics":[{"scope":{},"metrics":[{"name":"agent.googleapis.com/agent/internal/ops/feature_tracking","gauge":{"dataPoints":[{"attributes":[{"key":"module","value":{"stringValue":"logging"}},{"key":"feature","value":{"stringValue":"service:pipelines"}},{"key":"key","value":{"stringValue":"default_pipeline_overridden"}},{"key":"value","value":{"stringValue":"false"}}],"asInt":"1"},{"attributes":[{"key":"module","value":{"stringValue":"metrics"}},{"key":"feature","value":{"stringValue":"service:pipelines"}},{"key":"key","value":{"stringValue":"default_pipeline_overridden"}},{"key":"value","value":{"stringValue":"false"}}],"asInt":"1"},{"attributes":[{"key":"module","value":{"stringValue":"global"}},{"key":"feature","value":{"stringValue":"default:self_log"}},{"key":"key","value":{"stringValue":"default_self_log_file_collection"}},{"key":"value","value":{"stringValue":"true"}}],"asInt":"1"},{"attributes":[{"key":"module","value":{"stringValue":"logging"}},{"key":"feature","value":{"stringValue":"service:otel_logging"}},{"key":"key","value":{"stringValue":"otel_logging_supported_config"}},{"key":"value","value":{"stringValue":"true"}}],"asInt":"1"},{"attributes":[{"key":"module","value":{"stringValue":"metrics"}},{"key":"feature","value":{"stringValue":"exporters:otlp"}},{"key":"key","value":{"stringValue":"otlp_exporter"}},{"key":"value","value":{"stringValue":"true"}}],"asInt":"1"},{"attributes":[{"key":"module","value":{"stringValue":"logging"}},{"key":"feature","value":{"stringValue":"exporters:otlp"}},{"key":"key","value":{"stringValue":"otlp_exporter"}},{"key":"value","value":{"stringValue":"true"}}],"asInt":"1"}]}}]}]}]} \ No newline at end of file diff --git a/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/features.yaml b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/features.yaml new file mode 100644 index 0000000000..43639eb425 --- /dev/null +++ b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/features.yaml @@ -0,0 +1,24 @@ +- module: logging + feature: service:pipelines + key: default_pipeline_overridden + value: "false" +- module: metrics + feature: service:pipelines + key: default_pipeline_overridden + value: "false" +- module: global + feature: default:self_log + key: default_self_log_file_collection + value: "true" +- module: logging + feature: service:otel_logging + key: otel_logging_supported_config + value: "true" +- module: metrics + feature: exporters:otlp + key: otlp_exporter + value: "true" +- module: logging + feature: exporters:otlp + key: otlp_exporter + value: "true" diff --git a/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/fluent_bit_main.conf b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/fluent_bit_main.conf new file mode 100644 index 0000000000..9d767d886b --- /dev/null +++ b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/fluent_bit_main.conf @@ -0,0 +1,153 @@ +@SET buffers_dir=/var/lib/google-cloud-ops-agent/fluent-bit/buffers +@SET logs_dir=/var/log/google-cloud-ops-agent + +[SERVICE] + Daemon off + Flush 1 + Log_Level info + dns.resolver legacy + storage.backlog.mem_limit 50M + storage.checksum off + storage.max_chunks_up 128 + storage.metrics on + storage.sync normal + +[INPUT] + Name fluentbit_metrics + Scrape_Interval 60 + Scrape_On_Start True + +[INPUT] + Dummy {"code": "LogPingOpsAgent", "severity": "DEBUG"} + Interval_NSec 0 + Interval_Sec 600 + Name dummy + Tag ops-agent-health + +[INPUT] + Buffer_Chunk_Size 512k + Buffer_Max_Size 2M + DB ${buffers_dir}/ops-agent-fluent-bit + DB.locking true + Key message + Mem_Buf_Limit 10M + Name tail + Path ${logs_dir}/subagents/logging-module.log + Read_from_Head True + Rotate_Wait 30 + Skip_Long_Lines On + Tag ops-agent-fluent-bit + storage.type memory + +[INPUT] + Buffer_Chunk_Size 512k + Buffer_Max_Size 2M + DB ${buffers_dir}/ops-agent-health + DB.locking true + Key message + Mem_Buf_Limit 10M + Name tail + Path ${logs_dir}/health-checks.log + Read_from_Head True + Rotate_Wait 30 + Skip_Long_Lines On + Tag ops-agent-health + storage.type memory + +[FILTER] + Match ops-agent-fluent-bit + Name lua + call parser_nest + script b4a0dead382dce7b4fe011d3f59fdb6d.lua + +[FILTER] + Key_Name message + Match ops-agent-fluent-bit + Name parser + Preserve_Key True + Reserve_Data True + Parser ops-agent-fluent-bit.fluent-bit-self-log-regex-parsing + +[FILTER] + Match ops-agent-fluent-bit + Name lua + call parser_merge_record + script 5fc5f42c16c9e1ab8292e3d42f74f3be.lua + +[FILTER] + Match ops-agent-health + Name lua + call parser_nest + script b4a0dead382dce7b4fe011d3f59fdb6d.lua + +[FILTER] + Key_Name message + Match ops-agent-health + Name parser + Reserve_Data True + Parser ops-agent-health.health-checks-json + +[FILTER] + Match ops-agent-health + Name lua + call parser_merge_record + script 5fc5f42c16c9e1ab8292e3d42f74f3be.lua + +[FILTER] + Match ops-agent-health + Name grep + Regex severity INFO|ERROR|WARNING|DEBUG|info|error|warning|debug + +[FILTER] + Match ops-agent-fluent-bit + Name rewrite_tag + Rule message \[error\]\s\[lib\]\sbackend\sfailed ops-agent-health true + +[FILTER] + Name modify + Match ops-agent-health + Condition Key_value_matches message \[error\]\s\[lib\]\sbackend\sfailed + Set code LogPipelineErr + Set message "[Runtime Check] Result: FAIL, Error code: LogPipelineErr, Failure: Ops Agent logging pipeline failed, Solution: Refer to provided documentation link., Resource: https://cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/troubleshoot-find-info" + +[FILTER] + Match ops-agent-fluent-bit + Name rewrite_tag + Rule message \[error\]\s\[parser\]\scannot\sparse ops-agent-health true + +[FILTER] + Name modify + Match ops-agent-health + Condition Key_value_matches message \[error\]\s\[parser\]\scannot\sparse + Set code LogParseErr + Set message "[Runtime Check] Result: WARNING, Error code: LogParseErr, Failure: Ops Agent failed to parse logs, Solution: Refer to provided documentation link., Resource: https://cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/troubleshoot-find-info" + +[FILTER] + Match ops-agent-health + Name lua + call process + script 0f15dbe303dc7122d43443c9a4c31632.lua + +[FILTER] + Match ops-agent-* + Name lua + call process + script 4d6012ff003886818fb9b9285b4af962.lua + +[OUTPUT] + Match_Regex ^(ops-agent-health|ops-agent-fluent-bit)$ + Name stackdriver + Retry_Limit 3 + http_request_key logging.googleapis.com/httpRequest + net.connect_timeout_log_error False + resource gce_instance + stackdriver_agent Google-Cloud-Ops-Agent-Logging/latest (BuildDistro=build_distro;Platform=linux;ShortName=linux_platform;ShortVersion=linux_platform_version) + tls On + tls.verify Off + workers 8 + +[OUTPUT] + Match * + Name prometheus_exporter + host 0.0.0.0 + port 20202 diff --git a/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/fluent_bit_parser.conf b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/fluent_bit_parser.conf new file mode 100644 index 0000000000..3c603780bd --- /dev/null +++ b/confgenerator/testdata/goldens/otlp_exporter_global_config/golden/linux-gpu/fluent_bit_parser.conf @@ -0,0 +1,13 @@ +[PARSER] + Format regex + Name ops-agent-fluent-bit.fluent-bit-self-log-regex-parsing + Regex (?\[[ ]*(?