Skip to content

Commit

Permalink
prepend mackerel-plugin-metadata- to the cache file of metadata plugi…
Browse files Browse the repository at this point in the history
…n when MACKEREL_PLUGIN_WORKDIR is specified
  • Loading branch information
itchyny committed Jul 29, 2019
1 parent 8366178 commit 79f7890
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions command/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ func metadataGenerators(conf *config.Config) []*metadata.Generator {

workdir := filepath.Join(pluginutil.PluginWorkDir(), "mackerel-metadata")
for name, pluginConfig := range conf.MetadataPlugins {
workdir := workdir
if dir := lookupPluginWorkDir(pluginConfig.Command.Env); dir != "" {
workdir = dir
}
generator := &metadata.Generator{
Name: name,
Config: pluginConfig,
Cachefile: filepath.Join(workdir, name),
Cachefile: getCacheFileName(name, workdir, pluginConfig),
}
logger.Debugf("Metadata plugin generator created: %#v %#v", generator, generator.Config)
generators = append(generators, generator)
Expand All @@ -46,6 +42,13 @@ func lookupPluginWorkDir(env []string) string {
return ""
}

func getCacheFileName(name, defaultWorkDir string, plugin *config.MetadataPlugin) string {
if dir := lookupPluginWorkDir(plugin.Command.Env); dir != "" {
return filepath.Join(dir, "mackerel-plugin-metadata-"+name)
}
return filepath.Join(defaultWorkDir, name)
}

type metadataResult struct {
namespace string
metadata interface{}
Expand Down

0 comments on commit 79f7890

Please sign in to comment.