首页 > 解决方案 > 无法通过 http 获取 steeltoe 健康执行器端点

问题描述

我已经阅读了发布说明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-coresteeltoe

解决方案


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

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

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

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

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


推荐阅读