@@ -114,7 +114,6 @@ collector.yaml: |
114114 processors:
115115 - resource/pgadmin
116116 - transform/pgadmin_log
117- - resourcedetection
118117 - batch/logs
119118 - groupbyattrs/compact
120119 receivers:
@@ -125,15 +124,14 @@ collector.yaml: |
125124 processors:
126125 - resource/pgadmin
127126 - transform/pgadmin_log
128- - resourcedetection
129127 - batch/logs
130128 - groupbyattrs/compact
131129 receivers:
132130 - filelog/pgadmin
133131` ))
134132 })
135133
136- t .Run ("InstrumentationSpecDefined " , func (t * testing.T ) {
134+ t .Run ("InstrumentationSpecDefinedNoDetectors " , func (t * testing.T ) {
137135 gate := feature .NewGate ()
138136 assert .NilError (t , gate .SetFromMap (map [string ]bool {
139137 feature .OpenTelemetryLogs : true ,
@@ -232,6 +230,134 @@ collector.yaml: |
232230 include:
233231 - /var/lib/pgadmin/logs/pgadmin.log
234232 storage: file_storage/pgadmin_data_logs
233+ service:
234+ extensions:
235+ - file_storage/pgadmin_data_logs
236+ pipelines:
237+ logs/gunicorn:
238+ exporters:
239+ - googlecloud
240+ processors:
241+ - resource/pgadmin
242+ - transform/pgadmin_log
243+ - batch/logs
244+ - groupbyattrs/compact
245+ receivers:
246+ - filelog/gunicorn
247+ logs/pgadmin:
248+ exporters:
249+ - googlecloud
250+ processors:
251+ - resource/pgadmin
252+ - transform/pgadmin_log
253+ - batch/logs
254+ - groupbyattrs/compact
255+ receivers:
256+ - filelog/pgadmin
257+ ` ))
258+ })
259+
260+ t .Run ("InstrumentationSpecDefinedDetectorSet" , func (t * testing.T ) {
261+ gate := feature .NewGate ()
262+ assert .NilError (t , gate .SetFromMap (map [string ]bool {
263+ feature .OpenTelemetryLogs : true ,
264+ }))
265+
266+ ctx := feature .NewContext (context .Background (), gate )
267+
268+ var spec v1beta1.InstrumentationSpec
269+ require .UnmarshalInto (t , & spec , `{
270+ config: {
271+ detectors: [{name: gcp}],
272+ exporters: {
273+ googlecloud: {
274+ log: { default_log_name: opentelemetry.io/collector-exported-log },
275+ project: google-project-name,
276+ },
277+ },
278+ },
279+ logs: { exporters: [googlecloud] },
280+ }` )
281+
282+ configmap := new (corev1.ConfigMap )
283+ initialize .Map (& configmap .Data )
284+ err := collector .EnablePgAdminLogging (ctx , & spec , configmap )
285+ assert .NilError (t , err )
286+
287+ assert .Assert (t , cmp .MarshalMatches (configmap .Data , `
288+ collector.yaml: |
289+ # Generated by postgres-operator. DO NOT EDIT.
290+ # Your changes will not be saved.
291+ exporters:
292+ debug:
293+ verbosity: detailed
294+ googlecloud:
295+ log:
296+ default_log_name: opentelemetry.io/collector-exported-log
297+ project: google-project-name
298+ extensions:
299+ file_storage/pgadmin_data_logs:
300+ create_directory: false
301+ directory: /var/lib/pgadmin/logs/receiver
302+ fsync: true
303+ processors:
304+ batch/1s:
305+ timeout: 1s
306+ batch/200ms:
307+ timeout: 200ms
308+ batch/logs:
309+ send_batch_size: 8192
310+ timeout: 200ms
311+ groupbyattrs/compact: {}
312+ resource/pgadmin:
313+ attributes:
314+ - action: insert
315+ key: k8s.container.name
316+ value: pgadmin
317+ - action: insert
318+ key: k8s.namespace.name
319+ value: ${env:K8S_POD_NAMESPACE}
320+ - action: insert
321+ key: k8s.pod.name
322+ value: ${env:K8S_POD_NAME}
323+ - action: insert
324+ key: process.executable.name
325+ value: pgadmin
326+ resourcedetection:
327+ detectors:
328+ - gcp
329+ override: false
330+ timeout: 30s
331+ transform/pgadmin_log:
332+ log_statements:
333+ - statements:
334+ - set(log.attributes["log.record.original"], log.body)
335+ - set(log.cache, ParseJSON(log.body))
336+ - merge_maps(log.attributes, ExtractPatterns(log.cache["message"], "(?P<webrequest>[A-Z]{3}.*?[\\d]{3})"),
337+ "insert")
338+ - set(log.body, log.cache["message"])
339+ - set(instrumentation_scope.name, log.cache["name"])
340+ - set(log.severity_text, log.cache["level"])
341+ - set(log.time_unix_nano, Int(log.cache["time"]*1000000000))
342+ - set(log.severity_number, SEVERITY_NUMBER_DEBUG) where log.severity_text ==
343+ "DEBUG"
344+ - set(log.severity_number, SEVERITY_NUMBER_INFO) where log.severity_text ==
345+ "INFO"
346+ - set(log.severity_number, SEVERITY_NUMBER_WARN) where log.severity_text ==
347+ "WARNING"
348+ - set(log.severity_number, SEVERITY_NUMBER_ERROR) where log.severity_text ==
349+ "ERROR"
350+ - set(log.severity_number, SEVERITY_NUMBER_FATAL) where log.severity_text ==
351+ "CRITICAL"
352+ receivers:
353+ filelog/gunicorn:
354+ include:
355+ - /var/lib/pgadmin/logs/gunicorn.log
356+ storage: file_storage/pgadmin_data_logs
357+ filelog/pgadmin:
358+ include:
359+ - /var/lib/pgadmin/logs/pgadmin.log
360+ storage: file_storage/pgadmin_data_logs
235361 service:
236362 extensions:
237363 - file_storage/pgadmin_data_logs
0 commit comments