Skip to content

Commit

Permalink
test tenant const
Browse files Browse the repository at this point in the history
  • Loading branch information
salvacorts committed Oct 21, 2024
1 parent d2da933 commit e754f39
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions pkg/pattern/drain/drain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ import (
"github.com/grafana/loki/v3/pkg/logql/log/pattern"
)

const (
testTenant = "fake"
)

func TestDrain_TrainExtractsPatterns(t *testing.T) {
t.Parallel()

// Set this so the test will print the patterns found, in string slice format for easy copy-paste
outputPatternsForTestUpdate := false

tests := []struct {
drain *Drain
inputFile string
patterns []string
format string
}{
{
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputFile: `testdata/agent-logfmt.txt`,
format: FormatLogfmt,
patterns: []string{
Expand Down Expand Up @@ -56,7 +59,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
},
},
{
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputFile: `testdata/ingester-logfmt.txt`,
format: FormatLogfmt,
patterns: []string{
Expand All @@ -66,7 +69,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
},
},
{
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputFile: `testdata/drone-json.txt`,
format: FormatJSON,
patterns: []string{
Expand All @@ -79,7 +82,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
},
},
{
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputFile: "testdata/distributor-logfmt.txt",
format: FormatLogfmt,
patterns: []string{
Expand All @@ -91,7 +94,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
},
},
{
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputFile: "testdata/journald.txt",
format: FormatUnknown,
patterns: []string{
Expand Down Expand Up @@ -211,7 +214,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
},
},
{
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputFile: "testdata/kafka.txt",
format: FormatUnknown,
patterns: []string{
Expand All @@ -232,7 +235,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
},
},
{
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputFile: "testdata/kubernetes.txt",
format: FormatUnknown,
patterns: []string{
Expand Down Expand Up @@ -273,15 +276,15 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
},
},
{
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputFile: "testdata/vault.txt",
format: FormatUnknown,
patterns: []string{
`<_> [INFO] expiration: revoked lease: lease_id=<_>`,
},
},
{
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputFile: "testdata/calico.txt",
format: FormatUnknown,
patterns: []string{
Expand Down Expand Up @@ -374,7 +377,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
},
},
{
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputFile: "testdata/grafana-ruler.txt",
format: FormatLogfmt,
patterns: []string{
Expand Down Expand Up @@ -470,7 +473,7 @@ func TestDrain_TrainGeneratesPatternsMatchableByLokiPatternFilter(t *testing.T)
}{
{
name: "should extract patterns that all lines match",
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputLines: []string{
"test 1 test test",
"test 2 test test",
Expand All @@ -480,7 +483,7 @@ func TestDrain_TrainGeneratesPatternsMatchableByLokiPatternFilter(t *testing.T)
},
{
name: "should extract patterns that match if line ends with newlines",
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputLines: []string{
`test 1 test test
`,
Expand All @@ -494,7 +497,7 @@ func TestDrain_TrainGeneratesPatternsMatchableByLokiPatternFilter(t *testing.T)
},
{
name: "should extract patterns that match if line ends with empty space",
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputLines: []string{
`test 1 test test `,
`test 2 test test `,
Expand All @@ -504,7 +507,7 @@ func TestDrain_TrainGeneratesPatternsMatchableByLokiPatternFilter(t *testing.T)
},
{
name: "should extract patterns that match if line starts with empty space",
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputLines: []string{
` test 1 test test`,
` test 2 test test`,
Expand All @@ -514,7 +517,7 @@ func TestDrain_TrainGeneratesPatternsMatchableByLokiPatternFilter(t *testing.T)
},
{
name: "Scheduler patterns are matchable",
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputLines: []string{
`ts=2024-05-30T12:50:36.648377186Z caller=scheduler_processor.go:143 level=warn msg="error contacting scheduler" err="rpc error: code = Unavailable desc = connection error: desc = \"error reading server preface: EOF\"" addr=10.0.151.101:9095`,
`ts=2024-05-30T12:50:36.350575929Z caller=scheduler_processor.go:143 level=warn msg="error contacting scheduler" err="rpc error: code = Unavailable desc = connection error: desc = \"error reading server preface: EOF\"" addr=10.0.151.101:9095`,
Expand Down Expand Up @@ -611,7 +614,7 @@ func TestDrain_PruneTreeClearsOldBranches(t *testing.T) {
}{
{
name: "should prune old branches",
drain: New("", DefaultConfig(), &fakeLimits{}, "", nil),
drain: New(testTenant, DefaultConfig(), &fakeLimits{}, "", nil),
inputLines: []string{
"test test test A",
"test test test B",
Expand Down

0 comments on commit e754f39

Please sign in to comment.