Skip to content

Commit

Permalink
fix(opamp): multiple fixes for opamp (#1705)
Browse files Browse the repository at this point in the history
* Uses new sumologicextension from our fork of
opentelemetry-collector-contrib. This is necessary for now as the
changes are not available on upstream and upstream is using a newer
version of the collector.

* Updated the OpAmp agent to output the filename (includes the source
template ID) when processing source templates.

* Added the `file_storage` and `health_check` extensions to the
generated `sumologic-remote.yaml` config when using otelcol-config.

Signed-off-by: Justin Kolberg <[email protected]>
  • Loading branch information
amdprophet authored Nov 16, 2024
1 parent 6fa181e commit 74a9060
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion otelcolbuilder/.otelcol-builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ providers:
- gomod: go.opentelemetry.io/collector/confmap/provider/httpsprovider v0.108.0
- gomod: go.opentelemetry.io/collector/confmap/provider/yamlprovider v0.108.0


excludes:
- github.com/knadh/koanf v1.5.0

Expand All @@ -243,5 +242,6 @@ replaces:
# version which gets then translated into a replace in go.mod file.
# This does not replace the version that sumologicexporter depends on.
- github.com/SumoLogic/sumologic-otel-collector/pkg/extension/opampextension => ../../pkg/extension/opampextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/sumologicextension v0.108.0 => github.com/SumoLogic/opentelemetry-collector-contrib/extension/sumologicextension bf012a09b9651cddda4a907ad4ff17834a0b81ef
- github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/globprovider => ../../pkg/configprovider/globprovider
- github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/opampprovider => ../../pkg/configprovider/opampprovider
24 changes: 15 additions & 9 deletions pkg/extension/opampextension/opamp_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,17 @@ func (o *opampAgent) saveEffectiveConfig(dir string) error {
}
}

o.logger.Debug("Loading Component Factories...")
factories, err := Components()
if err != nil {
return fmt.Errorf("cannot get the list of factories: %v", err)
}

for k, v := range o.effectiveConfig {
logger := o.logger.With(
zap.String("filename", k),
)

p := filepath.Join(dir, k)

// OpenFile the same way os.Create does it, but with 0600 perms
Expand All @@ -420,12 +430,8 @@ func (o *opampAgent) saveEffectiveConfig(dir string) error {
if err != nil {
return err
}
o.logger.Debug("Loading Component Factories...")
factories, err := Components()
if err != nil {
return fmt.Errorf("cannot get the list of factories: %v", err)
}
o.logger.Info("Loading Configuration to Validate...")

logger.Info("Loading Configuration to Validate...")

_, errValidate := loadConfigAndValidateWithSettings(factories, otelcol.ConfigProviderSettings{
ResolverSettings: confmap.ResolverSettings{
Expand All @@ -438,10 +444,10 @@ func (o *opampAgent) saveEffectiveConfig(dir string) error {
},
})
if errValidate != nil {
o.logger.Error("Validation Failed... %v", zap.Error(errValidate))
return fmt.Errorf("cannot validate config named %v", errValidate)
logger.Error("Validation Failed", zap.Error(errValidate))
return fmt.Errorf("cannot validate config: %v", errValidate)
}
o.logger.Info("Config Validation Successful...")
logger.Info("Config Validation Successful")
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/extension/opampextension/opamp_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

const (
errMsgRemoteConfigNotAccepted = "OpAMP agent does not accept remote configuration"
errMsgInvalidConfigName = "cannot validate config named " +
errMsgInvalidConfigName = "cannot validate config: " +
"service::pipelines::logs/localfilesource/0aa79379-c764-4d3d-9d66-03f6df029a07: " +
"references processor \"batch\" which is not configured"
errMsgInvalidInterval = "'max_elapsed_time' must be non-negative"
Expand Down
12 changes: 12 additions & 0 deletions pkg/tools/otelcol-config/remote_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ func makeNewSumologicRemoteYAML(ctx *actionContext, conf ConfDir) error {

var sumoRemoteConfig = map[string]any{
"extensions": map[string]any{
"file_storage": map[string]any{
"compaction": map[string]any{
"directory": "/var/lib/otelcol-sumo/file_storage",
"on_rebound": true,
},
"directory": "/var/lib/otelcol-sumo/file_storage",
},
"health_check": map[string]any{
"endpoint": "localhost:13133",
},
"opamp": map[string]any{
"remote_configuration_directory": remoteConfigDir,
"endpoint": DefaultSumoLogicOpampEndpoint,
Expand All @@ -70,6 +80,8 @@ func makeNewSumologicRemoteYAML(ctx *actionContext, conf ConfDir) error {
"service": map[string]any{
"extensions": []string{
"sumologic",
"health_check",
"file_storage",
"opamp",
},
"pipelines": map[string]any{
Expand Down
9 changes: 9 additions & 0 deletions pkg/tools/otelcol-config/remote_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ func TestEnableRemoteControlConfigFileNotPresent(t *testing.T) {
const expData = `exporters:
nop: {}
extensions:
file_storage:
compaction:
directory: /var/lib/otelcol-sumo/file_storage
on_rebound: true
directory: /var/lib/otelcol-sumo/file_storage
health_check:
endpoint: localhost:13133
opamp:
endpoint: wss://opamp-events.sumologic.com/v1/opamp
remote_configuration_directory: /etc/otelcol-sumo/opamp.d
Expand All @@ -90,6 +97,8 @@ receivers:
service:
extensions:
- sumologic
- health_check
- file_storage
- opamp
pipelines:
logs/default:
Expand Down

0 comments on commit 74a9060

Please sign in to comment.