Skip to content

Commit

Permalink
feat: Detect level as structured metadata by default (grafana#12479)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyriltovena authored and rhnasc committed Apr 12, 2024
1 parent 771e9fe commit 836509c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/sources/configure/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3020,7 +3020,7 @@ The `limits_config` block configures global and per-tenant limits in Loki. The v
# would be added to Structured Metadata with name 'level' and one of the values
# from 'debug', 'info', 'warn', 'error', 'critical', 'fatal'.
# CLI flag: -validation.discover-log-levels
[discover_log_levels: <boolean> | default = false]
[discover_log_levels: <boolean> | default = true]

# Maximum number of active streams per user, per ingester. 0 to disable.
# CLI flag: -ingester.max-streams-per-user
Expand Down
13 changes: 6 additions & 7 deletions integration/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import (
"github.com/grafana/loki/v3/pkg/validation"
)

var (
configTemplate = template.Must(template.New("").Parse(`
var configTemplate = template.Must(template.New("").Parse(`
auth_enabled: true
server:
Expand Down Expand Up @@ -63,6 +62,7 @@ limits_config:
reject_old_samples: false
allow_structured_metadata: true
discover_service_name:
discover_log_levels: false
otlp_config:
resource_attributes:
attributes_config:
Expand Down Expand Up @@ -120,7 +120,6 @@ ruler:
directory: {{.sharedDataPath}}/rules
rule_path: {{.sharedDataPath}}/prom-rule
`))
)

func resetMetricRegistry() {
registry := &wrappedRegisterer{Registry: prometheus.NewRegistry()}
Expand Down Expand Up @@ -174,7 +173,7 @@ func New(logLevel level.Value, opts ...func(*Cluster)) *Cluster {

overridesFile := filepath.Join(sharedPath, "loki-overrides.yaml")

err = os.WriteFile(overridesFile, []byte(`overrides:`), 0777)
err = os.WriteFile(overridesFile, []byte(`overrides:`), 0o777)
if err != nil {
panic(fmt.Errorf("error creating overrides file: %w", err))
}
Expand Down Expand Up @@ -346,7 +345,7 @@ func (c *Component) writeConfig() error {
return fmt.Errorf("error getting merged config: %w", err)
}

if err := os.WriteFile(configFile.Name(), mergedConfig, 0644); err != nil {
if err := os.WriteFile(configFile.Name(), mergedConfig, 0o644); err != nil {
return fmt.Errorf("error writing config file: %w", err)
}

Expand Down Expand Up @@ -413,7 +412,7 @@ func (c *Component) run() error {

var config loki.ConfigWrapper

var flagset = flag.NewFlagSet("test-flags", flag.ExitOnError)
flagset := flag.NewFlagSet("test-flags", flag.ExitOnError)

if err := cfg.DynamicUnmarshal(&config, append(
c.flags,
Expand Down Expand Up @@ -522,7 +521,7 @@ func (c *Component) SetTenantLimits(tenant string, limits validation.Limits) err
return err
}

return os.WriteFile(c.overridesFile, config, 0777)
return os.WriteFile(c.overridesFile, config, 0o777)
}

func (c *Component) GetTenantLimits(tenant string) validation.Limits {
Expand Down
4 changes: 3 additions & 1 deletion pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,19 @@ func Test_IncrementTimestamp(t *testing.T) {
flagext.DefaultValues(incrementingDisabled)
incrementingDisabled.DiscoverServiceName = nil
incrementingDisabled.RejectOldSamples = false
incrementingDisabled.DiscoverLogLevels = false

incrementingEnabled := &validation.Limits{}
flagext.DefaultValues(incrementingEnabled)
incrementingEnabled.DiscoverServiceName = nil
incrementingEnabled.RejectOldSamples = false
incrementingEnabled.IncrementDuplicateTimestamp = true
incrementingEnabled.DiscoverLogLevels = false

defaultLimits := &validation.Limits{}
flagext.DefaultValues(defaultLimits)
now := time.Now()
defaultLimits.DiscoverLogLevels = false

tests := map[string]struct {
limits *validation.Limits
Expand Down Expand Up @@ -810,7 +813,6 @@ func BenchmarkShardStream(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
d.shardStream(stream, 0, "fake") //nolint:errcheck

}
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/validation/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (l *Limits) RegisterFlags(f *flag.FlagSet) {
"job",
}
f.Var((*dskit_flagext.StringSlice)(&l.DiscoverServiceName), "validation.discover-service-name", "If no service_name label exists, Loki maps a single label from the configured list to service_name. If none of the configured labels exist in the stream, label is set to unknown_service. Empty list disables setting the label.")
f.BoolVar(&l.DiscoverLogLevels, "validation.discover-log-levels", false, "Discover and add log levels during ingestion, if not present already. Levels would be added to Structured Metadata with name 'level' and one of the values from 'debug', 'info', 'warn', 'error', 'critical', 'fatal'.")
f.BoolVar(&l.DiscoverLogLevels, "validation.discover-log-levels", true, "Discover and add log levels during ingestion, if not present already. Levels would be added to Structured Metadata with name 'level' and one of the values from 'debug', 'info', 'warn', 'error', 'critical', 'fatal'.")

_ = l.RejectOldSamplesMaxAge.Set("7d")
f.Var(&l.RejectOldSamplesMaxAge, "validation.reject-old-samples.max-age", "Maximum accepted sample age before rejecting.")
Expand Down

0 comments on commit 836509c

Please sign in to comment.