-
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.
* --dry-run Promtail. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Remove changed on gomod Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fixes flaky test Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Ensure position file is readonly when doing dry-run Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Add information about dry run mode in the troubleshooting section. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Add more spaces. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fixes journaltarget refactor. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fixes journaltarget refactor. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fixes journaltarget refactor. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
- Loading branch information
1 parent
636ed15
commit 4210fce
Showing
15 changed files
with
245 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"sync" | ||
"text/tabwriter" | ||
"time" | ||
|
||
"github.com/cortexproject/cortex/pkg/util" | ||
"github.com/fatih/color" | ||
"github.com/prometheus/common/model" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type logger struct { | ||
*tabwriter.Writer | ||
sync.Mutex | ||
} | ||
|
||
// NewLogger creates a new client logger that logs entries instead of sending them. | ||
func NewLogger(cfgs ...Config) (Client, error) { | ||
// make sure the clients config is valid | ||
c, err := NewMulti(util.Logger, cfgs...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
c.Stop() | ||
fmt.Println(color.YellowString("Clients configured:")) | ||
for _, cfg := range cfgs { | ||
yaml, err := yaml.Marshal(cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
fmt.Println("----------------------") | ||
fmt.Println(string(yaml)) | ||
} | ||
return &logger{ | ||
Writer: tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0), | ||
}, nil | ||
} | ||
|
||
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, "\t") | ||
fmt.Fprint(l.Writer, color.YellowString(labels.String())) | ||
fmt.Fprint(l.Writer, "\t") | ||
fmt.Fprint(l.Writer, entry) | ||
fmt.Fprint(l.Writer, "\n") | ||
l.Flush() | ||
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,21 @@ | ||
package client | ||
|
||
import ( | ||
"net/url" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cortexproject/cortex/pkg/util/flagext" | ||
"github.com/prometheus/common/model" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewLogger(t *testing.T) { | ||
_, err := NewLogger([]Config{}...) | ||
require.Error(t, err) | ||
|
||
l, err := NewLogger([]Config{{URL: flagext.URLValue{URL: &url.URL{Host: "string"}}}}...) | ||
require.NoError(t, err) | ||
err = l.Handle(model.LabelSet{"foo": "bar"}, time.Now(), "entry") | ||
require.NoError(t, err) | ||
} |
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
Oops, something went wrong.