Skip to content

Commit

Permalink
Merge 97bcc36 into 35e37ea
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Jul 24, 2019
2 parents 35e37ea + 97bcc36 commit c00b7b0
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions command/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package command

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

"github.com/mackerelio/golib/pluginutil"
Expand All @@ -14,12 +15,16 @@ 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 {
workdir := workdir
if dir := lookupPluginWorkDir(pluginConfig.Command.Env); dir != "" {
workdir = dir
}
generator := &metadata.Generator{
Name: name,
Config: pluginConfig,
Cachefile: filepath.Join(workdir, "mackerel-metadata", name),
Cachefile: filepath.Join(workdir, name),
}
logger.Debugf("Metadata plugin generator created: %#v %#v", generator, generator.Config)
generators = append(generators, generator)
Expand All @@ -28,6 +33,19 @@ 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 e[len(workDirPrefix):]
}
}
return ""
}

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

0 comments on commit c00b7b0

Please sign in to comment.