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

Add WithServiceName and WithPid as config options for instrumentation… #346

Closed

Conversation

RonFed
Copy link
Contributor

@RonFed RonFed commented Sep 24, 2023

This PR add two InstrumentationOption:

In addition the Cleanup in bpffs was not called which resulted in garbage folders under /sys/fs/bpf not get deleted after the instrumentation is finished

…. Call the cleanup method of bpffs when needed
@RonFed RonFed requested a review from a team September 24, 2023 12:50
Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Can you split this PR into 4 PRs:

  • Add the service name option
  • Add the PID option
  • Fix the close
  • Fix the use of ioutil

Currently it is trying solve multiple issues in one PR.

return c
}

func (c instConfig) validate() error {
if c.target == nil {
return errUndefinedTarget
}
if c.serviceName == "" {
return errUndefinedServiceName
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be an error, or shouldn't it just use the resource default service name if not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, we are not allowing for not setting the service name env variable. So this code preserves that.
We can change it to a default service name if not set.

instrumentation.go Outdated Show resolved Hide resolved
// WithPID returns an [InstrumentationOption] corresponding to the executable
// used by the provided pid.
//
// If WithTarget is used, the one which is used last will take precedence.
Copy link
Contributor

Choose a reason for hiding this comment

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

WithTarget docs need to be updated to include this conflict as well.

instrumentation.go Outdated Show resolved Hide resolved
instrumentation.go Outdated Show resolved Hide resolved
exePath, err := os.Readlink(exeLinkPath)
if err != nil {
log.Logger.Error(err, "Failed to read link for process exe")
exePath = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

This likely shouldn't return WithTarget at this point. Maybe just return nil and ensure newInstConfig handles that value appropriately.

@@ -45,3 +46,7 @@ func (a *Allocator) Load(ctx *context.InstrumentorContext) error {

return nil
}

func (a *Allocator) Clean(target *process.TargetDetails) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing comment.

//
// If OTEL_SERVICE_NAME is defined it will take precedence over any value
// passed here.
func WithServiceName(serviceName string) InstrumentationOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a changelog entry in an Added section.

// used by the provided pid.
//
// If WithTarget is used, the one which is used last will take precedence.
func WithPID(pid int) InstrumentationOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a changelog entry in an Added section.

@pellared
Copy link
Member

pellared commented Sep 25, 2023

The tests are missing.

@RonFed
Copy link
Contributor Author

RonFed commented Sep 25, 2023

The tests are missing.

@pellared Where do you think would be a good place to add tests for these options? I couldn't find tests for the existing one

@RonFed
Copy link
Contributor Author

RonFed commented Sep 25, 2023

Can you split this PR into 4 PRs:

  • Add the service name option
  • Add the PID option
  • Fix the close
  • Fix the use of ioutil

Currently it is trying solve multiple issues in one PR.

Maybe the first 2 can be in the same PR since they are very similar?

@pellared
Copy link
Member

The tests are missing.

@pellared Where do you think would be a good place to add tests for these options? I couldn't find tests for the existing one

I am open to suggestions. Personally, I think both options deserve integration/e2e tests.

For service name handling we could also add unit tests for newInstConfig function.

@RonFed
Copy link
Contributor Author

RonFed commented Sep 29, 2023

WithServiceName #353
WithPID: #355
bpffs cleanup #347
stop using ioutil #351

@RonFed RonFed closed this Sep 29, 2023
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.

3 participants