Skip to content

Commit e25f9cc

Browse files
committed
Merge remote-tracking branch 'origin/main' into add-alma-10-support
2 parents a90e790 + a437da8 commit e25f9cc

90 files changed

Lines changed: 4076 additions & 1428 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test-build-docker.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ jobs:
9191
run: |
9292
mkdir amd64
9393
mkdir arm64
94-
aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.BucketKey }}/linux/amd64/amazon-cloudwatch-agent.deb amd64/amazon-cloudwatch-agent.deb
95-
aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.BucketKey }}/linux/arm64/amazon-cloudwatch-agent.deb arm64/amazon-cloudwatch-agent.deb
94+
aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.BucketKey }}/linux/amd64/amazon-cloudwatch-agent.rpm amd64/amazon-cloudwatch-agent.rpm
95+
aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.BucketKey }}/linux/arm64/amazon-cloudwatch-agent.rpm arm64/amazon-cloudwatch-agent.rpm
9696
9797
- name: Get ECR Repo name
9898
id: repo_name
@@ -106,7 +106,7 @@ jobs:
106106
uses: docker/build-push-action@v6
107107
if: contains(inputs.BucketKey, 'test') == false || steps.cached_container.outputs.cache-hit == false
108108
with:
109-
file: amazon-cloudwatch-container-insights/cloudwatch-agent-dockerfile/localdeb/Dockerfile
109+
file: amazon-cloudwatch-container-insights/cloudwatch-agent-dockerfile/localal2/Dockerfile
110110
context: .
111111
push: true
112112
tags: |
@@ -118,7 +118,7 @@ jobs:
118118
uses: docker/build-push-action@v6
119119
if: contains(inputs.BucketKey, 'test') == false || steps.cached_container.outputs.cache-hit == false
120120
with:
121-
file: amazon-cloudwatch-container-insights/cloudwatch-agent-dockerfile/localdeb/Dockerfile
121+
file: amazon-cloudwatch-container-insights/cloudwatch-agent-dockerfile/localal2/Dockerfile
122122
context: .
123123
push: true
124124
tags: |

README.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -116,34 +116,6 @@ It is using [Semantic versioning](https://semver.org/)
116116
## Distributions
117117
You can download the official release from S3, refer to [link](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/download-cloudwatch-agent-commandline.html)
118118

119-
Nightly s3 release are not production ready and should be used at own risk
120-
1. Download Binaries
121-
1. Linux
122-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/linux_{amd64/arm64}/amazon-cloudwatch-agent
123-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/linux_{amd64/arm64}/amazon-cloudwatch-agent-config-wizard
124-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/linux_{amd64/arm64}/config-downloader
125-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/linux_{amd64/arm64}/config-translator
126-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/linux_{amd64/arm64}/start-amazon-cloudwatch-agent
127-
1. Windows
128-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/windows_amd64/amazon-cloudwatch-agent-config-wizard.exe
129-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/windows_amd64/amazon-cloudwatch-agent.exe
130-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/windows_amd64/config-downloader.exe
131-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/windows_amd64/config-translator.exe
132-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/windows_amd64/start-amazon-cloudwatch-agent.exe
133-
1. Mac
134-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/darwin_amd64/amazon-cloudwatch-agent
135-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/darwin_amd64/amazon-cloudwatch-agent-config-wizard
136-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/darwin_amd64/config-downloader
137-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/darwin_amd64/config-translator
138-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/darwin_amd64/start-amazon-cloudwatch-agent
139-
2. Download Packages
140-
1. Linux
141-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/linux/{amd64/arm64}/amazon-cloudwatch-agent.{deb/rpm}
142-
2. Windows
143-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/windows/amd64/amazon-cloudwatch-agent.zip
144-
3. Mac
145-
* https://amazoncloudwatch-agent.s3.amazonaws.com/nightly-build/latest/darwin/amd64/amazon-cloudwatch-agent.tar.gz
146-
147119
## Usage data
148120
By default, the CloudWatch agent sends health and performance data about itself to CloudWatch whenever it publishes metrics or logs to CloudWatch. This data incurs no costs to you. You can prevent the agent from sending this data by specifying `false` for `usage_data` in the `agent` section of the configuration. If you omit this parameter, the default of true is used and the agent sends the health and performance data. Refer to [link](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html#CloudWatch-Agent-Configuration-File-Agentsection).
149121

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ARG BUILD_IMAGE=public.ecr.aws/amazonlinux/amazonlinux:latest
2+
FROM $BUILD_IMAGE AS build
3+
4+
ARG TARGETARCH
5+
6+
RUN yum update -y && \
7+
yum install -y ca-certificates && \
8+
rm -rf /var/lib/apt/lists/*
9+
10+
COPY ${TARGETARCH}/amazon-cloudwatch-agent.rpm /tmp/amazon-cloudwatch-agent.rpm
11+
12+
# Installing RPM normally will cause %posttrans script to fail as it will try to run the
13+
# ctl script to conditionally restart the agent, but the script will fail since the base image
14+
# doesn't have systemd installed by default. We don't care about this particular functionality
15+
# so we can simply skip the %posttrans step.
16+
RUN rpm -i --noposttrans /tmp/amazon-cloudwatch-agent.rpm && \
17+
rm -rf /tmp/* && \
18+
rm -rf /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard && \
19+
rm -rf /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl && \
20+
rm -rf /opt/aws/amazon-cloudwatch-agent/bin/config-downloader
21+
22+
FROM scratch
23+
24+
# Need to create /tmp or plugin files such as prometheus is missing
25+
# Must use copy because scratch does not contain shell so mkdir won't work
26+
COPY --from=build /tmp /tmp
27+
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-bundle.trust.crt
28+
COPY --from=build /opt/aws/amazon-cloudwatch-agent /opt/aws/amazon-cloudwatch-agent
29+
30+
ENV RUN_IN_CONTAINER="True"
31+
ENTRYPOINT ["/opt/aws/amazon-cloudwatch-agent/bin/start-amazon-cloudwatch-agent"]

cmd/amazon-cloudwatch-agent-config-wizard/wizard.go

Lines changed: 7 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -4,139 +4,18 @@
44
package main
55

66
import (
7-
"bufio"
8-
"flag"
9-
"fmt"
7+
"log"
108
"os"
119

12-
"github.com/aws/amazon-cloudwatch-agent/tool/data"
13-
"github.com/aws/amazon-cloudwatch-agent/tool/processors"
14-
"github.com/aws/amazon-cloudwatch-agent/tool/processors/basicInfo"
15-
"github.com/aws/amazon-cloudwatch-agent/tool/processors/migration/linux"
16-
"github.com/aws/amazon-cloudwatch-agent/tool/processors/migration/windows"
17-
"github.com/aws/amazon-cloudwatch-agent/tool/processors/serialization"
18-
"github.com/aws/amazon-cloudwatch-agent/tool/processors/tracesconfig"
19-
"github.com/aws/amazon-cloudwatch-agent/tool/runtime"
20-
"github.com/aws/amazon-cloudwatch-agent/tool/stdin"
21-
"github.com/aws/amazon-cloudwatch-agent/tool/testutil"
22-
"github.com/aws/amazon-cloudwatch-agent/tool/util"
10+
"github.com/aws/amazon-cloudwatch-agent/tool/cmdwrapper"
11+
"github.com/aws/amazon-cloudwatch-agent/tool/wizard/flags"
2312
)
2413

25-
type IMainProcessor interface {
26-
VerifyProcessor(processor interface{})
27-
}
28-
type MainProcessorStruct struct{}
29-
30-
var MainProcessorGlobal IMainProcessor = &MainProcessorStruct{}
31-
32-
var isNonInteractiveWindowsMigration *bool
33-
34-
var configOutputPath *string
35-
36-
var isNonInteractiveXrayMigration *bool
37-
3814
func main() {
39-
// Parse command line args for non-interactive Windows migration
40-
isNonInteractiveWindowsMigration = flag.Bool("isNonInteractiveWindowsMigration", false,
41-
"If true, it will use command line args to bypass the wizard. Default value is false.")
42-
43-
isNonInteractiveLinuxMigration := flag.Bool("isNonInteractiveLinuxMigration", false,
44-
"If true, it will do the linux config migration. Default value is false.")
45-
46-
tracesOnly := flag.Bool("tracesOnly", false, "If true, only trace configuration will be generated")
47-
useParameterStore := flag.Bool("useParameterStore", false,
48-
"If true, it will use the parameter store for the migrated config storage.")
49-
isNonInteractiveXrayMigration = flag.Bool("nonInteractiveXrayMigration", false, "If true, then this is part of non Interactive xray migration tool.")
50-
configFilePath := flag.String("configFilePath", "",
51-
fmt.Sprintf("The path of the old config file. Default is %s on Windows or %s on Linux", windows.DefaultFilePathWindowsConfiguration, linux.DefaultFilePathLinuxConfiguration))
52-
53-
configOutputPath = flag.String("configOutputPath", "", "Specifies where to write the configuration file generated by the wizard")
54-
parameterStoreName := flag.String("parameterStoreName", "", "The parameter store name. Default is AmazonCloudWatch-windows")
55-
parameterStoreRegion := flag.String("parameterStoreRegion", "", "The parameter store region. Default is us-east-1")
56-
57-
flag.Parse()
15+
log.Printf("Starting config-wizard, this will map back to a call to amazon-cloudwatch-agent")
5816

59-
if *isNonInteractiveWindowsMigration {
60-
addWindowsMigrationInputs(*configFilePath, *parameterStoreName, *parameterStoreRegion, *useParameterStore)
61-
} else if *isNonInteractiveLinuxMigration {
62-
ctx := new(runtime.Context)
63-
config := new(data.Config)
64-
ctx.HasExistingLinuxConfig = true
65-
ctx.ConfigFilePath = *configFilePath
66-
if ctx.ConfigFilePath == "" {
67-
ctx.ConfigFilePath = linux.DefaultFilePathLinuxConfiguration
68-
}
69-
process(ctx, config, linux.Processor, serialization.Processor)
70-
return
71-
} else if *tracesOnly {
72-
ctx := new(runtime.Context)
73-
config := new(data.Config)
74-
ctx.TracesOnly = true
75-
ctx.ConfigOutputPath = *configOutputPath
76-
if *isNonInteractiveXrayMigration {
77-
ctx.NonInteractiveXrayMigration = true
78-
}
79-
process(ctx, config, tracesconfig.Processor, serialization.Processor)
80-
return
81-
}
82-
83-
startProcessing()
84-
}
85-
86-
func init() {
87-
stdin.Scanln = func(a ...interface{}) (n int, err error) {
88-
scanner := bufio.NewScanner(os.Stdin)
89-
scanner.Scan()
90-
if len(a) > 0 {
91-
*a[0].(*string) = scanner.Text()
92-
n = len(*a[0].(*string))
93-
}
94-
err = scanner.Err()
95-
return
96-
}
97-
processors.StartProcessor = basicInfo.Processor
98-
}
99-
100-
func addWindowsMigrationInputs(configFilePath string, parameterStoreName string, parameterStoreRegion string, useParameterStore bool) {
101-
inputChan := testutil.SetUpTestInputStream()
102-
if useParameterStore {
103-
testutil.Type(inputChan, "2", "1", "2", "1", configFilePath, "1", parameterStoreName, parameterStoreRegion, "1")
104-
} else {
105-
testutil.Type(inputChan, "2", "1", "2", "1", configFilePath, "2")
106-
}
107-
}
108-
109-
func process(ctx *runtime.Context, config *data.Config, processors ...processors.Processor) {
110-
for _, processor := range processors {
111-
processor.Process(ctx, config)
112-
}
113-
}
114-
115-
func startProcessing() {
116-
ctx := new(runtime.Context)
117-
config := new(data.Config)
118-
ctx.ConfigOutputPath = *configOutputPath
119-
var processor interface{}
120-
processor = processors.StartProcessor
121-
if *isNonInteractiveWindowsMigration {
122-
ctx.WindowsNonInteractiveMigration = true
123-
}
124-
if *isNonInteractiveXrayMigration {
125-
ctx.NonInteractiveXrayMigration = true
126-
}
127-
for {
128-
if processor == nil {
129-
if util.CurOS() == util.OsTypeWindows && !*isNonInteractiveWindowsMigration {
130-
util.EnterToExit()
131-
}
132-
fmt.Println("Program exits now.")
133-
break
134-
}
135-
MainProcessorGlobal.VerifyProcessor(processor) // For testing purposes
136-
processor.(processors.Processor).Process(ctx, config)
137-
processor = processor.(processors.Processor).NextProcessor(ctx, config)
138-
}
139-
}
17+
fs, wizardFlags := cmdwrapper.CreateFlagSet(flags.Command, flags.WizardFlags)
18+
fs.Parse(os.Args[1:]) // Skip program name only
14019

141-
func (p *MainProcessorStruct) VerifyProcessor(processor interface{}) {
20+
_ = cmdwrapper.ExecuteSubcommand(flags.Command, wizardFlags)
14221
}

cmd/amazon-cloudwatch-agent-config-wizard/wizard_test.go

Lines changed: 0 additions & 78 deletions
This file was deleted.

cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,20 @@ import (
4141
"github.com/aws/amazon-cloudwatch-agent/internal/version"
4242
cwaLogger "github.com/aws/amazon-cloudwatch-agent/logger"
4343
"github.com/aws/amazon-cloudwatch-agent/logs"
44-
_ "github.com/aws/amazon-cloudwatch-agent/plugins"
44+
_ "github.com/aws/amazon-cloudwatch-agent/plugins" // do not remove, necessary for telegraf to know what plugins are used
4545
"github.com/aws/amazon-cloudwatch-agent/profiler"
4646
"github.com/aws/amazon-cloudwatch-agent/receiver/adapter"
4747
"github.com/aws/amazon-cloudwatch-agent/service/configprovider"
4848
"github.com/aws/amazon-cloudwatch-agent/service/defaultcomponents"
4949
"github.com/aws/amazon-cloudwatch-agent/service/registry"
50+
"github.com/aws/amazon-cloudwatch-agent/tool/cmdwrapper"
51+
"github.com/aws/amazon-cloudwatch-agent/tool/downloader"
52+
downloaderflags "github.com/aws/amazon-cloudwatch-agent/tool/downloader/flags"
5053
"github.com/aws/amazon-cloudwatch-agent/tool/paths"
54+
"github.com/aws/amazon-cloudwatch-agent/tool/translator"
55+
"github.com/aws/amazon-cloudwatch-agent/tool/wizard"
56+
wizardflags "github.com/aws/amazon-cloudwatch-agent/tool/wizard/flags"
57+
translatorflags "github.com/aws/amazon-cloudwatch-agent/translator/flags"
5158
"github.com/aws/amazon-cloudwatch-agent/translator/tocwconfig/toyamlconfig"
5259
)
5360

@@ -492,6 +499,40 @@ func (p *program) Stop(_ service.Service) error {
492499

493500
func main() {
494501
flag.Var(&fOtelConfigs, configprovider.OtelConfigFlagName, "YAML configuration files to run OTel pipeline")
502+
503+
// Check for subcommands first
504+
if len(os.Args) > 1 {
505+
subcommand := os.Args[1]
506+
if subcommand == translatorflags.TranslatorCommand || subcommand == downloaderflags.Command || subcommand == wizardflags.Command {
507+
subcommands := map[string]map[string]cmdwrapper.Flag{
508+
translatorflags.TranslatorCommand: translatorflags.TranslatorFlags,
509+
downloaderflags.Command: downloaderflags.DownloaderFlags,
510+
wizardflags.Command: wizardflags.WizardFlags,
511+
}
512+
handlers := map[string]func(map[string]*string) error{
513+
translatorflags.TranslatorCommand: translator.RunTranslator,
514+
downloaderflags.Command: downloader.RunDownloaderFromFlags,
515+
wizardflags.Command: wizard.RunWizardFromFlags,
516+
}
517+
518+
if err := cmdwrapper.HandleSubcommand(subcommands, handlers); err != nil {
519+
log.Fatalf("E! %s", err.Error())
520+
}
521+
return
522+
}
523+
}
524+
525+
// Override flag.Usage to include subcommand help
526+
flag.Usage = func() {
527+
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
528+
flag.PrintDefaults()
529+
fmt.Fprintf(os.Stderr, "\nAvailable subcommands:\n")
530+
fmt.Fprintf(os.Stderr, " %s\t\tTranslate configuration files\n", translatorflags.TranslatorCommand)
531+
fmt.Fprintf(os.Stderr, " %s\t\tDownload configuration from remote sources\n", downloaderflags.Command)
532+
fmt.Fprintf(os.Stderr, " %s\t\t\tInteractive configuration wizard\n", wizardflags.Command)
533+
fmt.Fprintf(os.Stderr, "\nUse '%s <subcommand> --help' for more information about a subcommand.\n", os.Args[0])
534+
}
535+
495536
flag.Parse()
496537
if len(fOtelConfigs) == 0 {
497538
_ = fOtelConfigs.Set(getFallbackOtelConfig(*fTomlConfig, paths.YamlConfigPath))
@@ -614,6 +655,7 @@ func main() {
614655
}
615656
}
616657
return
658+
617659
}
618660

619661
if runtime.GOOS == "windows" && windowsRunAsService() {

0 commit comments

Comments
 (0)