Skip to content

Commit 635ef53

Browse files
authored
Merge pull request #144 from cybertec-postgresql/PatroniJSONLogs
Patroni json logs
2 parents 40b5674 + 9709818 commit 635ef53

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

pkg/apis/cpo.opensource.cybertec.at/v1/crds.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,49 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
707707
"ttl": {
708708
Type: "integer",
709709
},
710+
"log": {
711+
Type: "object",
712+
Properties: map[string]apiextv1.JSONSchemaProps{
713+
"type": {
714+
Type: "string",
715+
Enum: []apiextv1.JSON{
716+
{Raw: []byte(`"plain"`)},
717+
{Raw: []byte(`"json"`)},
718+
},
719+
},
720+
"level": {
721+
Type: "string",
722+
Enum: []apiextv1.JSON{
723+
{Raw: []byte(`"DEBUG"`)},
724+
{Raw: []byte(`"INFO"`)},
725+
{Raw: []byte(`"WARNING"`)},
726+
{Raw: []byte(`"ERROR"`)},
727+
{Raw: []byte(`"CRITICAL"`)},
728+
},
729+
},
730+
"traceback_level": {
731+
Type: "string",
732+
Enum: []apiextv1.JSON{
733+
{Raw: []byte(`"DEBUG"`)},
734+
{Raw: []byte(`"INFO"`)},
735+
{Raw: []byte(`"WARNING"`)},
736+
{Raw: []byte(`"ERROR"`)},
737+
{Raw: []byte(`"CRITICAL"`)},
738+
},
739+
},
740+
"static_fields": {
741+
Type: "object",
742+
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
743+
Schema: &apiextv1.JSONSchemaProps{
744+
Type: "string",
745+
},
746+
},
747+
},
748+
"deduplicate_heartbeat_logs": {
749+
Type: "boolean",
750+
},
751+
},
752+
},
710753
},
711754
},
712755
"podAnnotations": {

pkg/apis/cpo.opensource.cybertec.at/v1/postgresql_type.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ type Patroni struct {
182182
SynchronousNodeCount uint32 `json:"synchronous_node_count,omitempty" defaults:"1"`
183183
Multisite *Multisite `json:"multisite,omitempty"`
184184
FailsafeMode *bool `json:"failsafe_mode,omitempty"`
185+
Log *PatroniLog `json:"log,omitempty"`
185186
}
186187

187188
// StandbyDescription contains remote primary config or s3/gs wal path
@@ -342,3 +343,11 @@ type EtcdConfig struct {
342343
Protocol *string `json:"protocol,omitempty"`
343344
CertSecretName *string `json:"certSecretName,omitempty"`
344345
}
346+
347+
type PatroniLog struct {
348+
Type string `json:"type,omitempty"`
349+
Level string `json:"level,omitempty"`
350+
TracebackLevel string `json:"traceback_level,omitempty"`
351+
StaticFields map[string]string `json:"static_fields,omitempty"`
352+
DeduplicateHeartbeatLogs *bool `json:"deduplicate_heartbeat_logs,omitempty"`
353+
}

pkg/cluster/k8sres.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,22 @@ type pgBootstrap struct {
8181
type spiloConfiguration struct {
8282
PgLocalConfiguration map[string]interface{} `json:"postgresql"`
8383
Bootstrap pgBootstrap `json:"bootstrap"`
84+
Log *spiloLogConfiguration `json:"log,omitempty"`
8485
}
8586

8687
type TDEConfig struct {
8788
Enabled bool
8889
KeyBits string
8990
}
9091

92+
type spiloLogConfiguration struct {
93+
Type string `json:"type,omitempty"`
94+
Level string `json:"level,omitempty"`
95+
TracebackLevel string `json:"traceback_level,omitempty"`
96+
StaticFields map[string]string `json:"static_fields,omitempty"`
97+
DeduplicateHeartbeatLogs *bool `json:"deduplicate_heartbeat_logs,omitempty"`
98+
}
99+
91100
func (c *Cluster) statefulSetName() string {
92101
return c.Name
93102
}
@@ -468,6 +477,26 @@ PatroniInitDBParams:
468477
config.PgLocalConfiguration[patroniPGHBAConfParameterName] = patroni.PgHba
469478
}
470479

480+
if patroni.Log != nil {
481+
logConfig := &spiloLogConfiguration{}
482+
if patroni.Log.Type != "" {
483+
logConfig.Type = patroni.Log.Type
484+
}
485+
if patroni.Log.Level != "" {
486+
logConfig.Level = patroni.Log.Level
487+
}
488+
if patroni.Log.TracebackLevel != "" {
489+
logConfig.TracebackLevel = patroni.Log.TracebackLevel
490+
}
491+
if patroni.Log.StaticFields != nil {
492+
logConfig.StaticFields = patroni.Log.StaticFields
493+
}
494+
if patroni.Log.DeduplicateHeartbeatLogs != nil {
495+
logConfig.DeduplicateHeartbeatLogs = patroni.Log.DeduplicateHeartbeatLogs
496+
}
497+
config.Log = logConfig
498+
}
499+
471500
res, err := json.Marshal(config)
472501
return string(res), err
473502
}

0 commit comments

Comments
 (0)