閱讀英文

共用方式為

监视并诊断反向代理中的请求处理

从 Service Fabric 的 5.7 版本开始,反向代理事件可用于收集。 这些事件在两个通道中可用,其中一个通道仅包含与反向代理的请求处理失败相关的错误事件,第二个通道包含包含成功和失败请求条目的详细事件。

请参阅 “收集反向代理事件 ”,以便从本地和 Azure Service Fabric 群集中的这些通道收集事件。

使用诊断日志进行故障排除

下面是有关如何解释一个可能遇到的常见故障日志的一些示例:

  1. 反向代理返回响应状态代码 504(超时)。

    原因之一可能是服务未能在请求超时期限内答复。 下列第一个事件记录了在反向代理接收请求时的详细信息。 第二个事件表示在转发请求到服务时失败,是因为“内部错误 = ERROR_WINHTTP_TIMEOUT”

    载荷包括:

    • traceId:此 GUID 可用于关联与单个请求对应的所有事件。 在下面两个事件中,traceId = 0000aaaa-11bb-cccc-dd22-eeeeee3333333,表示它们属于同一请求。

    • requestUrl:请求发送到的 URL(反向代理 URL)。

    • 动词:HTTP 动词。

    • remoteAddress:发送请求的客户端地址。

    • resolvedServiceUrl:解析传入请求的服务终结点 URL。

    • errorDetails:有关失败的其他信息。

      {
      "Timestamp": "2017-07-20T15:57:59.9871163-07:00",
      "ProviderName": "Microsoft-ServiceFabric",
      "Id": 51477,
      "Message": "0000aaaa-11bb-cccc-dd22-eeeeee333333 Request url = https://localhost:19081/LocationApp/LocationFEService?zipcode=98052, verb = GET, remote (client) address = ::1, resolved service url = Https://localhost:8491/LocationApp/?zipcode=98052, request processing start time =     15:58:00.074114 (745,608.196 MSec) ",
      "ProcessId": 57696,
      "Level": "Informational",
      "Keywords": "0x1000000000000021",
      "EventName": "ReverseProxy",
      "ActivityID": null,
      "RelatedActivityID": null,
      "Payload": {
      "traceId": "0000aaaa-11bb-cccc-dd22-eeeeee333333",
      "requestUrl": "https://localhost:19081/LocationApp/LocationFEService?zipcode=98052",
      "verb": "GET",
      "remoteAddress": "::1",
      "resolvedServiceUrl": "Https://localhost:8491/LocationApp/?zipcode=98052",
      "requestStartTime": "2017-07-20T15:58:00.0741142-07:00"
      }
      }
      
      {
      "Timestamp": "2017-07-20T16:00:01.3173605-07:00",
      ...
      "Message": "0000aaaa-11bb-cccc-dd22-eeeeee333333 Error while forwarding request to service: response status code = 504, description = Reverse proxy Timeout, phase = FinishSendRequest, internal error = ERROR_WINHTTP_TIMEOUT ",
      ...
      "Payload": {
      "traceId": "0000aaaa-11bb-cccc-dd22-eeeeee333333",
      "statusCode": 504,
      "description": "Reverse Proxy Timeout",
      "sendRequestPhase": "FinishSendRequest",
      "errorDetails": "internal error = ERROR_WINHTTP_TIMEOUT"
      }
      }
      
  2. 反向代理返回响应状态代码 404(找不到)。

    下面是一个示例事件,其中反向代理返回 404,因为它找不到匹配的服务终结点。 此处感兴趣的有效负载条目如下:

    • processRequestPhase:指示失败时请求处理期间的阶段, TryGetEndpoint 即尝试提取要转发的服务终结点。

    • errorDetails:列出终结点搜索条件。 在这里可以看到,指定的 listenerName = FrontEndListener ,而副本终结点列表仅包含名为 OldListener 的侦听器。

      {
      ...
      "Message": "1111bbbb-22cc-dddd-ee33-ffffff444444 Error while processing request, cannot forward to service: request url = https://localhost:19081/LocationApp/LocationFEService?ListenerName=FrontEndListener&zipcode=98052, verb = GET, remote (client) address = ::1, request processing start time = 16:43:02.686271 (3,448,220.353 MSec), error = FABRIC_E_ENDPOINT_NOT_FOUND, message = , phase = TryGetEndoint, SecureOnlyMode = false, gateway protocol = https, listenerName = FrontEndListener, replica endpoint = {\"Endpoints\":{\"\":\"Https:\/\/localhost:8491\/LocationApp\/\"}} ",
      "ProcessId": 57696,
      "Level": "Warning",
      "EventName": "ReverseProxy",
      "Payload": {
      "traceId": "1111bbbb-22cc-dddd-ee33-ffffff444444",
      "requestUrl": "https://localhost:19081/LocationApp/LocationFEService?ListenerName=NewListener&zipcode=98052",
      ...
      "processRequestPhase": "TryGetEndoint",
      "errorDetails": "SecureOnlyMode = false, gateway protocol = https, listenerName = FrontEndListener, replica endpoint = {\"Endpoints\":{\"OldListener\":\"Https:\/\/localhost:8491\/LocationApp\/\"}}"
      }
      }
      

      反向代理可以返回 404 未找到的另一个示例是:ApplicationGateway\Http 配置参数 SecureOnlyMode 设置为 true,而反向代理侦听 HTTPS,但所有副本终结点都是不安全的(侦听 HTTP)。 反向代理返回 404,因为它找不到可以侦听 HTTPS 的终结点来转发请求。 分析事件有效负载中的参数有助于缩小问题的范围:

      "errorDetails": "SecureOnlyMode = true, gateway protocol = https, listenerName = NewListener, replica endpoint = {\"Endpoints\":{\"OldListener\":\"Http:\/\/localhost:8491\/LocationApp\/\", \"NewListener\":\"Http:\/\/localhost:8492\/LocationApp\/\"}}"
      
  3. 对反向代理的请求因超时错误而失败。 事件日志包含包含收到请求详细信息的事件(此处未显示)。 下一个事件显示服务响应了 404 状态代码,反向代理开始重新解析。

    {
      ...
      "Message": "2222cccc-33dd-eeee-ff44-aaaaaa555555 Request to service returned: status code = 404, status description = , Reresolving ",
      "Payload": {
        "traceId": "2222cccc-33dd-eeee-ff44-aaaaaa555555",
        "statusCode": 404,
        "statusDescription": ""
      }
    }
    {
      ...
      "Message": "2222cccc-33dd-eeee-ff44-aaaaaa555555 Re-resolved service url = Https://localhost:8491/LocationApp/?zipcode=98052 ",
      "Payload": {
        "traceId": "2222cccc-33dd-eeee-ff44-aaaaaa555555",
        "requestUrl": "Https://localhost:8491/LocationApp/?zipcode=98052"
      }
    }
    

    收集所有事件时,会看到一个展示每次解析和转发尝试的事件序列。 序列中的最后一个事件显示请求处理失败并出现超时,以及成功解析尝试次数。

    注意

    建议默认禁用详细通道事件集合,并根据需要启用它进行故障排除。

    {
      ...
      "Message": "2222cccc-33dd-eeee-ff44-aaaaaa555555 Error while processing request: number of successful resolve attempts = 12, error = FABRIC_E_TIMEOUT, message = , phase = ResolveServicePartition,  ",
      "EventName": "ReverseProxy",
      ...
      "Payload": {
        "traceId": "2222cccc-33dd-eeee-ff44-aaaaaa555555",
        "resolveCount": 12,
        "errorval": -2147017729,
        "errorMessage": "",
        "processRequestPhase": "ResolveServicePartition",
        "errorDetails": ""
      }
    }
    

    如果仅对严重/错误事件启用了收集,则会看到一个事件,其中包含有关超时和解析尝试次数的详细信息。

    打算将 404 状态代码发送回用户的服务应在响应中添加“X-ServiceFabric”标头。 将标头添加到响应后,反向代理会将状态代码转发回客户端。

  4. 当客户端断开请求的连接时的情况。

    当反向代理将响应转发到客户端但客户端断开连接时,将记录以下事件:

    {
      ...
      "Message": "3333dddd-44ee-ffff-aa55-bbbbbb666666 Unable to send response to client: phase = SendResponseHeaders, error = -805306367, internal error = ERROR_SUCCESS ",
      "ProcessId": 57696,
      "Level": "Warning",
      ...
      "EventName": "ReverseProxy",
      "Payload": {
        "traceId": "3333dddd-44ee-ffff-aa55-bbbbbb666666",
        "sendResponsePhase": "SendResponseHeaders",
        "errorval": -805306367,
        "winHttpError": "ERROR_SUCCESS"
      }
    }
    
  5. 反向代理返回 404 FABRIC_E_SERVICE_DOES_NOT_EXIST

    如果未为服务清单中的服务终结点指定 URI 方案,则返回FABRIC_E_SERVICE_DOES_NOT_EXIST错误。

    <Endpoint Name="ServiceEndpointHttp" Port="80" Protocol="http" Type="Input"/>
    

    若要解决此问题,请在清单中指定 URI 方案。

    <Endpoint Name="ServiceEndpointHttp" UriScheme="http" Port="80" Protocol="http" Type="Input"/>
    

注意

当前不会记录与 Websocket 请求处理相关的事件。 这将在下一个版本中添加。

后续步骤