Integration Tests: allow loki logs to be optionally output in integration tests (#8793)

**What this PR does / why we need it**:
Debugging integration tests can be difficult without Loki's logs being
output.

Changing the call from `cluster.New()` to `cluster.New(true,
level.WarnValue())` now allows the author the option to temporarily or
permanently enable logging for their test, as well as configure a level
filter to control the noise.

Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
pull/8793/merge
Danny Kopping 2 years ago committed by GitHub
parent 2a1bd3da00
commit 61311957a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      integration/cluster/cluster.go
  2. 2
      integration/loki_micro_services_delete_test.go
  3. 2
      integration/loki_micro_services_test.go
  4. 2
      integration/loki_rule_eval_test.go
  5. 2
      integration/loki_simple_scalable_test.go
  6. 2
      integration/loki_single_binary_test.go
  7. 2
      integration/multi_tenant_queries_test.go
  8. 2
      integration/per_request_limits_test.go

@ -16,6 +16,8 @@ import (
"text/template" "text/template"
"time" "time"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/multierror" "github.com/grafana/dskit/multierror"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
@ -24,6 +26,7 @@ import (
"github.com/grafana/loki/pkg/loki" "github.com/grafana/loki/pkg/loki"
"github.com/grafana/loki/pkg/util/cfg" "github.com/grafana/loki/pkg/util/cfg"
util_log "github.com/grafana/loki/pkg/util/log"
"github.com/grafana/loki/pkg/validation" "github.com/grafana/loki/pkg/validation"
) )
@ -141,7 +144,11 @@ type Cluster struct {
waitGroup sync.WaitGroup waitGroup sync.WaitGroup
} }
func New() *Cluster { func New(logLevel level.Value) *Cluster {
if logLevel != nil {
util_log.Logger = level.NewFilter(log.NewLogfmtLogger(os.Stderr), level.Allow(logLevel))
}
wrapRegistry() wrapRegistry()
sharedPath, err := os.MkdirTemp("", "loki-shared-data") sharedPath, err := os.MkdirTemp("", "loki-shared-data")
if err != nil { if err != nil {

@ -17,7 +17,7 @@ import (
) )
func TestMicroServicesDeleteRequest(t *testing.T) { func TestMicroServicesDeleteRequest(t *testing.T) {
clu := cluster.New() clu := cluster.New(nil)
defer func() { defer func() {
assert.NoError(t, clu.Cleanup()) assert.NoError(t, clu.Cleanup())
storage.ResetBoltDBIndexClientWithShipper() storage.ResetBoltDBIndexClientWithShipper()

@ -13,7 +13,7 @@ import (
) )
func TestMicroServicesIngestQuery(t *testing.T) { func TestMicroServicesIngestQuery(t *testing.T) {
clu := cluster.New() clu := cluster.New(nil)
defer func() { defer func() {
assert.NoError(t, clu.Cleanup()) assert.NoError(t, clu.Cleanup())
}() }()

@ -34,7 +34,7 @@ func TestRemoteRuleEval(t *testing.T) {
// In this test we stub out a remote-write receiver and check that the expected data is sent to it. // In this test we stub out a remote-write receiver and check that the expected data is sent to it.
// Both the local and the remote rule evaluation modes should produce the same result. // Both the local and the remote rule evaluation modes should produce the same result.
func testRuleEval(t *testing.T, mode string) { func testRuleEval(t *testing.T, mode string) {
clu := cluster.New() clu := cluster.New(nil)
t.Cleanup(func() { t.Cleanup(func() {
assert.NoError(t, clu.Cleanup()) assert.NoError(t, clu.Cleanup())
}) })

@ -13,7 +13,7 @@ import (
) )
func TestSimpleScalable_IngestQuery(t *testing.T) { func TestSimpleScalable_IngestQuery(t *testing.T) {
clu := cluster.New() clu := cluster.New(nil)
defer func() { defer func() {
assert.NoError(t, clu.Cleanup()) assert.NoError(t, clu.Cleanup())
}() }()

@ -13,7 +13,7 @@ import (
) )
func TestSingleBinaryIngestQuery(t *testing.T) { func TestSingleBinaryIngestQuery(t *testing.T) {
clu := cluster.New() clu := cluster.New(nil)
defer func() { defer func() {
assert.NoError(t, clu.Cleanup()) assert.NoError(t, clu.Cleanup())
}() }()

@ -13,7 +13,7 @@ import (
) )
func TestMultiTenantQuery(t *testing.T) { func TestMultiTenantQuery(t *testing.T) {
clu := cluster.New() clu := cluster.New(nil)
defer func() { defer func() {
assert.NoError(t, clu.Cleanup()) assert.NoError(t, clu.Cleanup())
}() }()

@ -15,7 +15,7 @@ import (
) )
func TestPerRequestLimits(t *testing.T) { func TestPerRequestLimits(t *testing.T) {
clu := cluster.New() clu := cluster.New(nil)
defer func() { defer func() {
assert.NoError(t, clu.Cleanup()) assert.NoError(t, clu.Cleanup())
}() }()

Loading…
Cancel
Save