Skip to content

Conversation

@braydonk
Copy link
Contributor

@braydonk braydonk commented Mar 7, 2025

This PR is a rewrite of the opentelemetry-operations-collector repo to the new version from the google-otel-poc branch. The new version has:

  • A tool called distrogen for generation and management of collector distributions
  • The original otelopscol binary buildable with ocb
  • The new Google-Built OpenTelemetry Collector
  • All the same original components as the original repo, modularized for use with OCB
  • An in-depth Makefile and developer tooling to make updating OTel versions for components as seamless as possible

@braydonk braydonk force-pushed the google-otel-rewrite branch from cd1bfd6 to c3753a0 Compare March 7, 2025 19:29
@ridwanmsharif
Copy link
Contributor

Interesting, do we need to make relevant kokoro config changes to make it work with this change?

@braydonk
Copy link
Contributor Author

braydonk commented Mar 7, 2025

I think we should just get rid of that Kokoro setup, it is utterly unnecessary and has been for years.

@bwplotka
Copy link

Looks solid, nice!

Copy link

@LujieDuan LujieDuan left a comment

Choose a reason for hiding this comment

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

Nice work! Couple of small suggestions:

Copy link
Contributor

@ridwanmsharif ridwanmsharif left a comment

Choose a reason for hiding this comment

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

note: I only reviewed distrogen. Most of my comments are noits and not blocking. Once responded to or addressed, I'll do another quick pass but things look pretty good now

"github.com/google/go-cmp/cmp"
)

var ErrNoDiff = errors.New("no differences found with previous generation")
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this have to be exported?


RUN_DISTROGEN=go run ./cmd/distrogen

GEN_GOOGLE_OTEL=$(RUN_DISTROGEN) -registry ./registries/operations-collector-registry.yaml -spec ./specs/google-otel.yaml -custom_templates ./templates/google-otel
Copy link
Contributor

Choose a reason for hiding this comment

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

These are really cool make targets. Could you add a README.md in the distrogen tool with some instructions on what we expect each of these yaml files to contain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do, but need a bit more time to write something nice.

var result T
err = yaml.Unmarshal(content, &result)
if err != nil {
return nil, wrapYamlErr(err, path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, wrapYamlErr(err, path)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal file %s something: %w", path, originalErr)
}
return &result, nil

Why not just this? I don't see wrapYamlErr used anywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

brain must have been turned off when I wrote this cause yeah idk why I did that. Fixed in 79e8314

return generateDistribution()
}

func generateSpec() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat idea. We don't have to recommend or document this option yet but I'm not sure if this is how I want to recommend folks build their GBOT spec. I imagine folks want a collector for a bunch of different configs/use cases and we don't want folks to build a different spec for each one. It is certainly a useful tool to find a minimal spec but this could confuse some people too.

Also, it doesn't do enough right? If my config uses an invalid receiver, or uses a forked component, I still would need to provide a registry.yaml file for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This feature is definitely half-baked. I forgot it was even here in the primary branch. I did it as a mockup for someone at KubeCon. I am okay with straight up removing the feature for now cause it's half-baked.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah might be simpler to just remove for now

if !ok {
return nil, fmt.Errorf("reading section %s: invalid section data", sectionName)
}
return mapKeys(section), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not entirely right is it? You can have receivers with the name prometheus/self-metrics and prometheus/app both referring to the same underlying receiver but the receiver is just prometheus.


// LoadAll will take a list of component names and load them
// from the registry, attaching the appropriate version tag.
func (rl RegistryList) LoadAll(names []string, version string, stableVersion string, contribVersion string) (RegistryComponents, RegistryLoadError) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Load here is used in a different context than how its used when we called LoadRegistry. Lets fix one of the naming to something else

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Load is such an equally good word for both things that I struggled to come up with something. Proposed something in 7442ce8


// RegistryComponents is a map of registry component names to component
// details.
type RegistryComponents map[string]*RegistryComponent
Copy link
Contributor

Choose a reason for hiding this comment

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

type RegistryList map[string]*RegistryComponent

Isn't this component effectively the same from one in line 70?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah you're right, I didn't notice these types converge when I refactored a bunch of registry stuff. Removed and consolidated the methods in 79e8314


errs := make(RegistryLoadError)
var err RegistryLoadError
context.Receivers, err = registry.Receivers.LoadAll(spec.Components.Receivers, spec.OpenTelemetryVersion, spec.OpenTelemetryStableVersion, spec.OpenTelemetryContribVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

This translation from the RegistryList to RegistryComponents is confusing. They are the same no?

Seems like all this is doing is some cleanup of the gomod entry

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In registry, the full list of all components exists. The context will only contain the actual configured components from the spec. Now that the type names are the same this is more confusing, not sure if this can either be done differently or if I should just add a comment clarifying.

@ridwanmsharif ridwanmsharif self-requested a review March 14, 2025 04:09
return generateDistribution()
}

func generateSpec() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah might be simpler to just remove for now

errs := make(RegistryLoadError)

for _, name := range names {
entry, err := rl.LoadComponent(name)
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] This is just a map lookup now, we can inline this when its called and get rid of this method.

Suggested change
entry, err := rl.LoadComponent(name)
entry, ok := rl[name]
if !ok {
errs[name] = ErrComponentNotFound
continue
}

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 ended up refactoring this slightly in 055331f

The method is still there but it does things in a different order that makes more sense

}

// LoadComponent will load a component from the registry.
func (rl RegistryComponents) LoadComponent(name string) (*RegistryComponent, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need this I don't think, see other comment

Copy link
Contributor

@ridwanmsharif ridwanmsharif left a comment

Choose a reason for hiding this comment

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

my comments don't block a merge fwiw. Feel free to resolve and address the rest

all distrogen changes LGTM. Lets get this in 🚀🚀🚀

Copy link

@LujieDuan LujieDuan left a comment

Choose a reason for hiding this comment

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

Reviewed other changes and LGTM! 🚀

braydonk and others added 16 commits March 14, 2025 20:02
This PR is a rewrite of the opentelemetry-operations-collector repo to
the new version from the `google-otel-poc` branch. The new version has:
* A tool called `distrogen` for generations and managing collector
  distributions
* The original otelopscol binary buildable with ocb
* The new Google-Built OpenTelemetry Collector
* All the same original components as the original repo, modularized for
  use with OCB
* An in-depth Makefile and developer tooling to make updating OTel
  versions for components as seamless as possible
@braydonk braydonk force-pushed the google-otel-rewrite branch from 59043c8 to 65c09be Compare March 14, 2025 20:03
@ridwanmsharif
Copy link
Contributor

FYI: I updated the branch protection rules on this repo so the Kokoro presubmits are non-blocking for merge to master.

@braydonk braydonk merged commit cb12823 into master Mar 18, 2025
3 of 6 checks passed
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.

5 participants