Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/282-niladrih
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for warning log de-duplication
15 changes: 15 additions & 0 deletions cmd/provisioner-localpv/app/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import (
"github.com/openebs/maya/pkg/version"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"k8s.io/client-go/rest"
"k8s.io/klog/v2"
pvController "sigs.k8s.io/sig-storage-lib-external-provisioner/v9/controller"

"github.com/openebs/dynamic-localpv-provisioner/pkg/logger"
)

var (
Expand All @@ -23,6 +26,7 @@ var (
// localpv provisioner
LeaderElectionKey = "LEADER_ELECTION_ENABLED"
usage = cmdName
dedupeWarnings bool
)

// StartProvisioner will start a new dynamic Host Path PV provisioner
Expand All @@ -39,13 +43,24 @@ func StartProvisioner() (*cobra.Command, error) {
},
}

cmd.PersistentFlags().BoolVar(&dedupeWarnings, "dedupe-warnings", false, "De-duplicate warning messages")

return cmd, nil
}

// Start will initialize and run the dynamic provisioner daemon
func Start(cmd *cobra.Command) error {
klog.Infof("Starting Provisioner...")

// De-duplicate warning messages, to avoid flooding logs.
if dedupeWarnings {
rest.SetDefaultWarningHandler(
rest.NewWarningWriter(logger.KlogWarner{}, rest.WarningWriterOptions{
Deduplicate: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a brute force dedup of all warnings?
What's the memory usage impact of this?

Color: false,
}),
)
}
// Dynamic Provisioner can run successfully if it can establish
// connection to the Kubernetes Cluster. mKube helps with
// establishing the connection either via InCluster or
Expand Down
1 change: 1 addition & 0 deletions cmd/provisioner-localpv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func run() error {

// Merge all flags from the Cobra Command to the global FlagSet
// and Parse them
pflag.CommandLine.AddFlagSet(cmd.PersistentFlags())
pflag.CommandLine.AddFlagSet(cmd.Flags())
pflag.Parse()

Expand Down
10 changes: 10 additions & 0 deletions deploy/helm/charts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ spec:
- name: {{ template "localpv.fullname" . }}
image: "{{ with .Values.localpv.image.registry | default .Values.global.imageRegistry | trimSuffix "/" }}{{ . }}/{{ end }}{{ .Values.localpv.image.repository }}:{{ .Values.localpv.image.tag }}"
imagePullPolicy: {{ .Values.localpv.image.pullPolicy }}
{{- $args := list }}
{{- if .Values.localpv.logging.dedupeWarnings }}
{{- $args = append $args "--dedupe-warnings" }}
{{- end }}
{{- if gt (len $args) 0 }}
args:
{{- range $args }}
- {{ . | quote }}
{{- end }}
{{- end }}
resources:
{{ toYaml .Values.localpv.resources | indent 10 }}
env:
Expand Down
3 changes: 3 additions & 0 deletions deploy/helm/charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ localpv:
## Labels to be added to localpv provisioner deployment pods
podLabels:
name: openebs-localpv-provisioner
logging:
# Disable duplicate warning messages
dedupeWarnings: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it not be enabled by default then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it's more expected that errors and warnings show up repeatedly in kubernetes controllers.

healthCheck:
initialDelaySeconds: 30
periodSeconds: 60
Expand Down
9 changes: 9 additions & 0 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,22 @@ var (
loggerKillSwitch = make(chan struct{})
)

// KlogWriter writes to Klog's Info stream.
type KlogWriter struct{}

func (k KlogWriter) Write(data []byte) (n int, err error) {
klog.Info(string(data))
return len(data), nil
}

// KlogWarner writes to Klog's Warning stream.
type KlogWarner struct{}

func (w KlogWarner) Write(data []byte) (n int, err error) {
klog.Warning(string(data))
return len(data), nil
}

// This needs to be set correctly to the default log flush duration
// in case it is not equal to KLOG_FLUSH_INTERVAL.
// This sets the default flush interval for logs
Expand Down
Loading