Estou tentando descobrir como configurar esse processador de filtro para filtrar algum tipo de log.
Eu criei para mim um playground no minikube com um aplicativo que gera logs aleatoriamente e instalei a integração do otel no coralogix .
O exemplo de registros:
{
"level": "error",
"ts": 1709652353.609003,
"caller": "logs-generator/logs-generator.go:60",
"msg": "Each Set Am.",
"error": "expected header is undefined",
"stacktrace": "anatoly.dev/dummy-logs/internal/logs-generator.(*LogsGenerator).GenerateRandomErrorLog\n\t/app/internal/logs-generator/logs-generator.go:60\nanatoly.dev/dummy-logs/internal/logs-generator.(*LogsGenerator).GenerateRandomLog\n\t/app/internal/logs-generator/logs-generator.go:71\nanatoly.dev/dummy-logs/cmd.NewRootCommand.NewStartCommand.func1\n\t/app/cmd/start.go:38\ngithub.com/spf13/cobra.(*Command).execute\n\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:983\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:1115\ngithub.com/spf13/cobra.(*Command).Execute\n\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:1039\ngithub.com/spf13/cobra.(*Command).ExecuteContext\n\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:1032\nmain.main\n\t/app/main.go:14\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:271"
},
{
"level": "warn",
"ts": 1709652354.6102042,
"caller": "logs-generator/logs-generator.go:47",
"msg": "The SMS circuit is down, construct the redundant monitor so we can synthesize the EXE sensor!",
"name": "Silas Anderson",
"email": "[email protected]",
"phone": "8381490753",
"color": "White"
},
{
"level": "info",
"ts": 1709652350.6055088,
"caller": "logs-generator/logs-generator.go:47",
"msg": "The SSL array is down, deconstruct the online protocol so we can load the AI interface!",
"name": "George Rice",
"email": "[email protected]",
"phone": "3695382906",
"color": "Blue"
},
{
"level": "debug",
"ts": 1709652351.6065476,
"caller": "logs-generator/logs-generator.go:47",
"msg": "If we compress the protocol, we can get to the HDD circuit through the 1080p JSON port!",
"name": "Kamron Marvin",
"email": "[email protected]",
"phone": "4465694677",
"color": "Green"
},
você pode ver, é um nível de log diferente, uma cor diferente, etc ... Agora quero configurar este processador de filtro para que algum tipo de log seja descartado. Por exemplo, registros com o nível error
e debug
:
Eu tentei o seguinte:
opentelemetry-agent:
config:
exporters:
debug:
verbosity: detailed
processors:
filter/ottl:
error_mode: ignore
logs:
log_record:
- 'IsMatch(body["level"], "debug")'
- 'IsMatch(body["level"], "error")'
service:
pipelines:
logs:
exporters:
- debug
processors:
- filter/ottl
- k8sattributes
- resourcedetection/env
- resourcedetection/region
- batch
Não funciona, ainda posso ver esses logs chegando ao Coalogix. Tentei várias opções, mas nada funciona.
Você pode ver que usei aqui o debug exportador tentando descobrir o que precisa ser filtrado, não me ajudou, você pode ver um exemplo de saída do debug aqui:
{
"level": "info",
"ts": 1709665690.10114,
"msg": {
"ResourceLog #0": {
"Resource SchemaURL": "https://opentelemetry.io/schemas/1.6.1",
"Resource attributes": {
"-> k8s.container.name": "Str(dummylogs)",
"-> k8s.namespace.name": "Str(default)",
"-> k8s.pod.name": "Str(dummylogs-58f59cf6c8-mtn7q)",
"-> k8s.container.restart_count": "Str(0)",
"-> k8s.pod.uid": "Str(2b42cdfc-05bf-4004-bca5-a5f74cb899e3)",
"-> k8s.cluster.name": "Str(coralogix-dummylogs-2)",
"-> cx.otel_integration.name": "Str(coralogix-integration-helm)",
"-> k8s.deployment.name": "Str(dummylogs)",
"-> k8s.node.name": "Str(coralogix-dummylogs-2)",
"-> host.name": "Str(coralogix-dummylogs-2)",
"-> os.type": "Str(linux)",
"-> host.id": "Str(61419f744ec9452499a59356fc030992)"
}
},
"ScopeLogs #0": {
"ScopeLogs SchemaURL": "InstrumentationScope",
"LogRecord #0": {
"ObservedTimestamp": "2024-03-05 19:08:09.996222879 +0000 UTC",
"Timestamp": "2024-03-05 19:08:09.845494796 +0000 UTC",
"SeverityText": "",
"SeverityNumber": "Unspecified(0)",
"Body": "Str({\"level\":\"error\",\"ts\":1709665689.8447518,\"caller\":\"logs-generator/logs-generator.go:60\",\"msg\":\"Those Meeting Dig.\",\"error\":\"error\",\"stacktrace\":\"anatoly.dev/dummy-logs/internal/logs-generator.(*LogsGenerator).GenerateRandomErrorLog\\n\\t/app/internal/logs-generator/logs-generator.go:60\\nanatoly.dev/dummy-logs/internal/logs-generator.(*LogsGenerator).GenerateRandomLog\\n\\t/app/internal/logs-generator/logs-generator.go:71\\nanatoly.dev/dummy-logs/cmd.NewRootCommand.NewStartCommand.func1\\n\\t/app/cmd/start.go:38\\ngithub.com/spf13/cobra.(*Command).execute\\n\\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:983\\ngithub.com/spf13/cobra.(*Command).ExecuteC\\n\\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:1115\\ngithub.com/spf13/cobra.(*Command).Execute\\n\\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:1039\\ngithub.com/spf13/cobra.(*Command).ExecuteContext\\n\\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:1032\\nmain.main\\n\\t/app/main.go:14\\nruntime.main\\n\\t/usr/local/go/src/runtime/proc.go:271\"})",
"Attributes": {
"-> log.file.path": "Str(/var/log/pods/default_dummylogs-58f59cf6c8-mtn7q_2b42cdfc-05bf-4004-bca5-a5f74cb899e3/dummylogs/0.log)",
"-> time": "Str(2024-03-05T19:08:09.845494796Z)",
"-> log.iostream": "Str(stderr)",
"Trace ID": "",
"Span ID": "",
"Flags": "0"
},
"kind": "exporter",
"data_type": "logs",
"name": "debug"
}
}
}
}
ou
{
"level": "info",
"ts": 1709665689.2971187,
"msg": {
"ResourceLog #0": {
"Resource SchemaURL": "https://opentelemetry.io/schemas/1.6.1",
"Resource attributes": {
"-> k8s.container.restart_count": "Str(0)",
"-> k8s.pod.uid": "Str(2b42cdfc-05bf-4004-bca5-a5f74cb899e3)",
"-> k8s.container.name": "Str(dummylogs)",
"-> k8s.namespace.name": "Str(default)",
"-> k8s.pod.name": "Str(dummylogs-58f59cf6c8-mtn7q)",
"-> k8s.cluster.name": "Str(coralogix-dummylogs-2)",
"-> cx.otel_integration.name": "Str(coralogix-integration-helm)",
"-> k8s.deployment.name": "Str(dummylogs)",
"-> k8s.node.name": "Str(coralogix-dummylogs-2)",
"-> host.name": "Str(coralogix-dummylogs-2)",
"-> os.type": "Str(linux)",
"-> host.id": "Str(61419f744ec9452499a59356fc030992)"
}
},
"ScopeLogs #0": {
"ScopeLogs SchemaURL": "InstrumentationScope",
"LogRecord #0": {
"ObservedTimestamp": "2024-03-05 19:08:08.995622545 +0000 UTC",
"Timestamp": "2024-03-05 19:08:08.84215517 +0000 UTC",
"SeverityText": "",
"SeverityNumber": "Unspecified(0)",
"Body": "Str({\"level\":\"debug\",\"ts\":1709665688.8411458,\"caller\":\"logs-generator/logs-generator.go:47\",\"msg\":\"I'll bundle the haptic ADP bandwidth, that should construct the PCI circuit!\",\"name\":\"Laurianne Aufderhar\",\"email\":\"[email protected]\",\"phone\":\"2654965339\",\"color\":\"Green\"})",
"Attributes": {
"-> log.file.path": "Str(/var/log/pods/default_dummylogs-58f59cf6c8-mtn7q_2b42cdfc-05bf-4004-bca5-a5f74cb899e3/dummylogs/0.log)",
"-> log.iostream": "Str(stderr)",
"-> time": "Str(2024-03-05T19:08:08.84215517Z)",
"Trace ID": "",
"Span ID": "",
"Flags": "0"
},
"kind": "exporter",
"data_type": "logs",
"name": "debug"
}
}
}
}
Então, minha pergunta é como posso definir o filterprocessor usando a linguagem OTTL para filtrar logs com base em:
- nível, ou seja, erro, informações de depuração
- com base
k8s.node.name
e nível juntos
Não sou especialista em OTEL nem nada e nunca escrevi uma configuração de agente OTEL do zero, mas parece que você está tentando filtrar um campo que é uma string, mas sua expressão de filtro o trata como um objeto JSON
Eu estou supondo que esta expressão deve funcionar mais ou menos