Azure / api-management-self-hosted-gateway

Home of Azure API Management's Self-Hosted Gateway
https://docs.microsoft.com/en-gb/azure/api-management/self-hosted-gateway-overview
Other
66 stars 27 forks source link

LocalSyslog fails to store logs #240

Closed oskrabanek closed 5 months ago

oskrabanek commented 1 year ago

Report

As I want to store the logs locally, I would like to enable LocalSyslog. According to the documentation this snippet should work.

        telemetry.logs.std: "text"
        telemetry.logs.local.localsyslog.endpoint: "/dev/log"
        telemetry.logs.local.localsyslog.facility: "7"

But according to the log below the local path is tried to be resolved using DnsResolver, which fails and causes the logs not to be saved.

[Info] 2023-07-26T10:57:58.065 [LocalLogFormatIdentified], message: Local logging is configured with format 'LocalSyslog' and minimal log level 'Informational'., source: LocalLogSinkFactory
[Info] 2023-07-26T10:57:58.065 [LocalLogEndpointIdentified], message: Endpoint address '/app/logs' configured for log format 'LocalSyslog'., source: LocalLogSinkFactory
[Warn] 2023-07-26T10:57:58.069 [DnsResultionFailed], message: /app/logs, exception: System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000005, 0xFFFDFFFF): Name does not resolve
   at System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses, AddressFamily addressFamily, ValueStopwatch stopwatch)
   at System.Net.Dns.<>c.<GetHostEntryOrAddressesCoreAsync>b__33_0(Object s, ValueStopwatch stopwatch)
   at System.Net.Dns.<>c__DisplayClass39_0`1.<RunAsync>b__0(Task <p0>, Object <p1>)
   at System.Threading.Tasks.ContinuationResultTaskFromTask`1.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.WindowsAzure.ApiManagement.Proxy.Runtime.DefaultDnsNameResolver.ResolveAsync(String name, CancellationToken cancellation) in D:\a\1\s\Proxy\Gateway.Pipeline.IO\Dns\DefaultDnsNameResolver.cs:line 26
   at Gateway.Pipeline.IO.Dns.DnsMonitor.Resolve(String hostname) in D:\a\1\s\Proxy\Gateway.Pipeline.IO\Dns\DnsMonitor.cs:line 92, source: DnsMonitor

I'm testing it locally in the docker to be able to debug it easier.

Expected Behavior

The logs are stored in the given location.

Actual Behavior

The logs target directory is empty

Steps to Reproduce the Problem

  1. Create your own docker image to create directory for logs
    
    FROM mcr.microsoft.com/azure-api-management/gateway:2.3.2

USER root

Create log directory

RUN mkdir -p /app/logs/

USER apimuser


2. Run the following command:

docker run --rm -it -p 8889:8080 --name ApimTest-ApimTestLocal -e telemetry.logs.std='text' -e telemetry.logs.local='localsyslog' -e telemetry.logs.local.localsyslog.endpoint='/app/logs' -e telemetry.logs.local.localsyslog.facility='7' -e config.service.endpoint='*********************************' -e config.service.auth='GatewayKey ****' ` [name-of-your-image:latest]

3. Check the directory `/app/logs`

### Logs from self-hosted gateway

version: 2.3.2.0 commit: 55015ec2cb8387c342ce66e48d82a5c0cbd14948 [Info] 2023-07-26T10:57:57.155 [GatewayCipherSuite], message: Default cipher suites are being used for gateway. [Warn] 2023-07-26T10:57:57.157 [DnsResultionFailed], message: /app/logs, exception: System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000005, 0xFFFDFFFF): Name does not resolve at System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses, AddressFamily addressFamily, ValueStopwatch stopwatch) at System.Net.Dns.<>c.b33_0(Object s, ValueStopwatch stopwatch) at System.Net.Dns.<>c__DisplayClass39_0`1.b0(Task , Object ) at System.Threading.Tasks.ContinuationResultTaskFromTask`1.InnerInvoke() at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj) at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at Microsoft.WindowsAzure.ApiManagement.Proxy.Runtime.DefaultDnsNameResolver.ResolveAsync(String name, CancellationToken cancellation) in D:\a\1\s\Proxy\Gateway.Pipeline.IO\Dns\DefaultDnsNameResolver.cs:line 26 at Gateway.Pipeline.IO.Dns.DnsMonitor.Resolve(String hostname) in D:\a\1\s\Proxy\Gateway.Pipeline.IO\Dns\DnsMonitor.cs:line 92, source: DnsMonitor



### Self-hosted Gateway Version

2.3.2

### Deployment

Docker (Compose)

### Platform

None

### Kubernetes Version

None

### Anything else?

_No response_
tomkerkhove commented 1 year ago

Local syslog are streamed to a socket and is not just writing to a folder, we don't have docs for Docker but for AKS we offer some guidance: https://learn.microsoft.com/en-us/azure/api-management/how-to-configure-local-metrics-logs#using-local-syslog-logs-on-azure-kubernetes-service-aks