gpt4 book ai didi

azure - 应用程序洞察和 kubernetes : How to not log successful/liveness and/hc probes to trace logs

转载 作者:行者123 更新时间:2023-12-02 19:12:22 25 4
gpt4 key购买 nike

我已经使用 kubernetes 在 Azure 中部署了一个 aspnetcore 项目。

我正在使用 Application Insights,并且我不想从 kubernetes 收到数千条有关成功的 liveness 和就绪性(/liveness/hc)探测的消息。

是否可以过滤它们?

基于ITelemetryProcessor的文件管理器我已经有了。

enter image description here

最佳答案

例如,在 active 和就绪探针的配置中,您可以指定与请求一起发送的自定义 header

          livenessProbe:
httpGet:
path: /api/health
port: http
httpHeaders:
- name: HealthProbe-Type
value: Liveness
readinessProbe:
httpGet:
path: /api/health
port: http
httpHeaders:
- name: HealthProbe-Type
value: Readiness

然后,您可以在 ITelemetryProcessor 实现中根据该 header 进行过滤:

public class HealthProbeTelemetryProcessor : ITelemetryProcessor
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ITelemetryProcessor _nextProcessor;
public static string HealthProbeHeaderName => "HealthProbe-Type";

public HealthProbeTelemetryProcessor(IHttpContextAccessor httpContextAccessor, ITelemetryProcessor nextProcessor)
{
_httpContextAccessor = httpContextAccessor;
_nextProcessor = nextProcessor;
}

public void Process(ITelemetry item)
{
if (item == null) throw new ArgumentNullException(nameof(item));

if (!string.IsNullOrWhiteSpace(item.Context.Operation.SyntheticSource))
return;

var isNotRequestTelemetry = !(item is RequestTelemetry);

if ((isNotRequestTelemetry || _httpContextAccessor.HttpContext == null || !(_httpContextAccessor.HttpContext.Request?.Headers.ContainsKey(HealthProbeHeaderName)).GetValueOrDefault()))
_nextProcessor.Process(item);
}
}

关于azure - 应用程序洞察和 kubernetes : How to not log successful/liveness and/hc probes to trace logs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64064041/

25 4 0