Skip to content

Commit 2be5109

Browse files
committed
Add test cases for batches and detectors with attributes to the collector package TestEnablePostgresLogging test.
1 parent b5711e5 commit 2be5109

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

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

816896
func TestEnablePostgresMetrics(t *testing.T) {

0 commit comments

Comments
 (0)