-
Notifications
You must be signed in to change notification settings - Fork 263
Refactor helper binaries to save 161MB of disk space when the agent is installed and reduce RPM by 48MB #1454
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
Changes from all commits
7a309f4
bb1706e
65bf64f
ccd2f51
b5b87d7
8761b5f
f276200
f150d03
02d6463
c7ef885
cc320e5
053f080
bdaa4bd
24b1621
e8a6f09
178497d
9df4029
b8cfc3e
0ccbac8
5fa7aa6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,13 +41,20 @@ import ( | |
| "github.com/aws/amazon-cloudwatch-agent/internal/version" | ||
| cwaLogger "github.com/aws/amazon-cloudwatch-agent/logger" | ||
| "github.com/aws/amazon-cloudwatch-agent/logs" | ||
| _ "github.com/aws/amazon-cloudwatch-agent/plugins" | ||
| _ "github.com/aws/amazon-cloudwatch-agent/plugins" // do not remove, necessary for telegraf to know what plugins are used | ||
| "github.com/aws/amazon-cloudwatch-agent/profiler" | ||
| "github.com/aws/amazon-cloudwatch-agent/receiver/adapter" | ||
| "github.com/aws/amazon-cloudwatch-agent/service/configprovider" | ||
| "github.com/aws/amazon-cloudwatch-agent/service/defaultcomponents" | ||
| "github.com/aws/amazon-cloudwatch-agent/service/registry" | ||
| "github.com/aws/amazon-cloudwatch-agent/tool/cmdwrapper" | ||
| "github.com/aws/amazon-cloudwatch-agent/tool/downloader" | ||
| downloaderflags "github.com/aws/amazon-cloudwatch-agent/tool/downloader/flags" | ||
| "github.com/aws/amazon-cloudwatch-agent/tool/paths" | ||
| "github.com/aws/amazon-cloudwatch-agent/tool/translator" | ||
| "github.com/aws/amazon-cloudwatch-agent/tool/wizard" | ||
| wizardflags "github.com/aws/amazon-cloudwatch-agent/tool/wizard/flags" | ||
| translatorflags "github.com/aws/amazon-cloudwatch-agent/translator/flags" | ||
| "github.com/aws/amazon-cloudwatch-agent/translator/tocwconfig/toyamlconfig" | ||
| ) | ||
|
|
||
|
|
@@ -492,6 +499,40 @@ func (p *program) Stop(_ service.Service) error { | |
|
|
||
| func main() { | ||
| flag.Var(&fOtelConfigs, configprovider.OtelConfigFlagName, "YAML configuration files to run OTel pipeline") | ||
|
|
||
| // Check for subcommands first | ||
| if len(os.Args) > 1 { | ||
| subcommand := os.Args[1] | ||
| if subcommand == translatorflags.TranslatorCommand || subcommand == downloaderflags.Command || subcommand == wizardflags.Command { | ||
| subcommands := map[string]map[string]cmdwrapper.Flag{ | ||
| translatorflags.TranslatorCommand: translatorflags.TranslatorFlags, | ||
| downloaderflags.Command: downloaderflags.DownloaderFlags, | ||
| wizardflags.Command: wizardflags.WizardFlags, | ||
| } | ||
| handlers := map[string]func(map[string]*string) error{ | ||
| translatorflags.TranslatorCommand: translator.RunTranslator, | ||
| downloaderflags.Command: downloader.RunDownloaderFromFlags, | ||
| wizardflags.Command: wizard.RunWizardFromFlags, | ||
| } | ||
|
|
||
| if err := cmdwrapper.HandleSubcommand(subcommands, handlers); err != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we already did all of the work here to find the subcommand and we already know which handler and flag set to use so the Not that important to update though since the duplicate work is not going to impact performance in any meaningful way
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think this is a fair point. We can improve this in a separate PR as a follow up. |
||
| log.Fatalf("E! %s", err.Error()) | ||
| } | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // Override flag.Usage to include subcommand help | ||
| flag.Usage = func() { | ||
| fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) | ||
| flag.PrintDefaults() | ||
| fmt.Fprintf(os.Stderr, "\nAvailable subcommands:\n") | ||
| fmt.Fprintf(os.Stderr, " %s\t\tTranslate configuration files\n", translatorflags.TranslatorCommand) | ||
| fmt.Fprintf(os.Stderr, " %s\t\tDownload configuration from remote sources\n", downloaderflags.Command) | ||
| fmt.Fprintf(os.Stderr, " %s\t\t\tInteractive configuration wizard\n", wizardflags.Command) | ||
| fmt.Fprintf(os.Stderr, "\nUse '%s <subcommand> --help' for more information about a subcommand.\n", os.Args[0]) | ||
| } | ||
|
Comment on lines
+526
to
+534
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really nice 👍 |
||
|
|
||
| flag.Parse() | ||
| if len(fOtelConfigs) == 0 { | ||
| _ = fOtelConfigs.Set(getFallbackOtelConfig(*fTomlConfig, paths.YamlConfigPath)) | ||
|
|
@@ -614,6 +655,7 @@ func main() { | |
| } | ||
| } | ||
| return | ||
|
|
||
| } | ||
|
|
||
| if runtime.GOOS == "windows" && windowsRunAsService() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: stylistically I'd rather use a switch statement here but I think this is perfectly fine