Skip to content

Commit dd7c6ff

Browse files
committed
Add test cases for batches and detectors with attributes to the collector package TestEnablePostgresLogging test.
1 parent 5d3b562 commit dd7c6ff

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

internal/collector/postgres_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/crunchydata/postgres-operator/internal/feature"
1414
"github.com/crunchydata/postgres-operator/internal/postgres"
15+
"github.com/crunchydata/postgres-operator/internal/testing/cmp"
1516
"github.com/crunchydata/postgres-operator/internal/testing/require"
1617
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
1718
)
@@ -813,6 +814,85 @@ service:
813814
- filelog/postgres_jsonlog
814815
`)
815816
})
817+
818+
t.Run("LogsBatchesConfigured", func(t *testing.T) {
819+
gate := feature.NewGate()
820+
assert.NilError(t, gate.SetFromMap(map[string]bool{
821+
feature.OpenTelemetryLogs: true,
822+
}))
823+
ctx := feature.NewContext(context.Background(), gate)
824+
825+
cluster := new(v1beta1.PostgresCluster)
826+
cluster.Spec.PostgresVersion = 99
827+
require.UnmarshalInto(t, &cluster.Spec, `{
828+
instrumentation: {
829+
logs: {
830+
batches: {
831+
maxDelay: 5min 12sec,
832+
maxRecords: 123,
833+
minRecords: 45,
834+
},
835+
},
836+
},
837+
}`)
838+
839+
config := NewConfig(cluster.Spec.Instrumentation)
840+
params := postgres.NewParameters()
841+
842+
EnablePostgresLogging(ctx, cluster, config, params.Default)
843+
844+
result, err := config.ToYAML()
845+
assert.NilError(t, err)
846+
assert.Assert(t, cmp.Contains(result, `
847+
batch/logs:
848+
send_batch_max_size: 123
849+
send_batch_size: 45
850+
timeout: 5m12s
851+
`))
852+
})
853+
854+
t.Run("DetectorsWithAttributes", func(t *testing.T) {
855+
gate := feature.NewGate()
856+
assert.NilError(t, gate.SetFromMap(map[string]bool{
857+
feature.OpenTelemetryLogs: true,
858+
}))
859+
ctx := feature.NewContext(context.Background(), gate)
860+
861+
cluster := new(v1beta1.PostgresCluster)
862+
cluster.Spec.PostgresVersion = 99
863+
cluster.Spec.Instrumentation = testInstrumentationSpec()
864+
cluster.Spec.Instrumentation.Config.Detectors = []v1beta1.OpenTelemetryResourceDetector{
865+
{Name: "gcp"},
866+
{Name: "aks", Attributes: map[string]bool{
867+
"k8s.cluster.name": true,
868+
}},
869+
}
870+
871+
config := NewConfig(cluster.Spec.Instrumentation)
872+
params := postgres.NewParameters()
873+
874+
EnablePostgresLogging(ctx, cluster, config, params.Default)
875+
876+
result, err := config.ToYAML()
877+
assert.NilError(t, err)
878+
assert.Assert(t, cmp.Contains(result, `
879+
resourcedetection:
880+
aks:
881+
resource_attributes:
882+
k8s.cluster.name:
883+
enabled: true
884+
detectors:
885+
- gcp
886+
- aks
887+
override: false
888+
timeout: 30s
889+
`))
890+
// Verify resourcedetection is in the pipeline
891+
assert.Assert(t, cmp.Contains(result, `
892+
- resourcedetection
893+
- batch/logs
894+
`))
895+
})
816896
}
817897

818898
func TestEnablePostgresMetrics(t *testing.T) {

0 commit comments

Comments
 (0)