Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop extra prometheus metadata metrics for container insights #1555

Merged
merged 9 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/exporter/awsemf"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/extension/agenthealth"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/processor/batchprocessor"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/processor/filterprocessor"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/processor/gpu"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/processor/kueue"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/processor/metricstransformprocessor"
Expand Down Expand Up @@ -57,8 +58,13 @@ func (t *translator) Translate(conf *confmap.Conf) (*common.ComponentTranslators
return nil, &common.MissingKeyError{ID: t.ID(), JsonKey: fmt.Sprint(ecsKey, " or ", eksKey)}
}

// create processor map with default batch processor based on pipeline name
processors := common.NewTranslatorMap(batchprocessor.NewTranslatorWithNameAndSection(t.pipelineName, common.LogsKey))
// create processor map with
// - default batch processor
// - filter processor to drop prometheus metadata
processors := common.NewTranslatorMap(
batchprocessor.NewTranslatorWithNameAndSection(t.pipelineName, common.LogsKey),
filterprocessor.NewTranslator(common.WithName(t.pipelineName)),
)
// create exporter map with default emf exporter based on pipeline name
exporters := common.NewTranslatorMap(awsemf.NewTranslatorWithName(t.pipelineName))
// create extensions map based on pipeline name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
metrics:
exclude:
match_type: strict
metric_names:
- up
- scrape_duration_seconds
- scrape_samples_scraped
- scrape_series_added
- scrape_samples_post_metric_relabeling
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const (
//go:embed filter_jmx_config.yaml
var containerInsightsJmxConfig string

//go:embed filter_containerinsights_config.yaml
var containerInsightsConfig string

type translator struct {
common.NameProvider
common.IndexProvider
Expand Down Expand Up @@ -52,14 +55,18 @@ func (t *translator) ID() component.ID {
// Translate creates a processor config based on the fields in the
// Metrics section of the JSON config.
func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) {
if conf == nil || (!conf.IsSet(common.JmxConfigKey) && t.Name() != common.PipelineNameContainerInsightsJmx) {
// also checking for container insights pipeline to add default filtering for prometheus metadata
if conf == nil || (t.Name() != common.PipelineNameContainerInsights && t.Name() != common.PipelineNameContainerInsightsJmx && !conf.IsSet(common.JmxConfigKey)) {
return nil, &common.MissingKeyError{ID: t.ID(), JsonKey: common.JmxConfigKey}
}

cfg := t.factory.CreateDefaultConfig().(*filterprocessor.Config)
if t.Name() == common.PipelineNameContainerInsightsJmx {
return common.GetYamlFileToYamlConfig(cfg, containerInsightsJmxConfig)
}
if t.Name() == common.PipelineNameContainerInsights {
return common.GetYamlFileToYamlConfig(cfg, containerInsightsConfig)
}

jmxMap := common.GetIndexedMap(conf, common.JmxConfigKey, t.Index())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,17 @@ func TestContainerInsightsJmx(t *testing.T) {
assert.True(t, ok)
assert.Equal(t, len(expectedCfg.Metrics.Include.MetricNames), len(actualCfg.Metrics.Include.MetricNames))
}

func TestContainerInsights(t *testing.T) {
transl := NewTranslator(common.WithName(common.PipelineNameContainerInsights)).(*translator)
expectedCfg := transl.factory.CreateDefaultConfig().(*filterprocessor.Config)
c := testutil.GetConf(t, "filter_containerinsights_config.yaml")
require.NoError(t, c.Unmarshal(&expectedCfg))

conf := confmap.NewFromStringMap(testutil.GetJson(t, filepath.Join("testdata", "config.json")))
translatedCfg, err := transl.Translate(conf)
assert.NoError(t, err)
actualCfg, ok := translatedCfg.(*filterprocessor.Config)
assert.True(t, ok)
assert.Equal(t, len(expectedCfg.Metrics.Exclude.MetricNames), len(actualCfg.Metrics.Exclude.MetricNames))
}
Loading