-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new config command to print out all configuration (#119)
### Description OB-37220 add a new config command to print out all configuration This naming matches the `datadog-agent config` command. Having this will facilitate debugging as we start to add templated data to our OTEL config fragments. ### Checklist - [ ] Created tests which fail without the change (if possible) - [ ] Extended the README / documentation, if necessary
- Loading branch information
1 parent
7cd4fbf
commit 2bcd1c1
Showing
9 changed files
with
75 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package config | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/observeinc/observe-agent/internal/commands/start" | ||
logger "github.com/observeinc/observe-agent/internal/commands/util" | ||
"github.com/observeinc/observe-agent/internal/root" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var configCmd = &cobra.Command{ | ||
Use: "config", | ||
Short: "Prints the full configuration for this agent.", | ||
Long: `This command prints all configuration for this agent including any additional | ||
OTEL configuration.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := logger.WithCtx(context.Background(), logger.GetNop()) | ||
configFilePaths, cleanup, err := start.SetupAndGetConfigFiles(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
if cleanup != nil { | ||
defer cleanup() | ||
} | ||
agentConfig := viper.ConfigFileUsed() | ||
configFilePaths = append([]string{agentConfig}, configFilePaths...) | ||
for _, filePath := range configFilePaths { | ||
file, err := os.ReadFile(filePath) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error reading config file %s: %s", filePath, err.Error()) | ||
} else { | ||
fmt.Printf("# ======== config file %s\n", filePath) | ||
fmt.Println(string(file)) | ||
} | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
root.RootCmd.AddCommand(configCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters