Skip to content

Commit

Permalink
Removes file size check for pipe, not provided by linux. (#1893)
Browse files Browse the repository at this point in the history
* Removes file size check for pipe, not provided by linux.

Signed-off-by: Cyril Tovena <[email protected]>

* Disable color on windows.

Signed-off-by: Cyril Tovena <[email protected]>
(cherry picked from commit 7573078)
  • Loading branch information
cyriltovena authored and slim-bean committed Apr 6, 2020
1 parent 375daae commit 8e80160
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
20 changes: 17 additions & 3 deletions pkg/promtail/client/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"fmt"
"os"
"runtime"
"sync"
"text/tabwriter"
"time"
Expand All @@ -13,6 +14,18 @@ import (
"gopkg.in/yaml.v2"
)

var (
yellow = color.New(color.FgYellow)
blue = color.New(color.FgBlue)
)

func init() {
if runtime.GOOS == "windows" {
yellow.DisableColor()
blue.DisableColor()
}
}

type logger struct {
*tabwriter.Writer
sync.Mutex
Expand All @@ -26,7 +39,8 @@ func NewLogger(cfgs ...Config) (Client, error) {
return nil, err
}
c.Stop()
fmt.Println(color.YellowString("Clients configured:"))

fmt.Println(yellow.Sprint("Clients configured:"))
for _, cfg := range cfgs {
yaml, err := yaml.Marshal(cfg)
if err != nil {
Expand All @@ -45,9 +59,9 @@ func (*logger) Stop() {}
func (l *logger) Handle(labels model.LabelSet, time time.Time, entry string) error {
l.Lock()
defer l.Unlock()
fmt.Fprint(l.Writer, color.BlueString(time.Format("2006-01-02T15:04:05")))
fmt.Fprint(l.Writer, blue.Sprint(time.Format("2006-01-02T15:04:05")))
fmt.Fprint(l.Writer, "\t")
fmt.Fprint(l.Writer, color.YellowString(labels.String()))
fmt.Fprint(l.Writer, yellow.Sprint(labels.String()))
fmt.Fprint(l.Writer, "\t")
fmt.Fprint(l.Writer, entry)
fmt.Fprint(l.Writer, "\n")
Expand Down
2 changes: 2 additions & 0 deletions pkg/promtail/targets/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package targets
import (
"github.com/cortexproject/cortex/pkg/util"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/pkg/errors"

"github.com/grafana/loki/pkg/promtail/api"
Expand Down Expand Up @@ -38,6 +39,7 @@ func NewTargetManagers(
var syslogScrapeConfigs []scrape.Config

if isStdinPipe() {
level.Debug(util.Logger).Log("msg", "detected pipe from stdin")
stdin, err := newStdinTargetManager(app, client, scrapeConfigs)
if err != nil {
return nil, err
Expand Down
6 changes: 1 addition & 5 deletions pkg/promtail/targets/stdin_target_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ func isStdinPipe() bool {
level.Warn(util.Logger).Log("err", err)
return false
}
m := info.Mode()
if m&os.ModeCharDevice != 0 || info.Size() <= 0 {
return false
}
return true
return info.Mode()&os.ModeCharDevice == 0
}

type Shutdownable interface {
Expand Down

0 comments on commit 8e80160

Please sign in to comment.