Skip to content

Commit

Permalink
Feature jmx metrics (#1131)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeffrey Chien <[email protected]>
Co-authored-by: Yared <[email protected]>
Co-authored-by: Kaushik Surya <[email protected]>
  • Loading branch information
4 people authored May 29, 2024
1 parent 6d69782 commit f32323d
Show file tree
Hide file tree
Showing 61 changed files with 2,766 additions and 275 deletions.
1 change: 1 addition & 0 deletions .github/workflows/PR-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- main*
- feature*
types:
- opened
- synchronize
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ec2-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
if: steps.cache_if_success.outputs.cache-hit != 'true'
uses: nick-fields/retry@v2
with:
max_attempts: 3
max_attempts: 2
timeout_minutes: 60
retry_wait_seconds: 5
command: |
Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
if: ${{ cancelled() || failure() }}
uses: nick-fields/retry@v2
with:
max_attempts: 3
max_attempts: 2
timeout_minutes: 8
retry_wait_seconds: 5
command: cd ${{ inputs.test_dir }} && terraform destroy -var="region=${{ inputs.region }}" -var="ami=${{ matrix.arrays.ami }}" --auto-approve
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ build-for-docker-amd64:
$(LINUX_AMD64_BUILD)/amazon-cloudwatch-agent github.com/aws/amazon-cloudwatch-agent/cmd/amazon-cloudwatch-agent
$(LINUX_AMD64_BUILD)/start-amazon-cloudwatch-agent github.com/aws/amazon-cloudwatch-agent/cmd/start-amazon-cloudwatch-agent
$(LINUX_AMD64_BUILD)/config-translator github.com/aws/amazon-cloudwatch-agent/cmd/config-translator
cp $(BASE_SPACE)/packaging/opentelemetry-jmx-metrics.jar $(BUILD_SPACE)/bin/linux_amd64/opentelemetry-jmx-metrics.jar

build-for-docker-windows-amd64:
$(WIN_BUILD)/amazon-cloudwatch-agent.exe github.com/aws/amazon-cloudwatch-agent/cmd/amazon-cloudwatch-agent
Expand All @@ -119,6 +120,7 @@ build-for-docker-arm64:
$(LINUX_ARM64_BUILD)/amazon-cloudwatch-agent github.com/aws/amazon-cloudwatch-agent/cmd/amazon-cloudwatch-agent
$(LINUX_ARM64_BUILD)/start-amazon-cloudwatch-agent github.com/aws/amazon-cloudwatch-agent/cmd/start-amazon-cloudwatch-agent
$(LINUX_ARM64_BUILD)/config-translator github.com/aws/amazon-cloudwatch-agent/cmd/config-translator
cp $(BASE_SPACE)/packaging/opentelemetry-jmx-metrics.jar $(BUILD_SPACE)/bin/linux_arm64/opentelemetry-jmx-metrics.jar

docker-build: build-for-docker-amd64 build-for-docker-arm64
docker buildx build --platform linux/amd64,linux/arm64 . -f amazon-cloudwatch-container-insights/cloudwatch-agent-dockerfile/localbin/Dockerfile -t $(IMAGE)
Expand Down Expand Up @@ -216,6 +218,7 @@ package-prepare-rpm:
cp $(BASE_SPACE)/packaging/linux/amazon-cloudwatch-agent.conf $(BUILD_SPACE)/private/linux/amd64/rpm/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/packaging/linux/amazon-cloudwatch-agent.spec $(BUILD_SPACE)/private/linux/amd64/rpm/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/translator/config/schema.json $(BUILD_SPACE)/private/linux/amd64/rpm/amazon-cloudwatch-agent-pre-pkg/amazon-cloudwatch-agent-schema.json
cp $(BASE_SPACE)/packaging/opentelemetry-jmx-metrics.jar $(BUILD_SPACE)/private/linux/amd64/rpm/amazon-cloudwatch-agent-pre-pkg/opentelemetry-jmx-metrics.jar

# arm64 rpm
mkdir -p $(BUILD_SPACE)/private/linux/arm64/rpm/amazon-cloudwatch-agent-pre-pkg
Expand All @@ -229,6 +232,7 @@ package-prepare-rpm:
cp $(BASE_SPACE)/packaging/linux/amazon-cloudwatch-agent.conf $(BUILD_SPACE)/private/linux/arm64/rpm/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/packaging/linux/amazon-cloudwatch-agent.spec $(BUILD_SPACE)/private/linux/arm64/rpm/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/translator/config/schema.json $(BUILD_SPACE)/private/linux/arm64/rpm/amazon-cloudwatch-agent-pre-pkg/amazon-cloudwatch-agent-schema.json
cp $(BASE_SPACE)/packaging/opentelemetry-jmx-metrics.jar $(BUILD_SPACE)/private/linux/arm64/rpm/amazon-cloudwatch-agent-pre-pkg/opentelemetry-jmx-metrics.jar
cp -rf $(BASE_SPACE)/Tools $(BUILD_SPACE)/

package-prepare-deb:
Expand All @@ -243,6 +247,7 @@ package-prepare-deb:
cp $(BASE_SPACE)/cfg/commonconfig/common-config.toml $(BUILD_SPACE)/private/linux/amd64/deb/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/packaging/linux/amazon-cloudwatch-agent.conf $(BUILD_SPACE)/private/linux/amd64/deb/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/translator/config/schema.json $(BUILD_SPACE)/private/linux/amd64/deb/amazon-cloudwatch-agent-pre-pkg/amazon-cloudwatch-agent-schema.json
cp $(BASE_SPACE)/packaging/opentelemetry-jmx-metrics.jar $(BUILD_SPACE)/private/linux/amd64/deb/amazon-cloudwatch-agent-pre-pkg/opentelemetry-jmx-metrics.jar

# arm64 deb
mkdir -p $(BUILD_SPACE)/private/linux/arm64/deb/amazon-cloudwatch-agent-pre-pkg
Expand All @@ -255,6 +260,7 @@ package-prepare-deb:
cp $(BASE_SPACE)/cfg/commonconfig/common-config.toml $(BUILD_SPACE)/private/linux/arm64/deb/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/packaging/linux/amazon-cloudwatch-agent.conf $(BUILD_SPACE)/private/linux/arm64/deb/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/translator/config/schema.json $(BUILD_SPACE)/private/linux/arm64/deb/amazon-cloudwatch-agent-pre-pkg/amazon-cloudwatch-agent-schema.json
cp $(BASE_SPACE)/packaging/opentelemetry-jmx-metrics.jar $(BUILD_SPACE)/private/linux/arm64/deb/amazon-cloudwatch-agent-pre-pkg/opentelemetry-jmx-metrics.jar

cp -rf $(BASE_SPACE)/Tools $(BUILD_SPACE)/
cp -rf $(BASE_SPACE)/packaging $(BUILD_SPACE)/
Expand All @@ -271,6 +277,7 @@ package-prepare-win-zip:
cp ${BASE_SPACE}/packaging/windows/amazon-cloudwatch-agent-ctl.ps1 $(BUILD_SPACE)/private/windows/amd64/zip/amazon-cloudwatch-agent-pre-pkg/
cp ${BASE_SPACE}/packaging/windows/install.ps1 $(BUILD_SPACE)/private/windows/amd64/zip/amazon-cloudwatch-agent-pre-pkg/
cp ${BASE_SPACE}/packaging/windows/uninstall.ps1 $(BUILD_SPACE)/private/windows/amd64/zip/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/packaging/opentelemetry-jmx-metrics.jar $(BUILD_SPACE)/private/windows/amd64/zip/amazon-cloudwatch-agent-pre-pkg/opentelemetry-jmx-metrics.jar
cp -rf $(BASE_SPACE)/Tools $(BUILD_SPACE)/

package-prepare-darwin-tar:
Expand All @@ -284,6 +291,7 @@ package-prepare-darwin-tar:
cp $(BASE_SPACE)/translator/config/schema.json $(BUILD_SPACE)/private/darwin/amd64/tar/amazon-cloudwatch-agent-pre-pkg/amazon-cloudwatch-agent-schema.json
cp $(BASE_SPACE)/packaging/darwin/amazon-cloudwatch-agent-ctl $(BUILD_SPACE)/private/darwin/amd64/tar/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/packaging/darwin/com.amazon.cloudwatch.agent.plist $(BUILD_SPACE)/private/darwin/amd64/tar/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/packaging/opentelemetry-jmx-metrics.jar $(BUILD_SPACE)/private/darwin/amd64/tar/amazon-cloudwatch-agent-pre-pkg/opentelemetry-jmx-metrics.jar

# arm64 darwin
mkdir -p $(BUILD_SPACE)/private/darwin/arm64/tar/amazon-cloudwatch-agent-pre-pkg
Expand All @@ -295,6 +303,7 @@ package-prepare-darwin-tar:
cp $(BASE_SPACE)/translator/config/schema.json $(BUILD_SPACE)/private/darwin/arm64/tar/amazon-cloudwatch-agent-pre-pkg/amazon-cloudwatch-agent-schema.json
cp $(BASE_SPACE)/packaging/darwin/amazon-cloudwatch-agent-ctl $(BUILD_SPACE)/private/darwin/arm64/tar/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/packaging/darwin/com.amazon.cloudwatch.agent.plist $(BUILD_SPACE)/private/darwin/arm64/tar/amazon-cloudwatch-agent-pre-pkg/
cp $(BASE_SPACE)/packaging/opentelemetry-jmx-metrics.jar $(BUILD_SPACE)/private/darwin/arm64/tar/amazon-cloudwatch-agent-pre-pkg/opentelemetry-jmx-metrics.jar

cp -rf $(BASE_SPACE)/Tools $(BUILD_SPACE)/

Expand Down
1 change: 1 addition & 0 deletions Tools/src/create_darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ cp ${PREPKGPATH}/config-translator ${BUILD_ROOT}${MACHINE_ROOT}bin/
cp ${PREPKGPATH}/config-downloader ${BUILD_ROOT}${MACHINE_ROOT}bin/
cp ${PREPKGPATH}/amazon-cloudwatch-agent-config-wizard ${BUILD_ROOT}${MACHINE_ROOT}bin/
cp ${PREPKGPATH}/start-amazon-cloudwatch-agent ${BUILD_ROOT}${MACHINE_ROOT}bin/
cp ${PREPKGPATH}/opentelemetry-jmx-metrics.jar ${BUILD_ROOT}${MACHINE_ROOT}bin/
cp ${PREPKGPATH}/common-config.toml ${BUILD_ROOT}${MACHINE_ROOT}etc/
cp ${PREPKGPATH}/amazon-cloudwatch-agent-schema.json ${BUILD_ROOT}${MACHINE_ROOT}doc/
cp ${PREPKGPATH}/com.amazon.cloudwatch.agent.plist ${BUILD_ROOT}/Library/LaunchDaemons/
Expand Down
1 change: 1 addition & 0 deletions Tools/src/create_deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cp ${PREPKGPATH}/config-translator ${BUILD_ROOT}/opt/aws/amazon-cloudwatch-agent
cp ${PREPKGPATH}/config-downloader ${BUILD_ROOT}/opt/aws/amazon-cloudwatch-agent/bin/
cp ${PREPKGPATH}/amazon-cloudwatch-agent-config-wizard ${BUILD_ROOT}/opt/aws/amazon-cloudwatch-agent/bin/
cp ${PREPKGPATH}/start-amazon-cloudwatch-agent ${BUILD_ROOT}/opt/aws/amazon-cloudwatch-agent/bin/
cp ${PREPKGPATH}/opentelemetry-jmx-metrics.jar ${BUILD_ROOT}/opt/aws/amazon-cloudwatch-agent/bin/
cp ${PREPKGPATH}/common-config.toml ${BUILD_ROOT}/opt/aws/amazon-cloudwatch-agent/etc/
cp ${PREPKGPATH}/amazon-cloudwatch-agent.conf ${BUILD_ROOT}/etc/init/
cp ${PREPKGPATH}/amazon-cloudwatch-agent-schema.json ${BUILD_ROOT}/opt/aws/amazon-cloudwatch-agent/doc/
Expand Down
1 change: 1 addition & 0 deletions Tools/src/create_rpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ cp ${PREPKGPATH}/config-translator ${BUILD_ROOT}/SOURCES/opt/aws/amazon-cloudwat
cp ${PREPKGPATH}/config-downloader ${BUILD_ROOT}/SOURCES/opt/aws/amazon-cloudwatch-agent/bin/
cp ${PREPKGPATH}/amazon-cloudwatch-agent-config-wizard ${BUILD_ROOT}/SOURCES/opt/aws/amazon-cloudwatch-agent/bin/
cp ${PREPKGPATH}/start-amazon-cloudwatch-agent ${BUILD_ROOT}/SOURCES/opt/aws/amazon-cloudwatch-agent/bin/
cp ${PREPKGPATH}/opentelemetry-jmx-metrics.jar ${BUILD_ROOT}/SOURCES/opt/aws/amazon-cloudwatch-agent/bin/
cp ${PREPKGPATH}/common-config.toml ${BUILD_ROOT}/SOURCES/opt/aws/amazon-cloudwatch-agent/etc/
cp ${PREPKGPATH}/amazon-cloudwatch-agent.conf ${BUILD_ROOT}/SOURCES/etc/init/amazon-cloudwatch-agent.conf
cp ${PREPKGPATH}/amazon-cloudwatch-agent-schema.json ${BUILD_ROOT}/SOURCES/opt/aws/amazon-cloudwatch-agent/doc/
Expand Down
1 change: 1 addition & 0 deletions Tools/src/create_win.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ cp ${PREPKGPATH}/amazon-cloudwatch-agent-config-wizard.exe ${BUILD_ROOT}/amazon-
cp ${PREPKGPATH}/start-amazon-cloudwatch-agent.exe ${BUILD_ROOT}/amazon-cloudwatch-agent/
cp ${PREPKGPATH}/common-config.toml ${BUILD_ROOT}/amazon-cloudwatch-agent/
cp ${PREPKGPATH}/amazon-cloudwatch-agent-schema.json ${BUILD_ROOT}/amazon-cloudwatch-agent/
cp ${PREPKGPATH}/opentelemetry-jmx-metrics.jar ${BUILD_ROOT}/amazon-cloudwatch-agent/

echo "Constructing the zip package"

Expand Down
8 changes: 8 additions & 0 deletions cmd/config-translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ func TestTracesConfig(t *testing.T) {
checkIfSchemaValidateAsExpected(t, "../../translator/config/sampleSchema/invalidTrace.json", false, expectedErrorMap)
}

func TestJMXConfig(t *testing.T) {
checkIfSchemaValidateAsExpected(t, "../../translator/config/sampleSchema/validJMX.json", true, map[string]int{})
expectedErrorMap := map[string]int{}
expectedErrorMap["number_one_of"] = 1
expectedErrorMap["required"] = 1
checkIfSchemaValidateAsExpected(t, "../../translator/config/sampleSchema/invalidJMX.json", false, expectedErrorMap)
}

func TestLogFilesConfig(t *testing.T) {
checkIfSchemaValidateAsExpected(t, "../../translator/config/sampleSchema/validLogFiles.json", true, map[string]int{})
expectedErrorMap := map[string]int{}
Expand Down
10 changes: 10 additions & 0 deletions extension/agenthealth/handler/useragent/useragent.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/google/uuid"
telegraf "github.com/influxdata/telegraf/config"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jmxreceiver"
"go.opentelemetry.io/collector/otelcol"
"go.uber.org/atomic"
"golang.org/x/exp/maps"
Expand All @@ -22,6 +23,7 @@ import (
"github.com/aws/amazon-cloudwatch-agent/internal/util/collections"
"github.com/aws/amazon-cloudwatch-agent/internal/version"
"github.com/aws/amazon-cloudwatch-agent/receiver/adapter"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common"
)

const (
Expand Down Expand Up @@ -81,6 +83,14 @@ func (ua *userAgent) SetComponents(otelCfg *otelcol.Config, telegrafCfg *telegra
// trim the adapter prefix from adapted Telegraf plugins
name := strings.TrimPrefix(receiver.Type().String(), adapter.TelegrafPrefix)
ua.inputs.Add(name)
if name == common.JmxKey {
cfg := otelCfg.Receivers[receiver].(*jmxreceiver.Config)
targetSystems := strings.Split(cfg.TargetSystem, ",")
for _, system := range targetSystems {
targetSystem := name + "-" + system
ua.inputs.Add(targetSystem)
}
}
}
for _, processor := range pipeline.Processors {
ua.processors.Add(processor.Type().String())
Expand Down
45 changes: 45 additions & 0 deletions extension/agenthealth/handler/useragent/useragent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
telegraf "github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/models"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jmxreceiver"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/otelcol"
Expand Down Expand Up @@ -138,6 +139,50 @@ func TestEmf(t *testing.T) {
assert.Equal(t, "outputs:(application_signals awsemf)", ua.outputsStr.Load())
}

func TestJmx(t *testing.T) {
jmx := "jmx"
jmxOther := "jmxOther"
nopType, _ := component.NewType("nop")
jmxType, _ := component.NewType(jmx)
pipelineType, _ := component.NewType("pipeline")
pipelineTypeOther, _ := component.NewType("pipelineOther")
pls := make(pipelines.Config)
pls[component.NewID(pipelineType)] = &pipelines.PipelineConfig{
Receivers: []component.ID{
component.NewIDWithName(jmxType, jmx),
},
Exporters: []component.ID{
component.NewID(nopType),
},
}
pls[component.NewID(pipelineTypeOther)] = &pipelines.PipelineConfig{
Receivers: []component.ID{
component.NewIDWithName(jmxType, jmxOther),
},
Exporters: []component.ID{
component.NewID(nopType),
},
}
otelCfg := &otelcol.Config{
Service: service.Config{
Pipelines: pls,
},
Receivers: map[component.ID]component.Config{
component.NewIDWithName(jmxType, jmx): &jmxreceiver.Config{TargetSystem: "jvm,tomcat"},
component.NewIDWithName(jmxType, jmxOther): &jmxreceiver.Config{TargetSystem: "jvm,kafka"},
},
}
ua := newUserAgent()
ua.SetComponents(otelCfg, &telegraf.Config{})
assert.Len(t, ua.inputs, 5)
assert.Len(t, ua.processors, 0)
assert.Len(t, ua.outputs, 1)

assert.Equal(t, "inputs:(jmx jmx-jvm jmx-kafka jmx-tomcat run_as_user)", ua.inputsStr.Load())
assert.Equal(t, "", ua.processorsStr.Load())
assert.Equal(t, "outputs:(nop)", ua.outputsStr.Load())
}

func TestSingleton(t *testing.T) {
assert.Equal(t, Get().(*userAgent).id, Get().(*userAgent).id)
}
Expand Down
Loading

0 comments on commit f32323d

Please sign in to comment.