Skip to content

feat: Add manifest update Command for Configuration Management#308

Merged
mailo-nr merged 2 commits intomainfrom
marsac/nrdot-cli
May 12, 2025
Merged

feat: Add manifest update Command for Configuration Management#308
mailo-nr merged 2 commits intomainfrom
marsac/nrdot-cli

Conversation

@mailo-nr
Copy link
Contributor

This PR introduces a new manifest update command to the nrdot-collector-builder CLI. The command streamlines the process of updating manifest configuration files, ensuring that OpenTelemetry (otel) components are always up to date and that configuration files remain valid and consistent.

  • New Cobra Command:
    Adds a manifest update subcommand, accessible via the CLI, with clear usage and help text.

  • Flexible File Matching:
    Supports glob patterns for the --config flag, allowing users to update multiple manifest files in a single invocation.

  • Robust Validation:
    Loads the specified configuration file(s), validates their structure and content, and ensures all required fields and modules are present.

  • Go Environment Detection:
    Automatically detects and sets the correct Go binary path if not explicitly provided, improving portability and reliability.

Example Usage:

nrdot-collector-builder manifest update --config path/to/manifest.yaml
nrdot-collector-builder manifest update --config 'distributins/*/manifest.yaml'

@mailo-nr mailo-nr requested a review from a team as a code owner May 12, 2025 19:39

var manifestConfigPath string

// manifestCmd represents the manifest command
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to align on our team's 'philosophy' on comments

Long: `
The manifest command allows you to manage the OCB manifest file.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("manifest called")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional or is this a leftover debugging artifact?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's leftover from the cobra scaffolding

manifestCmd.AddCommand(manifest.UpdateCmd)

// Define a persistent flag for `manifestCmd`
manifestCmd.PersistentFlags().StringVarP(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When testing, I absent-mindedly provided the config.yaml instead of the manifest.yaml and it obviously failed. As we have two configs in the collector world and the runtime configs are the ones that usually get more attention and are thus more associated with the 'config' word, we might want to think about using a different name/flag here? Just a thought but wanted to mention it.

Long: "Update the manifest file to ensure otel components are up to date.",

RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("manifest update called")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug artifact?

var errMissingGoMod = errors.New("missing gomod specification for module")

// Config holds the builder's configuration
type Config struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume there wasn't a (easy) way to reuse the definitions from the otel repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, all structs are internal

func TestUpdateCmd_RunE_InvalidConfig(t *testing.T) {

cmd := &cobra.Command{}
cmd.Flags().String("config", "test-config.yaml", "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we don't use the invalid test data config? As far as I can tell it's unused?

assert.Contains(t, err.Error(), "invalid configuration")

mockConfig.AssertExpectations(t)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we support globbing, a test to validate that would be great.

func validateModules(name string, mods []Module) error {
for i, mod := range mods {
if mod.GoMod == "" {
return fmt.Errorf("%s module at index %v: %w", name, i, errMissingGoMod)
Copy link
Contributor

@kb-newrelic kb-newrelic May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried to accidentally parse a non-manifest yaml, the error message was

2025-05-12T14:35:58.717-0700    INFO    manifest/update.go:80   Using config file       {"path": "../../distributions/nrdot-collector-host/config.yaml"}
Error: invalid configuration: extension module at index 0: missing gomod specification for module; receiver module at index 0: missing gomod specification for module; exporter module at index 0: missing gomod specification for module; processor module at index 0: missing gomod specification for module

It took me a while to realize that I was parsing the wrong type of config. Might be good to short circuit early when the component-type keys (e.g. receiver) is not present at all instead of accumulating all the errors from this level.

return nil
}

func parseModules(mods []Module, usedNames map[string]int) ([]Module, error) {
Copy link
Contributor

@kb-newrelic kb-newrelic May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we ourselves are not yet using anything but gomod for module specification, it would be good to have some tests to document what this is validating.

@mailo-nr mailo-nr force-pushed the marsac/nrdot-cli branch from b00de65 to 1e142a6 Compare May 12, 2025 22:33
@mailo-nr mailo-nr merged commit 023aa5c into main May 12, 2025
11 checks passed
@mailo-nr mailo-nr deleted the marsac/nrdot-cli branch May 12, 2025 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments