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

Nested plugin binaries are output to their respective directories #1007

Merged
merged 3 commits into from
Jun 17, 2024

Conversation

wbrowne
Copy link
Member

@wbrowne wbrowne commented Jun 14, 2024

What this PR does / why we need it:
Currently it is expected that any nested datasource binary is placed in the root of the plugin dist. This forces the executable path of the nested plugin to contain relative path information so that the binary can be found when loaded by Grafana.

This is problematic as it makes it impossible to run these nested plugins on Windows as the path information is UNIX style. Considering the binary belongs to the nested plugin - it should live in the nested plugin's directory so that it is clear what the binary is associated with.

This PR makes it possible to do so while also keeping existing plugins backwards compatible. Therefore plugins with path information in the nested plugin executable ../$binaryName will continue to work.

Special notes for your reviewer:

  • In cases where there is backend app plugin with a nested backend datasource plugin, this will ensure that all binaries don't have to live in the same directory.
  • For the plugin CDN, if we ever wanted to upload all files, this change will make this much easier to reason about.

@wbrowne wbrowne added the chore label Jun 14, 2024
@wbrowne wbrowne self-assigned this Jun 14, 2024
@wbrowne wbrowne requested a review from a team as a code owner June 14, 2024 10:51
@wbrowne wbrowne requested review from marefr, andresmgot and xnyo and removed request for a team June 14, 2024 10:51
}

// execNameCache is a cache for the executable name, so we don't have to read the plugin.json file multiple times.
var executableNameCache sync.Map
Copy link
Member Author

Choose a reason for hiding this comment

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

This is mimicking what we are already doing today with var exname string above

Copy link
Contributor

Choose a reason for hiding this comment

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

I know you wanted to mimick what was there already but is this cache relevant? I'd say the time to read the plugin json file is negligible vs the time to compile 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess for building for all distros for example you benefit from not reading it 6+ times. I haven't performance tested it or anything though 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

I did some light testing and it's negligible it seems. I'll keep it for now for consistency and it does not harm I guess

var (
defaultOutputBinaryPath = "dist"
defaultPluginJSONPath = "src"
defaultNestedDataSourcePath = "datasource"
Copy link
Member Author

Choose a reason for hiding this comment

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

I have opted to not add a config option for this because I think if people want to do something out of the standard we are offering (docs to come in plugin-tools), then they can do so with mage. For example:

func Foo() {
	configCallback := func(cfg build.Config) (build.Config, error) {
		cfg.PluginJSONPath = "src/myCustomPath"
		return cfg, nil
	}
	build.SetBeforeBuildCallback(configCallback)
	build.BuildAll()
}

Copy link
Contributor

@marefr marefr left a comment

Choose a reason for hiding this comment

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

LGTM with a nit

@@ -40,6 +46,10 @@ func SetBeforeBuildCallback(cb BeforeBuildCallback) error {

var exname string

// Deprecated: Use getExecutableNameForPlugin instead.
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 not exported so maybe can be deleted?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to - but this func is being used in a couple of places (for debugging it looks like) and I'm reluctant to change in the off chance someone is relying on this behaviour in the debugging setup!

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

LGTM

}

// execNameCache is a cache for the executable name, so we don't have to read the plugin.json file multiple times.
var executableNameCache sync.Map
Copy link
Contributor

Choose a reason for hiding this comment

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

I know you wanted to mimick what was there already but is this cache relevant? I'd say the time to read the plugin json file is negligible vs the time to compile 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

3 participants