mirror of https://github.com/grafana/loki
This allows easier integration of other targets than files for promtail. Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>pull/282/head
parent
4c985efade
commit
31789eafc4
@ -1,4 +1,4 @@ |
||||
package promtail |
||||
package api |
||||
|
||||
import ( |
||||
"encoding/json" |
@ -0,0 +1,58 @@ |
||||
package targets |
||||
|
||||
import ( |
||||
"github.com/go-kit/kit/log" |
||||
"github.com/pkg/errors" |
||||
|
||||
"github.com/grafana/loki/pkg/promtail/api" |
||||
"github.com/grafana/loki/pkg/promtail/positions" |
||||
"github.com/grafana/loki/pkg/promtail/targets/file" |
||||
) |
||||
|
||||
type GenericTargetManager interface { |
||||
Stop() |
||||
} |
||||
|
||||
type TargetManager struct { |
||||
targetManagers []GenericTargetManager |
||||
} |
||||
|
||||
func NewTargetManager( |
||||
logger log.Logger, |
||||
positions *positions.Positions, |
||||
client api.EntryHandler, |
||||
scrapeConfigs []api.ScrapeConfig, |
||||
) (*TargetManager, error) { |
||||
var targetManagers []GenericTargetManager |
||||
var fileScrapeConfigs []api.ScrapeConfig |
||||
|
||||
for _, cfg := range scrapeConfigs { |
||||
// for now every scrape config is a file target
|
||||
fileScrapeConfigs = append( |
||||
fileScrapeConfigs, |
||||
cfg, |
||||
) |
||||
} |
||||
|
||||
fileTargetManager, err := file.NewTargetManager( |
||||
logger, |
||||
positions, |
||||
client, |
||||
fileScrapeConfigs, |
||||
) |
||||
if err != nil { |
||||
return nil, errors.Wrap(err, "failed to make file target manager") |
||||
} |
||||
targetManagers = append(targetManagers, fileTargetManager) |
||||
|
||||
return &TargetManager{targetManagers: targetManagers}, nil |
||||
|
||||
} |
||||
|
||||
func (tm *TargetManager) Stop() { |
||||
for _, t := range tm.targetManagers { |
||||
go func() { |
||||
t.Stop() |
||||
}() |
||||
} |
||||
} |
Loading…
Reference in new issue