Skip to content

Commit

Permalink
Add back ecs and kubernetes merge rules. (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefchien authored Jun 1, 2023
1 parent 8eef1a0 commit 614759b
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 4 deletions.
4 changes: 4 additions & 0 deletions translator/config/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func GetJsonSchema() string {
return schema
}

func OverwriteSchema(newSchema string) {
schema = newSchema
}

// Translate Sample:
// (root).agent.metrics_collection_interval -> /agent/metrics_collection_interval
// (root).metrics.metrics_collected.cpu.resources.1 -> /metrics/metrics_collected/cpu/resources/1
Expand Down
12 changes: 9 additions & 3 deletions translator/config/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ import (

func TestGetJsonSchema(t *testing.T) {
jsonFile, err := os.ReadFile("./schema.json")
if err != nil {
require.NoError(t, err)
}
require.NoError(t, err)
assert.Equal(t, string(jsonFile), GetJsonSchema(), "Json schema is inconsistent")
}

func TestOverwriteSchema(t *testing.T) {
originalSchema := GetJsonSchema()
newSchema := "new schema"
OverwriteSchema(newSchema)
assert.NotEqual(t, originalSchema, GetJsonSchema())
assert.Equal(t, newSchema, GetJsonSchema())
}

func TestGetFormattedPath(t *testing.T) {
assert.Equal(t, "/metrics/metrics_collected/cpu/resources/1", GetFormattedPath("(root).metrics.metrics_collected.cpu.resources.1"))
assert.Equal(t, "/metrics/metrics_collected/cpu", GetFormattedPath("(root).metrics.metrics_collected.cpu"))
Expand Down
1 change: 0 additions & 1 deletion translator/jsonconfig/mergeJsonConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ var testDataList = []TestData{
{"MixedSection_CompleteLinuxConfig", 3, 3, false},
{"MixedSection_CompleteWindowsConfig", 4, 4, false},
{"CustomizedTest_PutWhateverYouWantToQuicklyTestHere", 5, 2, false},

{"FailureTest_AgentConflicts", 6, 2, true},
{"FailureTest_MetricsConflicts", 7, 2, true},
{"FailureTest_LogsConflicts", 8, 2, true},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"metrics_collected": {
"kubernetes": {
"cluster_name": "TestCluster"
},
"ecs": {
"metrics_collection_interval": 30
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions translator/jsonconfig/sampleJsonConfig/test_5/input_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"metrics_collected": {
"kubernetes": {
"cluster_name": "TestCluster"
},
"ecs": {
}
}
},
Expand Down
7 changes: 7 additions & 0 deletions translator/jsonconfig/sampleJsonConfig/test_5/input_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
}
]
}
},
"metrics_collected": {
"kubernetes": {
},
"ecs": {
"metrics_collection_interval": 30
}
}
},
"metrics": {
Expand Down
2 changes: 2 additions & 0 deletions translator/registerrules/register_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
_ "github.com/aws/private-amazon-cloudwatch-agent-staging/translator/translate/logs/logs_collected/files/collect_list"
_ "github.com/aws/private-amazon-cloudwatch-agent-staging/translator/translate/logs/logs_collected/windows_events"
_ "github.com/aws/private-amazon-cloudwatch-agent-staging/translator/translate/logs/logs_collected/windows_events/collect_list"
_ "github.com/aws/private-amazon-cloudwatch-agent-staging/translator/translate/logs/metrics_collected/ecs"
_ "github.com/aws/private-amazon-cloudwatch-agent-staging/translator/translate/logs/metrics_collected/kubernetes"
_ "github.com/aws/private-amazon-cloudwatch-agent-staging/translator/translate/logs/metrics_collected/prometheus"
_ "github.com/aws/private-amazon-cloudwatch-agent-staging/translator/translate/logs/metrics_collected/prometheus/ecsservicediscovery"
_ "github.com/aws/private-amazon-cloudwatch-agent-staging/translator/translate/logs/metrics_collected/prometheus/ecsservicediscovery/dockerlabel"
Expand Down
31 changes: 31 additions & 0 deletions translator/translate/logs/metrics_collected/ecs/ecs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package ecs

import (
"github.com/aws/private-amazon-cloudwatch-agent-staging/translator/jsonconfig/mergeJsonRule"
"github.com/aws/private-amazon-cloudwatch-agent-staging/translator/jsonconfig/mergeJsonUtil"
parent "github.com/aws/private-amazon-cloudwatch-agent-staging/translator/translate/logs/metrics_collected"
)

const SectionKey = "ecs"

type ECS struct {
}

func GetCurPath() string {
curPath := parent.GetCurPath() + SectionKey + "/"
return curPath
}

var MergeRuleMap = map[string]mergeJsonRule.MergeRule{}

func (e *ECS) Merge(source map[string]interface{}, result map[string]interface{}) {
mergeJsonUtil.MergeMap(source, result, SectionKey, MergeRuleMap, GetCurPath())
}

func init() {
e := new(ECS)
parent.MergeRuleMap[SectionKey] = e
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package kubernetes

import (
"github.com/aws/private-amazon-cloudwatch-agent-staging/translator/jsonconfig/mergeJsonRule"
"github.com/aws/private-amazon-cloudwatch-agent-staging/translator/jsonconfig/mergeJsonUtil"
parent "github.com/aws/private-amazon-cloudwatch-agent-staging/translator/translate/logs/metrics_collected"
)

const SectionKey = "kubernetes"

type Kubernetes struct {
}

func GetCurPath() string {
curPath := parent.GetCurPath() + SectionKey + "/"
return curPath
}

var MergeRuleMap = map[string]mergeJsonRule.MergeRule{}

func (k *Kubernetes) Merge(source map[string]interface{}, result map[string]interface{}) {
mergeJsonUtil.MergeMap(source, result, SectionKey, MergeRuleMap, GetCurPath())
}

func init() {
k := new(Kubernetes)
parent.MergeRuleMap[SectionKey] = k
}

0 comments on commit 614759b

Please sign in to comment.