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

Disable config switch #191

Merged
merged 11 commits into from
Sep 22, 2023
Merged

Disable config switch #191

merged 11 commits into from
Sep 22, 2023

Conversation

johnbley
Copy link
Contributor

Add a config environment variable to disable the collection of metrics through this extension. Owing to the rules the lambda engine places on extensions, this isn't as simple as "just exit" - you still have to Register as an extension, and ask for at least the shutdown event. Additionally, add a config switch for "extension name" to make a complicated workaround for disabling the opentelemetry collector possible.

Copy link
Contributor

@pmcollins pmcollins left a comment

Choose a reason for hiding this comment

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

Approved with some non-blocking comments.

configuration := config.New()

initLogging(&configuration)

ossignal.Watch()

m := metrics.New()
var m *metrics.MetricEmitter = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of a nit, especially if this library is going away, but might be nice to instead extract an interface and use a no-op implementation so we don't have to check for nil before calling methods on the variable.

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, I like that. I'll add a comment to this effect for now.

cmd/splunk-extension-wrapper/splunk-extension-wrapper.go Outdated Show resolved Hide resolved

shutdownCondition := registerApiAndStartMainLoop(m, &configuration)
shutdownCondition := registerApiAndStartMainLoop(enabled, m, &configuration)
Copy link
Contributor

Choose a reason for hiding this comment

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

Also a nit and just a personal style preference (it's also in Clean Code!): instead of passing in a boolean flag then modifying the behavior of the function based on its value, consider creating two separate functions.

@@ -121,5 +140,9 @@ func initLogging(configuration *config.Configuration) {
}

func extensionName() string {
return path.Base(os.Args[0])
name := os.Getenv(extensionNameKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: another way to write this function using Go idioms:

	if name := os.Getenv(extensionNameKey); name != "" {
		return name
	}
	return path.Base(os.Args[0])

@johnbley johnbley merged commit fee0cd3 into main Sep 22, 2023
@johnbley johnbley deleted the disable_collector_config_switch branch September 22, 2023 17:21
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