Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ var fServiceDisplayName = flag.String("service-display-name", "Telegraf Data Col
var fRunAsConsole = flag.Bool("console", false, "run as console application (windows only)")
var fSetEnv = flag.String("setenv", "", "set an env in the configuration file in the format of KEY=VALUE")
var fStartUpErrorFile = flag.String("startup-error-file", "", "file to touch if agent can't start")
var fFeatureGates = flag.String("feature-gates", "",
"comma-delimited list of feature gates to enable/disable (e.g., gate1,-gate2,+gate3)")

var stop chan struct{}

Expand Down Expand Up @@ -391,10 +393,44 @@ func runAgent(ctx context.Context,
for _, uri := range otelConfigs {
e = append(e, "--config="+uri)
}
// Build feature gates argument
featureGates := buildFeatureGates(*fFeatureGates)
if featureGates != "" {
e = append(e, featureGates)
}
cmd.SetArgs(e)
return cmd.Execute()
}

// buildFeatureGates constructs the feature gates argument
func buildFeatureGates(featureGates string) string {
var gates []string

defaultGates := []string{
"receiver.prometheusreceiver.EnableNativeHistograms",
}

// Add default gates
gates = append(gates, defaultGates...)

// Add user-specified gates if provided
if featureGates != "" {
featureGatesList := strings.Split(featureGates, ",")
for _, gate := range featureGatesList {
gate = strings.TrimSpace(gate)
if gate != "" {
gates = append(gates, gate)
}
}
}

if len(gates) == 0 {
return ""
}

return "--feature-gates=" + strings.Join(gates, ",")
}

func getCollectorParams(factories otelcol.Factories, providerSettings otelcol.ConfigProviderSettings, loggingOptions []zap.Option) otelcol.CollectorSettings {
return otelcol.CollectorSettings{
Factories: func() (otelcol.Factories, error) {
Expand Down
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go 1.24.4

replace github.com/influxdata/telegraf => github.com/aws/telegraf v0.10.2-0.20250113150713-a2dfaa4cdf6d

replace collectd.org v0.4.0 => github.com/collectd/go-collectd v0.4.0

// Replace with https://github.com/amazon-contributing/opentelemetry-collector-contrib, there are no requirements for all receivers/processors/exporters
// to be all replaced since there are some changes that will always be from upstream
replace (
Expand Down Expand Up @@ -231,6 +233,11 @@ require (
k8s.io/klog/v2 v2.130.1
)

require (
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.124.1
go.opentelemetry.io/otel v1.35.0
)

require (
cloud.google.com/go/auth v0.15.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.7 // indirect
Expand Down Expand Up @@ -461,7 +468,6 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/sampling v0.124.1 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure v0.124.1 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.124.1 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.124.1 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheusremotewrite v0.124.1 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin v0.124.1 // indirect
github.com/opencontainers/cgroups v0.0.1 // indirect
Expand Down Expand Up @@ -565,7 +571,6 @@ require (
go.opentelemetry.io/contrib/otelconf v0.15.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.35.0 // indirect
go.opentelemetry.io/contrib/zpages v0.60.0 // indirect
go.opentelemetry.io/otel v1.35.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.11.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.11.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.35.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
code.cloudfoundry.org/clock v1.0.0 h1:kFXWQM4bxYvdBw2X8BbBeXwQNgfoWv1vqAk2ZZyBN2o=
code.cloudfoundry.org/clock v1.0.0/go.mod h1:QD9Lzhd/ux6eNQVUDVRJX/RKTigpewimNYBi7ivZKY8=
collectd.org v0.4.0 h1:nWNldfMqg7EVWAevG8oyOVsS9r/UHRG3LZRf6MdQho0=
collectd.org v0.4.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE=
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
Expand Down Expand Up @@ -409,6 +407,8 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42 h1:Om6kYQYDUk5wWbT0t0q6pvyM49i9XZAv9dDrkDA7gjk=
github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
github.com/collectd/go-collectd v0.4.0 h1:0u1GXChSSlMw+riTADhcWwTjugckVWxjQHJi7Zj2Xe4=
github.com/collectd/go-collectd v0.4.0/go.mod h1:xQe/Em/Q9IrN5ifWOvK5ZP2vMIB4KlsIA550yYzhkpY=
github.com/containerd/cgroups/v3 v3.0.3 h1:S5ByHZ/h9PMe5IOQoN7E+nMc2UcLEM/V48DGDJ9kip0=
github.com/containerd/cgroups/v3 v3.0.3/go.mod h1:8HBe7V3aWGLFPd/k03swSIsGjZhHI2WzJmticMgVuz0=
github.com/containerd/containerd/api v1.8.0 h1:hVTNJKR8fMc/2Tiw60ZRijntNMd1U+JVMyTRdsD2bS0=
Expand Down
1 change: 1 addition & 0 deletions plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
//Enable cloudwatch-agent process plugins
_ "github.com/aws/amazon-cloudwatch-agent/plugins/processors/ecsdecorator"
_ "github.com/aws/amazon-cloudwatch-agent/plugins/processors/k8sdecorator"
_ "github.com/aws/amazon-cloudwatch-agent/plugins/processors/prometheusadapter"

// Enabled cloudwatch-agent input plugins
_ "github.com/aws/amazon-cloudwatch-agent/plugins/inputs/logfile"
Expand Down
17 changes: 17 additions & 0 deletions plugins/processors/prometheusadapter/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package prometheusadapter

import (
"go.opentelemetry.io/collector/component"
)

type Config struct{}

// Verify Config implements Processor interface.
var _ component.Config = (*Config)(nil)

func (cfg *Config) Validate() error {
return nil
}
18 changes: 18 additions & 0 deletions plugins/processors/prometheusadapter/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package prometheusadapter

import (
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/confmap"
)

func TestUnmarshalDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NoError(t, confmap.New().Unmarshal(cfg))
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
}
56 changes: 56 additions & 0 deletions plugins/processors/prometheusadapter/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package prometheusadapter

import (
"context"
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"
)

const (
stability = component.StabilityLevelBeta
)

var (
TypeStr, _ = component.NewType("prometheusadapter")
processorCapabilities = consumer.Capabilities{MutatesData: true}
)

func NewFactory() processor.Factory {
return processor.NewFactory(
TypeStr,
createDefaultConfig,
processor.WithMetrics(createMetricsProcessor, stability))
}

func createDefaultConfig() component.Config {
return &Config{}
}

func createMetricsProcessor(
ctx context.Context,
set processor.Settings,
cfg component.Config,
nextConsumer consumer.Metrics,
) (processor.Metrics, error) {
processorConfig, ok := cfg.(*Config)
if !ok {
return nil, fmt.Errorf("configuration parsing error")
}

metricsProcessor := newPrometheusAdapterProcessor(processorConfig, set.Logger)

return processorhelper.NewMetrics(
ctx,
set,
cfg,
nextConsumer,
metricsProcessor.processMetrics,
processorhelper.WithCapabilities(processorCapabilities))
}
45 changes: 45 additions & 0 deletions plugins/processors/prometheusadapter/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package prometheusadapter

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/pipeline"
"go.opentelemetry.io/collector/processor/processortest"
)

func TestCreateDefaultConfig(t *testing.T) {
factory := NewFactory()
require.NotNil(t, factory)

cfg := factory.CreateDefaultConfig()
assert.NotNil(t, cfg, "failed to create default config")
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
}

func TestCreateProcessor(t *testing.T) {
factory := NewFactory()
require.NotNil(t, factory)

cfg := factory.CreateDefaultConfig()
setting := processortest.NewNopSettings(TypeStr)

tProcessor, err := factory.CreateTraces(context.Background(), setting, cfg, consumertest.NewNop())
assert.Equal(t, err, pipeline.ErrSignalNotSupported)
assert.Nil(t, tProcessor)

mProcessor, err := factory.CreateMetrics(context.Background(), setting, cfg, consumertest.NewNop())
assert.NoError(t, err)
assert.NotNil(t, mProcessor)

lProcessor, err := factory.CreateLogs(context.Background(), setting, cfg, consumertest.NewNop())
assert.Equal(t, err, pipeline.ErrSignalNotSupported)
assert.Nil(t, lProcessor)
}
Loading