-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
promtail: restore build support for non-linux platforms
Support for building promtail on non-Linux platforms (and Linux platforms where CGO has been disabled) has been added. This commit also reverts accidentally commited code in journaltarget.go that panics if a timestamp occurs before the timestamp of the previous received journal entry.
- Loading branch information
Showing
7 changed files
with
121 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// +build linux | ||
// +build linux,cgo | ||
|
||
package targets | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,45 @@ | ||
// +build !linux !cgo | ||
|
||
package targets | ||
|
||
import ( | ||
"github.com/go-kit/kit/log" | ||
"github.com/go-kit/kit/log/level" | ||
"github.com/grafana/loki/pkg/logentry/stages" | ||
"github.com/grafana/loki/pkg/promtail/api" | ||
"github.com/grafana/loki/pkg/promtail/positions" | ||
"github.com/grafana/loki/pkg/promtail/scrape" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// JournalTargetManager manages a series of JournalTargets. | ||
type JournalTargetManager struct { | ||
logger log.Logger | ||
targets map[string]*JournalTarget | ||
} | ||
type JournalTargetManager struct{} | ||
|
||
// NewJournalTargetManager creates a new JournalTargetManager. | ||
// NewJournalTargetManager returns nil as JournalTargets are not supported | ||
// on this platform. | ||
func NewJournalTargetManager( | ||
logger log.Logger, | ||
positions *positions.Positions, | ||
client api.EntryHandler, | ||
scrapeConfigs []scrape.Config, | ||
) (*JournalTargetManager, error) { | ||
tm := &JournalTargetManager{ | ||
logger: logger, | ||
targets: make(map[string]*JournalTarget), | ||
} | ||
|
||
for _, cfg := range scrapeConfigs { | ||
if cfg.JournalConfig == nil { | ||
continue | ||
} | ||
|
||
registerer := prometheus.DefaultRegisterer | ||
pipeline, err := stages.NewPipeline(log.With(logger, "component", "journal_pipeline"), cfg.PipelineStages, &cfg.JobName, registerer) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
t, err := NewJournalTarget( | ||
logger, | ||
pipeline.Wrap(client), | ||
positions, | ||
cfg.RelabelConfigs, | ||
cfg.JournalConfig, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tm.targets[cfg.JobName] = t | ||
} | ||
|
||
return tm, nil | ||
level.Warn(logger).Log("msg", "WARNING!!! Journal target manager initialized on platform without Journal support!") | ||
return &JournalTargetManager{}, nil | ||
} | ||
|
||
// Ready returns true if at least one JournalTarget is also ready. | ||
// Ready always returns false for JournalTargetManager on non-Linux | ||
// platforms. | ||
func (tm *JournalTargetManager) Ready() bool { | ||
for _, t := range tm.targets { | ||
if t.Ready() { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// Stop stops the JournalTargetManager and all of its JournalTargets. | ||
func (tm *JournalTargetManager) Stop() { | ||
for _, t := range tm.targets { | ||
if err := t.Stop(); err != nil { | ||
level.Error(t.logger).Log("msg", "error stopping JournalTarget", "err", err.Error()) | ||
} | ||
} | ||
} | ||
// Stop is a no-op on non-Linux platforms. | ||
func (tm *JournalTargetManager) Stop() {} | ||
|
||
// ActiveTargets returns the list of JournalTargets where journal data | ||
// is being read. ActiveTargets is an alias to AllTargets as | ||
// JournalTargets cannot be deactivated, only stopped. | ||
// ActiveTargets always returns nil on non-Linux platforms. | ||
func (tm *JournalTargetManager) ActiveTargets() map[string][]Target { | ||
return tm.AllTargets() | ||
return nil | ||
} | ||
|
||
// AllTargets returns the list of all targets where journal data | ||
// is currently being read. | ||
// AllTargets always returns nil on non-Linux platforms. | ||
func (tm *JournalTargetManager) AllTargets() map[string][]Target { | ||
result := make(map[string][]Target, len(tm.targets)) | ||
for k, v := range tm.targets { | ||
result[k] = []Target{v} | ||
} | ||
return result | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// +build cgo | ||
|
||
package targets | ||
|
||
import ( | ||
"github.com/go-kit/kit/log" | ||
"github.com/go-kit/kit/log/level" | ||
"github.com/grafana/loki/pkg/logentry/stages" | ||
"github.com/grafana/loki/pkg/promtail/api" | ||
"github.com/grafana/loki/pkg/promtail/positions" | ||
"github.com/grafana/loki/pkg/promtail/scrape" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// JournalTargetManager manages a series of JournalTargets. | ||
type JournalTargetManager struct { | ||
logger log.Logger | ||
targets map[string]*JournalTarget | ||
} | ||
|
||
// NewJournalTargetManager creates a new JournalTargetManager. | ||
func NewJournalTargetManager( | ||
logger log.Logger, | ||
positions *positions.Positions, | ||
client api.EntryHandler, | ||
scrapeConfigs []scrape.Config, | ||
) (*JournalTargetManager, error) { | ||
tm := &JournalTargetManager{ | ||
logger: logger, | ||
targets: make(map[string]*JournalTarget), | ||
} | ||
|
||
for _, cfg := range scrapeConfigs { | ||
if cfg.JournalConfig == nil { | ||
continue | ||
} | ||
|
||
registerer := prometheus.DefaultRegisterer | ||
pipeline, err := stages.NewPipeline(log.With(logger, "component", "journal_pipeline"), cfg.PipelineStages, &cfg.JobName, registerer) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
t, err := NewJournalTarget( | ||
logger, | ||
pipeline.Wrap(client), | ||
positions, | ||
cfg.RelabelConfigs, | ||
cfg.JournalConfig, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tm.targets[cfg.JobName] = t | ||
} | ||
|
||
return tm, nil | ||
} | ||
|
||
// Ready returns true if at least one JournalTarget is also ready. | ||
func (tm *JournalTargetManager) Ready() bool { | ||
for _, t := range tm.targets { | ||
if t.Ready() { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// Stop stops the JournalTargetManager and all of its JournalTargets. | ||
func (tm *JournalTargetManager) Stop() { | ||
for _, t := range tm.targets { | ||
if err := t.Stop(); err != nil { | ||
level.Error(t.logger).Log("msg", "error stopping JournalTarget", "err", err.Error()) | ||
} | ||
} | ||
} | ||
|
||
// ActiveTargets returns the list of JournalTargets where journal data | ||
// is being read. ActiveTargets is an alias to AllTargets as | ||
// JournalTargets cannot be deactivated, only stopped. | ||
func (tm *JournalTargetManager) ActiveTargets() map[string][]Target { | ||
return tm.AllTargets() | ||
} | ||
|
||
// AllTargets returns the list of all targets where journal data | ||
// is currently being read. | ||
func (tm *JournalTargetManager) AllTargets() map[string][]Target { | ||
result := make(map[string][]Target, len(tm.targets)) | ||
for k, v := range tm.targets { | ||
result[k] = []Target{v} | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters