Skip to content

Commit 73df6a0

Browse files
Change default logging level to info. Add --log.sampling (default true) (#1577)
Co-authored-by: Adam Janikowski <[email protected]>
1 parent abd8562 commit 73df6a0

15 files changed

+404
-72
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- (Feature) (ML) Featurization Job Type
88
- (Bugfix) Don't abort plan in case of optional action timeout
99
- (Documentation) Use relative links for generated docs
10+
- (Improvement) Change default logging level to info. Add --log.sampling (default true). Adjust log levels.
1011

1112
## [1.2.36](https://github.com/arangodb/kube-arangodb/tree/1.2.36) (2024-01-08)
1213
- (Documentation) Improvements and fixes for rendered documentation (GH pages)

cmd/cmd.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -75,7 +75,7 @@ const (
7575
defaultServerPort = 8528
7676
defaultAPIHTTPPort = 8628
7777
defaultAPIGRPCPort = 8728
78-
defaultLogLevel = "debug"
78+
defaultLogLevel = "info"
7979
defaultAdminSecretName = "arangodb-operator-dashboard"
8080
defaultAPIJWTSecretName = "arangodb-operator-api-jwt"
8181
defaultAPIJWTKeySecretName = "arangodb-operator-api-jwt-key"
@@ -98,6 +98,7 @@ var (
9898

9999
logFormat string
100100
logLevels []string
101+
logSampling bool
101102
serverOptions struct {
102103
host string
103104
port int
@@ -191,6 +192,7 @@ func init() {
191192
f.BoolVar(&serverOptions.allowAnonymous, "server.allow-anonymous-access", false, "Allow anonymous access to the dashboard")
192193
f.StringVar(&logFormat, "log.format", "pretty", "Set log format. Allowed values: 'pretty', 'JSON'. If empty, default format is used")
193194
f.StringArrayVar(&logLevels, "log.level", []string{defaultLogLevel}, fmt.Sprintf("Set log levels in format <level> or <logger>=<level>. Possible loggers: %s", strings.Join(logging.Global().Names(), ", ")))
195+
f.BoolVar(&logSampling, "log.sampling", true, "If true, operator will try to minimize duplication of logging events")
194196
f.BoolVar(&apiOptions.enabled, "api.enabled", true, "Enable operator HTTP and gRPC API")
195197
f.IntVar(&apiOptions.httpPort, "api.http-port", defaultAPIHTTPPort, "HTTP API port to listen on")
196198
f.IntVar(&apiOptions.grpcPort, "api.grpc-port", defaultAPIGRPCPort, "gRPC API port to listen on")
@@ -312,7 +314,10 @@ func executeMain(cmd *cobra.Command, args []string) {
312314
} else if strings.ToLower(logFormat) != "pretty" && logFormat != "" {
313315
logger.Fatal("Unknown log format: %s", logFormat)
314316
}
315-
logging.Global().ApplyLogLevels(levels)
317+
logging.Global().Configure(logging.Config{
318+
Levels: levels,
319+
Sampling: logSampling,
320+
})
316321

317322
podNameParts := strings.Split(name, "-")
318323
operatorID := podNameParts[len(podNameParts)-1]

pkg/deployment/deployment_inspector.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -54,7 +54,7 @@ func (d *Deployment) inspectDeployment(lastInterval util.Interval) util.Interval
5454
start := time.Now()
5555

5656
if delay := d.delayer.Wait(); delay > 0 {
57-
log.Info().Dur("delay", delay).Msgf("Reconciliation loop execution was delayed")
57+
log.Debug().Dur("delay", delay).Msgf("Reconciliation loop execution was delayed")
5858
}
5959
defer d.delayer.Delay(d.config.ReconciliationDelay)
6060

@@ -342,7 +342,7 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
342342
} else if err, updated := d.reconciler.CreatePlan(ctx); err != nil {
343343
return minInspectionInterval, errors.Wrapf(err, "Plan creation failed")
344344
} else if updated {
345-
d.log.Info("Plan generated, reconciling")
345+
d.log.Debug("Plan generated, reconciling")
346346
return minInspectionInterval, nil
347347
}
348348

pkg/deployment/logger.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -21,13 +21,15 @@
2121
package deployment
2222

2323
import (
24+
"time"
25+
2426
"github.com/rs/zerolog"
2527

2628
"github.com/arangodb/kube-arangodb/pkg/logging"
2729
)
2830

2931
var (
30-
logger = logging.Global().RegisterAndGetLogger("deployment", logging.Info)
32+
logger = logging.Global().RegisterAndGetLogger("deployment", logging.Info, logging.WithSamplingPeriod(time.Second*10))
3133
)
3234

3335
func (d *Deployment) sectionLogger(section string) logging.Logger {

pkg/deployment/reconcile/action_helper.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ package reconcile
2222

2323
import (
2424
"context"
25+
"time"
2526

2627
"github.com/rs/zerolog"
2728

@@ -31,7 +32,7 @@ import (
3132
)
3233

3334
var (
34-
logger = logging.Global().RegisterAndGetLogger("action", logging.Info)
35+
logger = logging.Global().RegisterAndGetLogger("action", logging.Info, logging.WithSamplingPeriod(time.Second*10))
3536
)
3637

3738
type actionEmpty struct {

pkg/deployment/reconcile/plan_builder_maintenance.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -146,7 +146,7 @@ func (r *Reconciler) createMaintenanceManagementPlan(ctx context.Context, apiObj
146146
}
147147

148148
if agencyState.Target.HotBackup.Create.Exists() {
149-
r.log.Info("HotBackup in progress")
149+
r.log.Debug("HotBackup in progress")
150150
return nil
151151
}
152152

@@ -155,7 +155,7 @@ func (r *Reconciler) createMaintenanceManagementPlan(ctx context.Context, apiObj
155155

156156
if (cok && c.IsTrue()) != enabled {
157157
// Condition not yet propagated
158-
r.log.Info("Condition not yet propagated")
158+
r.log.Str("condition", api.ConditionTypeMaintenance.String()).Debug("Condition not yet propagated")
159159
return nil
160160
}
161161

pkg/deployment/reconcile/plan_executor.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (d *Reconciler) executePlanStatus(ctx context.Context, pg planner) (bool, b
192192
loopStatus = d.context.GetStatus()
193193

194194
if pg.Set(&loopStatus, newPlan) {
195-
d.planLogger.Info("Updating plan")
195+
d.planLogger.Debug("Updating plan")
196196
if err := d.context.UpdateStatus(ctx, loopStatus); err != nil {
197197
d.planLogger.Err(err).Debug("Failed to update CR status")
198198
return false, false, errors.WithStack(err)
@@ -273,7 +273,7 @@ func (d *Reconciler) executePlan(ctx context.Context, statusPlan api.Plan, pg pl
273273
if ok {
274274
c.GetThrottles().Invalidate(components...)
275275

276-
d.planLogger.Info("Reloading cached status")
276+
d.planLogger.Debug("Reloading cached status")
277277
if err := c.Refresh(ctx); err != nil {
278278
d.planLogger.Err(err).Warn("Unable to reload cached status")
279279
return plan, recall, false, nil
@@ -338,7 +338,7 @@ func (d *Reconciler) executeOptionalAction(ctx context.Context, planAction api.A
338338

339339
func (d *Reconciler) executeAction(ctx context.Context, planAction api.Action, action Action) (done, abort, callAgain, retry bool, err error) {
340340
log := d.planLogger.Str("action", string(planAction.Type)).Str("member", planAction.MemberID)
341-
log.Info("Executing action")
341+
log.Debug("Executing action")
342342

343343
if !planAction.IsStarted() {
344344
// Not started yet
@@ -356,10 +356,10 @@ func (d *Reconciler) executeAction(ctx context.Context, planAction api.Action, a
356356
}
357357

358358
if ready {
359-
log.Bool("ready", ready).Info("Action Start completed")
359+
log.Bool("ready", ready).Debug("Action Start completed")
360360
return true, false, false, false, nil
361361
}
362-
log.Bool("ready", ready).Info("Action Started")
362+
log.Bool("ready", ready).Debug("Action Started")
363363

364364
return false, false, true, false, nil
365365
}

pkg/deployment/reconcile/reconciler.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ package reconcile
2222

2323
import (
2424
"context"
25+
"time"
2526

2627
"github.com/rs/zerolog"
2728
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -30,7 +31,7 @@ import (
3031
"github.com/arangodb/kube-arangodb/pkg/logging"
3132
)
3233

33-
var reconcileLogger = logging.Global().RegisterAndGetLogger("deployment-reconcile", logging.Info)
34+
var reconcileLogger = logging.Global().RegisterAndGetLogger("deployment-reconcile", logging.Info, logging.WithSamplingPeriod(time.Second*10))
3435

3536
// Reconciler is the service that takes care of bring the a deployment
3637
// in line with its (changed) specification.

pkg/deployment/resources/inspector/inspector.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -63,8 +63,8 @@ const (
6363
)
6464

6565
var (
66-
logger = logging.Global().RegisterAndGetLogger("inspector", logging.Info)
67-
clientLogger = logging.Global().RegisterAndGetLogger("k8s-client", logging.Info)
66+
logger = logging.Global().RegisterAndGetLogger("inspector", logging.Info, logging.WithSamplingPeriod(time.Second*10))
67+
clientLogger = logging.Global().RegisterAndGetLogger("k8s-client", logging.Info, logging.WithSamplingPeriod(time.Second*10))
6868
)
6969

7070
func (i inspectorLoaders) Get(name string) int {

pkg/deployment/resources/logger.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -21,13 +21,15 @@
2121
package resources
2222

2323
import (
24+
"time"
25+
2426
"github.com/rs/zerolog"
2527

2628
"github.com/arangodb/kube-arangodb/pkg/logging"
2729
)
2830

2931
var (
30-
logger = logging.Global().RegisterAndGetLogger("deployment-resources", logging.Info)
32+
logger = logging.Global().RegisterAndGetLogger("deployment-resources", logging.Info, logging.WithSamplingPeriod(time.Second*10))
3133
)
3234

3335
func (r *Resources) WrapLogger(in *zerolog.Event) *zerolog.Event {

pkg/logging/level.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -20,7 +20,9 @@
2020

2121
package logging
2222

23-
import "github.com/rs/zerolog"
23+
import (
24+
"github.com/rs/zerolog"
25+
)
2426

2527
type Level zerolog.Level
2628

@@ -40,3 +42,21 @@ const (
4042
func (l Level) String() string {
4143
return zerolog.Level(l).String()
4244
}
45+
46+
func WithLevel(l *zerolog.Logger, level Level) *zerolog.Event {
47+
switch level {
48+
case Trace:
49+
return l.Trace()
50+
case Debug:
51+
return l.Debug()
52+
case Info:
53+
return l.Info()
54+
case Warn:
55+
return l.Warn()
56+
case Error:
57+
return l.Error()
58+
case Fatal:
59+
return l.Fatal()
60+
}
61+
return nil
62+
}

0 commit comments

Comments
 (0)