Skip to content
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

Make MakeFactoryMap generic and move to otelcol #12220

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

jade-guiton-dd
Copy link
Contributor

@jade-guiton-dd jade-guiton-dd commented Jan 31, 2025

Description

At the moment, receiver, scraper, processor, exporter, and extension each have their own version of the MakeFactoryMap function, which takes a list of Factories and returns it as a map, with the component name as the key (and an error if there is overlap). Because all versions are near-identical except for the Factory type used, and this function is only used in tests and in the code generated by OCB (components.go), it was suggested to make it generic and move it to the otelcol package.

This PR does exactly that. The old MakeFactoryMap functions are deprecated (and may be removed alongside their tests in a future release). I also had to make a few other odd changes to fit the new dependency graph.

Link to tracking issue

Resolves #12222

Copy link

codecov bot commented Jan 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.45%. Comparing base (765e4a5) to head (d2a04ba).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12220      +/-   ##
==========================================
+ Coverage   91.39%   91.45%   +0.05%     
==========================================
  Files         468      469       +1     
  Lines       25591    25590       -1     
==========================================
+ Hits        23390    23404      +14     
+ Misses       1785     1775      -10     
+ Partials      416      411       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jade-guiton-dd
Copy link
Contributor Author

jade-guiton-dd commented Jan 31, 2025

Hm, CI says otelcorecol is out of date, but I get on my diff locally when running make genotelcorecol

Edit: The issue was that I was using a different version of Go from the CI, so the toolchain directive generated by ocb was different

@jade-guiton-dd

This comment was marked as resolved.

@jade-guiton-dd
Copy link
Contributor Author

I removed scraper from the test because the dependency changes were causing crosslink to add replaces where they weren't actually needed, might file an issue about that later. The generic code only relies on the component.Factory interface anyway, which scraper.Factory is a subinterface of, so this is probably fine?

@jade-guiton-dd jade-guiton-dd marked this pull request as ready for review February 3, 2025 11:29
@jade-guiton-dd jade-guiton-dd requested a review from a team as a code owner February 3, 2025 11:29
@mx-psi
Copy link
Member

mx-psi commented Feb 5, 2025

@bogdandrutu will merge this on Friday, this seems fine to me but since otelcol is far from being stabilized we can iterate on the function if we need to

@jade-guiton-dd can you solve the merge conflicts?

Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

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

The pattern to avoid circular deps that I've seen is to move tests in a package "builder_test" in the same directory.

@@ -13,7 +13,7 @@ import (

var (
errNilNextConsumer = errors.New("nil next Consumer")
nopType = component.MustNewType("nop")
NopType = component.MustNewType("nop")
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

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 moved the tests into the separate builderstest package to avoid circular dependencies, and this variable is used in the tests, so I needed to make it exported to keep it accessible. Note that all of this is still under internal, so I don't think this expands the public API.

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 based the builderstest naming convention on componenttest, connectortest, consumertest, etc. Do you think I should make it a child of builders instead of a sibling?

Copy link
Member

Choose a reason for hiding this comment

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

builderstest -> is the test files, not testing helpers

@mx-psi mx-psi requested a review from bogdandrutu February 7, 2025 09:12
@mx-psi mx-psi added the release:blocker The issue must be resolved before cutting the next release label Feb 10, 2025
@mx-psi
Copy link
Member

mx-psi commented Feb 10, 2025

I want us to be able to mark extension as 1.0 as soon as we mark component 1.0, so I am marking this as release blocker for the next release. I believe the changes discussed are all internal, so this is more of a reminder.

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Change looks good, just need to update the deprecation version

@@ -388,6 +388,8 @@ func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefa

// MakeFactoryMap takes a list of connector factories and returns a map with factory type as keys.
// It returns a non-nil error when there are factories with duplicate type.
//
// Deprecated: [v0.119.0] Use otelcol.MakeFactoryMap[connector.Factory] instead
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
// Deprecated: [v0.119.0] Use otelcol.MakeFactoryMap[connector.Factory] instead
// Deprecated: [v0.120.0] Use otelcol.MakeFactoryMap[connector.Factory] instead

@@ -190,6 +190,8 @@ func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefa

// MakeFactoryMap takes a list of factories and returns a map with Factory type as keys.
// It returns a non-nil error when there are factories with duplicate type.
//
// Deprecated: [v0.119.0] Use otelcol.MakeFactoryMap[exporter.Factory] instead
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
// Deprecated: [v0.119.0] Use otelcol.MakeFactoryMap[exporter.Factory] instead
// Deprecated: [v0.120.0] Use otelcol.MakeFactoryMap[exporter.Factory] instead

@@ -82,6 +82,8 @@ func NewFactory(

// MakeFactoryMap takes a list of factories and returns a map with Factory type as keys.
// It returns a non-nil error when there are factories with duplicate type.
//
// Deprecated: [v0.119.0] Use otelcol.MakeFactoryMap[extension.Factory] instead
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
// Deprecated: [v0.119.0] Use otelcol.MakeFactoryMap[extension.Factory] instead
// Deprecated: [v0.120.0] Use otelcol.MakeFactoryMap[extension.Factory] instead

@@ -138,6 +138,8 @@ func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefa

// MakeFactoryMap takes a list of receiver factories and returns a map with factory type as keys.
// It returns a non-nil error when there are factories with duplicate type.
//
// Deprecated: [v0.119.0] Use otelcol.MakeFactoryMap[scraper.Factory] instead
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
// Deprecated: [v0.119.0] Use otelcol.MakeFactoryMap[scraper.Factory] instead
// Deprecated: [v0.120.0] Use otelcol.MakeFactoryMap[scraper.Factory] instead

@@ -200,6 +200,8 @@ func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefa

// MakeFactoryMap takes a list of receiver factories and returns a map with factory type as keys.
// It returns a non-nil error when there are factories with duplicate type.
//
// Deprecated: [v0.119.0] Use otelcol.MakeFactoryMap[receiver.Factory] instead
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
// Deprecated: [v0.119.0] Use otelcol.MakeFactoryMap[receiver.Factory] instead
// Deprecated: [v0.120.0] Use otelcol.MakeFactoryMap[receiver.Factory] instead

@@ -193,6 +193,8 @@ func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefa

// MakeFactoryMap takes a list of factories and returns a map with Factory type as keys.
// It returns a non-nil error when there are factories with duplicate type.
//
// Deprecated: [v0.119.0] Use otelcol.MakeFactoryMap[processor.Factory] instead
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
// Deprecated: [v0.119.0] Use otelcol.MakeFactoryMap[processor.Factory] instead
// Deprecated: [v0.120.0] Use otelcol.MakeFactoryMap[processor.Factory] instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:blocker The issue must be resolved before cutting the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[extension/receiver/exporter/connector/processor] Move MakeFactoryMap to otelcol
4 participants