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

[chore] Schema Processor Revamp [Part 4] - Manager/Provider #37402

Conversation

ankitpatel96
Copy link
Contributor

@ankitpatel96 ankitpatel96 commented Jan 22, 2025

Description

This is a slice of changes from #35248
It's stacked on top of #37403

This PR details the Manager and Provider. The Manager is responsible for fetching and caching the translations. The Provider helps fetch the schema URLs.
It's a pretty small PR compared to part 3 -
❯ git diff ankit-schema-processor-3-translation --stat
.../translation/manager.go | 131 ++++++++++
.../translation/manager_test.go | 68 +++++
.../translation/provider.go | 73 ++++++
.../translation/provider_test.go | 52 ++++
.../testdata/schema.yaml | 112 ++++++++
5 files changed, 436 insertions(+)

Testing

Unit tests

@github-actions github-actions bot added the processor/schema Schema processor label Jan 22, 2025
@ankitpatel96 ankitpatel96 changed the title split out translation chunk split out manager/provider chunk Jan 22, 2025
@ankitpatel96 ankitpatel96 changed the title split out manager/provider chunk [chore] split out manager/provider chunk Jan 22, 2025
@ankitpatel96 ankitpatel96 changed the title [chore] split out manager/provider chunk [chore] split out manager/provider chunk Jan 22, 2025
@ankitpatel96 ankitpatel96 changed the title [chore] split out manager/provider chunk [chore] Schema Processor Revamp [Part 3] - Manager/Provider Jan 22, 2025
@ankitpatel96 ankitpatel96 changed the title [chore] Schema Processor Revamp [Part 3] - Manager/Provider [chore] Schema Processor Revamp [Part 4] - Manager/Provider Jan 22, 2025
@ankitpatel96 ankitpatel96 marked this pull request as ready for review January 22, 2025 15:19
@ankitpatel96 ankitpatel96 requested a review from a team as a code owner January 22, 2025 15:19
@ankitpatel96 ankitpatel96 force-pushed the ankit-schema-processor-4-manager-provider branch from b846651 to 2cf50a3 Compare January 22, 2025 18:54
@tigrannajaryan
Copy link
Member

Let me know once #37403 is merged and this is rebased, I will take a look.

@ankitpatel96 ankitpatel96 force-pushed the ankit-schema-processor-4-manager-provider branch from 2cf50a3 to 5fe87d3 Compare February 5, 2025 17:44
// of schema, the options allow for additional properties to be
// added to manager to enable additional locations of where to check
// for translations file.
func NewManager(targets []string, log *zap.Logger) (Manager, error) {
Copy link
Member

Choose a reason for hiding this comment

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

What are the targets? Are the they schema URLs? If yes perhaps targetShemaURLs as a name?

Comment on lines 43 to 47
// NewManager creates a manager that will allow for management
// of schema, the options allow for additional properties to be
// added to manager to enable additional locations of where to check
// for translations file.
func NewManager(targets []string, log *zap.Logger) (Manager, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Where are options ?

Comment on lines 71 to 73
m.log.Debug("No valid schema url was provided, using no-op schema",
zap.String("schema-url", schemaURL),
)
Copy link
Member

Choose a reason for hiding this comment

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

should this be error ?

Comment on lines 79 to 81
m.log.Debug("Not a known target, providing Nop Translation",
zap.String("schema-url", schemaURL),
)
Copy link
Member

Choose a reason for hiding this comment

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

I feel this is critical feedback to the user , should be error

}
m.rw.Lock()
m.providers = append(m.providers[:0], providers...)
m.rw.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

do a defer unlock

Comment on lines 55 to 73
type testProvider struct {
fs *embed.FS
}

func NewTestProvider(fs *embed.FS) Provider {
return &testProvider{fs: fs}
}

func (tp testProvider) Lookup(_ context.Context, schemaURL string) (io.Reader, error) {
parsedPath, err := url.Parse(schemaURL)
if err != nil {
return nil, err
}
f, err := tp.fs.Open(parsedPath.Path[1:])
if err != nil {
return nil, err
}
return f, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is test provider present here ?

type Provider interface {
// Lookup whill check the underlying provider to see if content exists
// for the provided schemaURL, in the even that it doesn't an error is returned.
Lookup(ctx context.Context, schemaURL string) (content io.Reader, err error)
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Can we return a string or a struct with result embedded


targetTranslation, match := m.match[family]
if !match {
m.log.Warn("Not a known targetTranslation, providing Nop Translation",
Copy link
Member

Choose a reason for hiding this comment

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

The message seems incorrect, we don't return Nop Translation.

Copy link
Member

Choose a reason for hiding this comment

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

good catch. fixed it

func (m *manager) RequestTranslation(ctx context.Context, schemaURL string) (Translation, error) {
family, version, err := GetFamilyAndVersion(schemaURL)
if err != nil {
m.log.Error("No valid schema url was provided, using no-op schema",
Copy link
Member

Choose a reason for hiding this comment

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

The message is unclear, what does "using no-op schema" mean?

Copy link
Member

Choose a reason for hiding this comment

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

good catch. fixed it

Comment on lines 20 to 22
cooldown time.Duration
callcount int
limit int
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to doc-comment these fields to explain how they work together to do rate limiting (plus resetTime, I think?).

Copy link
Member

Choose a reason for hiding this comment

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

Added comments

@tigrannajaryan
Copy link
Member

The build failed. Appears to be an unrelated test, but please double check.

@dineshg13
Copy link
Member

Prometheus tests have been flakey, will merge after successful build.

…m:ankitpatel96/opentelemetry-collector-contrib into ankit-schema-processor-4-manager-provider
@mx-psi mx-psi merged commit d437292 into open-telemetry:main Mar 5, 2025
156 checks passed
@github-actions github-actions bot added this to the next release milestone Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
processor/schema Schema processor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants