【问题标题】:Unable to get steeltoe health actuator endpoints via http无法通过 http 获取 steeltoe 健康执行器端点
【发布时间】:2019-04-11 04:03:36
【问题描述】:

我已经阅读了发行说明 https://steeltoe.io/reference/reference-release-notes/#2-2-0 并有兴趣通过 http 公开 /health 端点(我的意思是在 PCF 应用程序管理器之外)。我在 appsettings.json 中有以下设置

{
   "management": {
    "endpoints": {
      "path": "/cloudfoundryapplication",
      "cloudfoundry": {
        "validateCertificates": false
      },
      "health": {
        "showdetails": "always",
        "claim": {
          "type": "health_actuator",
          "value": "see_details"
        }
      }
    }
  } 
}

我的项目引用了 Steeltoe.Management.CloudFoundryCore V2.2.0,我的启动如下所示

public void ConfigureServices(IServiceCollection services)
        {
             // Add health actuator
            services.AddHealthActuator(configuration);
            services.AddCloudFoundryActuators(Configuration);
        }

public void Configure(IApplicationBuilder app) 

        {
            if (HostingEnvironment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCloudFoundryActuators();          

            app.UseHealthChecks();
            app.UseMvc();
        }

现在,当我尝试调用 url https://myservice/cloudfoundryapplication/health 时,我收到一个 401 错误,提示 {"security_error":"Authorization header is missing or invalid"}。知道这里可能有什么问题。

【问题讨论】:

    标签: asp.net-core steeltoe


    【解决方案1】:

    以下是在 cloudfoundry 中运行时访问应用程序管理器外部健康端点所需的步骤:

    1. 请勿设置 management:endpoints:path 或将其设置为 /cloudfoundryapplication 以外的任何内容。默认情况下,您的外部端点将在 /actuator/** 下可用。您可以将其设置为例如管理(只是不是 cloudfoundryapplication,因为应用程序人使用该路由并且它是安全的)。
    2. 像这样添加您的执行器:services.AddCloudFoundryActuators(Configuration, MediaTypeVersion.V2, ActuatorContext.ActuatorAndCloudFoundry); 这包括健康执行器,因此您不需要另一个 AddHealthActuator
    3. 像这样使用执行器:

      app.UseCloudFoundryActuators( MediaTypeVersion.V2, ActuatorContext.ActuatorAndCloudFoundry);

    4. 为了保护它,你可以添加这个配置, "claim": { "type": "health_actuator", "value": "see_details" }

    ...您应该在您的请求中提供这些信息。但看起来你不是。此配置是保护端点的一种方式。要在没有安全性的情况下查看它,您可以删除该部分配置。此外,默认设置是显示详细信息,因此您可以将配置完全放在“健康”下。

    【讨论】:

    • 我尝试从 appsettings.json 中删除整个健康部分,但仍然遇到同样的错误
    • 感谢它在我在 PCF 中运行时可以正常工作,但在本地运行时无法正常工作。我在启动期间遇到异常“System.InvalidOperationException:无法从根提供商解析范围服务'Steeltoe.Management.Endpoint.Health.HealthEndpoint'。知道如何让执行器端点与本地主机一起工作吗?
    • @Sajan 我最好的猜测是这个问题:github.com/SteeltoeOSS/Management/issues/52。这还没有进入我们的主要 nuget 提要,但可以在开发提要中找到:myget.org/feed/steeltoedev/package/nuget/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-07
    • 2017-08-11
    • 2015-12-14
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多