Skip to content

Commit

Permalink
Merge branch 'main' into j_config_merge_override
Browse files Browse the repository at this point in the history
  • Loading branch information
jagan2221 authored Nov 19, 2024
2 parents 165b03a + 74a9060 commit f168cef
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 17 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,6 +242,7 @@ 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
- github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/providerutil => ../../pkg/configprovider/providerutil
4 changes: 4 additions & 0 deletions pkg/extension/opampextension/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/nopexporter"
"go.opentelemetry.io/collector/exporter/otlpexporter"
"go.opentelemetry.io/collector/exporter/nopexporter"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/extension/ballastextension"

Expand All @@ -14,6 +15,7 @@ import (
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/nopreceiver"
"go.opentelemetry.io/collector/receiver/otlpreceiver"
"go.opentelemetry.io/collector/receiver/nopreceiver"
"go.uber.org/multierr"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sumologicexporter"
Expand Down Expand Up @@ -61,6 +63,7 @@ func Components() (
errs = multierr.Append(errs, err)

receivers, err := receiver.MakeFactoryMap(
nopreceiver.NewFactory(),
apachereceiver.NewFactory(),
filelogreceiver.NewFactory(),
hostmetricsreceiver.NewFactory(),
Expand All @@ -82,6 +85,7 @@ func Components() (
errs = multierr.Append(errs, err)

exporters, err := exporter.MakeFactoryMap(
nopexporter.NewFactory(),
otlpexporter.NewFactory(),
sumologicexporter.NewFactory(),
syslogexporter.NewFactory(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/extension/opampextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
go.opentelemetry.io/collector/confmap/provider/fileprovider v0.108.1
go.opentelemetry.io/collector/confmap/provider/yamlprovider v0.108.1
go.opentelemetry.io/collector/exporter v0.108.1
go.opentelemetry.io/collector/exporter/nopexporter v0.108.0
go.opentelemetry.io/collector/exporter/nopexporter v0.108.0
go.opentelemetry.io/collector/exporter/otlpexporter v0.108.0
go.opentelemetry.io/collector/extension v0.108.1
go.opentelemetry.io/collector/extension/ballastextension v0.108.0
Expand All @@ -55,7 +55,7 @@ require (
go.opentelemetry.io/collector/processor/batchprocessor v0.108.0
go.opentelemetry.io/collector/processor/memorylimiterprocessor v0.108.0
go.opentelemetry.io/collector/receiver v0.108.1
go.opentelemetry.io/collector/receiver/nopreceiver v0.108.0
go.opentelemetry.io/collector/receiver/nopreceiver v0.108.0
go.opentelemetry.io/collector/receiver/otlpreceiver v0.108.0
go.opentelemetry.io/collector/semconv v0.108.1
go.uber.org/multierr v1.11.0
Expand Down
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
20 changes: 19 additions & 1 deletion pkg/extension/sumologicextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net/http"
"net/url"
"os"
"regexp"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -798,7 +799,7 @@ func (se *SumologicExtension) updateMetadataWithHTTPClient(ctx context.Context,
Environment: se.conf.CollectorEnvironment,
},
CollectorDetails: api.OpenMetadataCollectorDetails{
RunningVersion: se.buildVersion,
RunningVersion: cleanupBuildVersion(se.buildVersion),
},
NetworkDetails: api.OpenMetadataNetworkDetails{
HostIpAddress: ip,
Expand Down Expand Up @@ -1057,3 +1058,20 @@ func getHostname(logger *zap.Logger) (string, error) {

return os.Hostname()
}

// cleanupBuildVersion adds a leading 'v' and removes the tailing build hash to make sure the
// backend understand the build number. Note that only version strings with the following format will be
// cleaned up. All other version formats will remain the same.
// Cleaned up format: 0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113
func cleanupBuildVersion(version string) string {
pattern := "(^[0-9]+\\.[0-9]+\\.[0-9]+-sumo-[0-9]+)-[0-9a-f]{40}$"
re := regexp.MustCompile(pattern)

sm := re.FindAllStringSubmatch(version, 1)
if len(sm) == 1 {
ver := sm[0][1]
return "v" + ver
}

return version
}
34 changes: 34 additions & 0 deletions pkg/extension/sumologicextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1593,3 +1593,37 @@ func TestUpdateMetadataRequestPayload(t *testing.T) {
err = se.updateMetadataWithHTTPClient(context.TODO(), httpClient)
require.NoError(t, err)
}

func Test_cleanupBuildVersion(t *testing.T) {
type args struct {
version string
}
tests := []struct {
name string
args args
want string
}{
{
name: "with hash",
args: args{version: "0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113"},
want: "v0.108.0-sumo-2",
}, {
name: "already ok",
args: args{version: "v0.108.0-sumo-2"},
want: "v0.108.0-sumo-2",
}, {
name: "non v",
args: args{version: "0.108.0-sumo-2"},
want: "0.108.0-sumo-2",
}, {
name: "nonsense",
args: args{version: "hfiwe-23rhc8eg.fhf"},
want: "hfiwe-23rhc8eg.fhf",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, cleanupBuildVersion(tt.args.version), "cleanupBuildVersion(%v)", tt.args.version)
})
}
}
43 changes: 42 additions & 1 deletion pkg/tools/otelcol-config/remote_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,52 @@ 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{
"enabled": true,
"remote_configuration_directory": remoteConfigDir,
"endpoint": DefaultSumoLogicOpampEndpoint,
},
"sumologic": map[string]any{
"installation_token": "${SUMOLOGIC_INSTALLATION_TOKEN}",
"collector_credentials_directory": "/var/lib/otelcol-sumo/credentials",
},
},
"receivers": map[string]any{
"nop": map[string]any{},
},
"exporters": map[string]any{
"nop": map[string]any{},
},
"service": map[string]any{
"extensions": []string{
"sumologic",
"health_check",
"file_storage",
"opamp",
},
"pipelines": map[string]any{
"metrics/default": map[string]any{
"receivers": []string{"nop"},
"exporters": []string{"nop"},
},
"logs/default": map[string]any{
"receivers": []string{"nop"},
"exporters": []string{"nop"},
},
"traces/default": map[string]any{
"receivers": []string{"nop"},
"exporters": []string{"nop"},
},
},
},
}

Expand Down
39 changes: 37 additions & 2 deletions pkg/tools/otelcol-config/remote_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,46 @@ func TestEnableRemoteControlConfigFileNotPresent(t *testing.T) {
values := &flagValues{
EnableRemoteControl: true,
}
const expData = `extensions:
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:
enabled: true
endpoint: wss://opamp-events.sumologic.com/v1/opamp
remote_configuration_directory: /etc/otelcol-sumo/opamp.d
sumologic:
collector_credentials_directory: /var/lib/otelcol-sumo/credentials
installation_token: ${SUMOLOGIC_INSTALLATION_TOKEN}
receivers:
nop: {}
service:
extensions:
- sumologic
- health_check
- file_storage
- opamp
pipelines:
logs/default:
exporters:
- nop
receivers:
- nop
metrics/default:
exporters:
- nop
receivers:
- nop
traces/default:
exporters:
- nop
receivers:
- nop
`
slrWriter := newTestWriter([]byte(expData))
ctx := &actionContext{
Expand Down

0 comments on commit f168cef

Please sign in to comment.