Skip to content

Commit

Permalink
Merge 79f7890 into 026b1f0
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Jul 29, 2019
2 parents 026b1f0 + 79f7890 commit 4e2bb30
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions command/metadata.go
Expand Up @@ -2,6 +2,7 @@ package command

import (
"path/filepath"
"strings"
"time"

"github.com/mackerelio/golib/pluginutil"
Expand All @@ -14,12 +15,12 @@ import (
func metadataGenerators(conf *config.Config) []*metadata.Generator {
generators := make([]*metadata.Generator, 0, len(conf.MetadataPlugins))

workdir := pluginutil.PluginWorkDir()
workdir := filepath.Join(pluginutil.PluginWorkDir(), "mackerel-metadata")
for name, pluginConfig := range conf.MetadataPlugins {
generator := &metadata.Generator{
Name: name,
Config: pluginConfig,
Cachefile: filepath.Join(workdir, "mackerel-metadata", name),
Cachefile: getCacheFileName(name, workdir, pluginConfig),
}
logger.Debugf("Metadata plugin generator created: %#v %#v", generator, generator.Config)
generators = append(generators, generator)
Expand All @@ -28,6 +29,26 @@ func metadataGenerators(conf *config.Config) []*metadata.Generator {
return generators
}

// The directory configuration in the env config of metadata should work as
// same as metric plugins. Since the working directory of metadata plugin is
// handled by mackerel-agent (not the plugin process), we have to lookup here.
func lookupPluginWorkDir(env []string) string {
workDirPrefix := "MACKEREL_PLUGIN_WORKDIR="
for _, e := range env {
if strings.HasPrefix(e, workDirPrefix) {
return strings.TrimPrefix(e, workDirPrefix)
}
}
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 4e2bb30

Please sign in to comment.