Skip to content

Commit

Permalink
feat: add latest syslog-ng stats syntax by default but do not enforce…
Browse files Browse the repository at this point in the history
… it if the old syntax is used explicitly

Signed-off-by: Peter Wilcsinszky <peter.wilcsinszky@axoflow.com>
  • Loading branch information
pepov committed Jun 2, 2023
1 parent fb559c0 commit cb0f36b
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 8 deletions.
7 changes: 7 additions & 0 deletions config/crd/bases/logging.banzaicloud.io_loggings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13660,6 +13660,13 @@ spec:
type: object
globalOptions:
properties:
stats:
properties:
freq:
type: integer
level:
type: integer
type: object
stats_freq:
type: integer
stats_level:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13660,6 +13660,13 @@ spec:
type: object
globalOptions:
properties:
stats:
properties:
freq:
type: integer
level:
type: integer
type: object
stats_freq:
type: integer
stats_level:
Expand Down
11 changes: 10 additions & 1 deletion pkg/sdk/logging/api/v1beta1/syslogng_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ type SyslogNGTLS struct {
}

type GlobalOptions struct {
// deprecated use stats/level from 4.1+
StatsLevel *int `json:"stats_level,omitempty"`
StatsFreq *int `json:"stats_freq,omitempty"`
// deprecated use stats/freq from 4.1+
StatsFreq *int `json:"stats_freq,omitempty"`
// TODO switch to this by default
Stats *Stats `json:"stats,omitempty"`
}

type Stats struct {
Level *int `json:"level,omitempty"`
Freq *int `json:"freq,omitempty"`
}
30 changes: 30 additions & 0 deletions pkg/sdk/logging/api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions pkg/sdk/logging/model/syslogng/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,15 @@ func configRenderer(in Input) (render.Renderer, error) {
// TODO: this should happen at the spec level, in something like `SyslogNGSpec.FinalGlobalOptions() GlobalOptions`
if in.Logging.Spec.SyslogNGSpec.Metrics != nil {
setDefault(&in.Logging.Spec.SyslogNGSpec.GlobalOptions, &v1beta1.GlobalOptions{})
setDefault(&in.Logging.Spec.SyslogNGSpec.GlobalOptions.StatsFreq, amp(10))
setDefault(&in.Logging.Spec.SyslogNGSpec.GlobalOptions.StatsLevel, amp(2))
if in.Logging.Spec.SyslogNGSpec.GlobalOptions.StatsFreq != nil ||
in.Logging.Spec.SyslogNGSpec.GlobalOptions.StatsLevel != nil {
setDefault(&in.Logging.Spec.SyslogNGSpec.GlobalOptions.StatsFreq, amp(10))
setDefault(&in.Logging.Spec.SyslogNGSpec.GlobalOptions.StatsLevel, amp(2))
} else {
setDefault(&in.Logging.Spec.SyslogNGSpec.GlobalOptions.Stats, &v1beta1.Stats{})
setDefault(&in.Logging.Spec.SyslogNGSpec.GlobalOptions.Stats.Freq, amp(10))
setDefault(&in.Logging.Spec.SyslogNGSpec.GlobalOptions.Stats.Level, amp(2))
}
}

globalOptions := renderAny(in.Logging.Spec.SyslogNGSpec.GlobalOptions, in.SecretLoaderFactory.SecretLoaderForNamespace(in.Logging.Namespace))
Expand Down
79 changes: 76 additions & 3 deletions pkg/sdk/logging/model/syslogng/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import (
"strings"
"testing"

"github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
"github.com/kube-logging/logging-operator/pkg/sdk/logging/model/syslogng/filter"
"github.com/kube-logging/logging-operator/pkg/sdk/logging/model/syslogng/output"
"github.com/cisco-open/operator-tools/pkg/secret"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
"github.com/kube-logging/logging-operator/pkg/sdk/logging/model/syslogng/filter"
"github.com/kube-logging/logging-operator/pkg/sdk/logging/model/syslogng/output"
)

func TestRenderConfigInto(t *testing.T) {
Expand Down Expand Up @@ -168,6 +169,78 @@ options {
stats_freq(0);
};
source "main_input" {
channel {
source {
network(flags("no-parse") port(601) transport("tcp"));
};
parser {
json-parser(prefix("json."));
};
};
};
`,
},
"global options default": {
input: Input{
Logging: v1beta1.Logging{
Spec: v1beta1.LoggingSpec{
SyslogNGSpec: &v1beta1.SyslogNGSpec{
Metrics: &v1beta1.Metrics{
Path: "/metrics",
},
GlobalOptions: &v1beta1.GlobalOptions{},
},
},
},
SourcePort: 601,
SecretLoaderFactory: &TestSecretLoaderFactory{},
},
wantOut: `@version: current
@include "scl.conf"
options {
stats(level(2) freq(10));
};
source "main_input" {
channel {
source {
network(flags("no-parse") port(601) transport("tcp"));
};
parser {
json-parser(prefix("json."));
};
};
};
`,
},
"global options_new_stats": {
input: Input{
Logging: v1beta1.Logging{
Spec: v1beta1.LoggingSpec{
SyslogNGSpec: &v1beta1.SyslogNGSpec{
GlobalOptions: &v1beta1.GlobalOptions{
Stats: &v1beta1.Stats{
Level: amp(3),
Freq: amp(0),
},
},
},
},
},
SourcePort: 601,
SecretLoaderFactory: &TestSecretLoaderFactory{},
},
wantOut: `@version: current
@include "scl.conf"
options {
stats(level(3) freq(0));
};
source "main_input" {
channel {
source {
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/static/gen/crds/generated.go

Large diffs are not rendered by default.

0 comments on commit cb0f36b

Please sign in to comment.