SteeltoeOSS / Steeltoe

.NET Components for Externalized Configuration, Database Connectors, Service Discovery, Logging and Distributed Tracing, Application Management, Security, and more.
https://steeltoe.io
Apache License 2.0
1.01k stars 163 forks source link

Unable to activate both CF Actuators and Endpoints together #161

Closed alfusinigoj closed 4 years ago

alfusinigoj commented 5 years ago

Describe the bug

Package steeltoe.management.endpointweb.2.4.0-rc1

Trying to enable actuators for an ASP.NET full framework application using ActuatorConfigurator as below. The problem is that when I set the context to ActuatorContext.Actuator I am able to hit the endpoints, say /actuator/health, but since I need the Cf Actuators to be enabled for AppsMan, I set the context to ActuatorContext.ActuatorAndCloudFoundry where I can see the actuators enabled in AppsMan, but I am getting 401 UnAuthorized when trying to access the endpoints say /actuator/health or /actuator/info

ActuatorConfigurator.UseCloudFoundryActuators(configuration,
                                                            dynamicLoggerProvider,
                                                            MediaTypeVersion.V1,
                                                            ActuatorContext.ActuatorAndCloudFoundry,
                                                            GetHealthContributors(),
                                                            GlobalConfiguration.Configuration.Services.GetApiExplorer(),
                                                            loggerFactory);

Expected behavior

When context is set to ActuatorContext.ActuatorAndCloudFoundry, we should be able to hit the endpoints, together with AppsMan actuators.

Environment (please complete the following information):

alfusinigoj commented 4 years ago

@hananiel At this point, do we need to enable /info and /health endpoints explicitly via configuration or they exposed by default. Any samples are welcome. Thanks!

hananiel commented 4 years ago

@alfusinigoj health and info should be exposed by default. Here is a sample: https://github.com/SteeltoeOSS/Samples/blob/master/Management/src/AspDotNetCore/CloudFoundry/Startup.cs

alfusinigoj commented 4 years ago

@hananiel the sample still uses steeltoe 2.4.0-rc1 which has this issue, i will test and let you know. thanks!

alfusinigoj commented 4 years ago

@hananiel I still think we will not be able to use cloudfoundry actuators and hypermedia actuators together. Is that true? Because it doesn't seem to work when i used ActuatorContext.ActuatorAndCloudFoundry

hananiel commented 4 years ago

It was working before - let me take a look.

alfusinigoj commented 4 years ago

ok thanks @hananiel . Here is my code (using in a ASP.NET app)

ActuatorConfigurator.UseCloudFoundryActuators(configuration,
                                                            dynamicLoggerProvider,
                                                            MediaTypeVersion.V1,
                                                            ActuatorContext.ActuatorAndCloudFoundry,
                                                            GetHealthContributors(),
                                                            GlobalConfiguration.Configuration.Services.GetApiExplorer(),
                                                            loggerFactory);

Looking at this decompiled code... it seems like the hypermedia actuator is ignored for any context other than Actuator

public static void UseCloudFoundryActuators(IConfiguration configuration, ILoggerProvider dynamicLogger, MediaTypeVersion version, ActuatorContext context, IEnumerable<IHealthContributor> healthContributors = null, IApiExplorer apiExplorer = null, ILoggerFactory loggerFactory = null)
        {
            if (context != ActuatorContext.Actuator)
            {
                ActuatorConfigurator.UseCloudFoundrySecurity(configuration, null, loggerFactory);
                ActuatorConfigurator.UseCloudFoundryActuator(configuration, loggerFactory);
            }
            else
            {
                ActuatorConfigurator.UseHypermediaActuator(configuration, loggerFactory);
            }
            ActuatorConfigurator.UseHealthActuator(configuration, null, healthContributors, loggerFactory);
            ActuatorConfigurator.UseHeapDumpActuator(configuration, null, loggerFactory);
            ActuatorConfigurator.UseThreadDumpActuator(configuration, version, null, loggerFactory);
            ActuatorConfigurator.UseInfoActuator(configuration, null, loggerFactory);
            ActuatorConfigurator.UseLoggerActuator(configuration, dynamicLogger, loggerFactory);
            ActuatorConfigurator.UseTraceActuator(configuration, version, null, loggerFactory);
            ActuatorConfigurator.UseMappingsActuator(configuration, apiExplorer, loggerFactory);
        }
hananiel commented 4 years ago

@alfusinigoj looking at the decompiled code now -- it does not match the latest version of 2.x. 2.4.0 is the latest stable and it was cut on Nov13th. For now myget is the latest version. I'll update the 4.x sample to reflect this once released - which should be soon.

jkonicki commented 4 years ago

This fix will be in 2.4.1 set to be released 1/17.

alfusinigoj commented 4 years ago

tested with steeltoe dev version, works perfect. thanks!

VenkateshSrini commented 4 years ago

@alfusinigoj , can you please provide me a sample where you have got the actuator work. I'm still not able to get it working

alfusinigoj commented 4 years ago

@VenkateshSrini here is a working sample https://github.com/alfusinigoj/pivotal_aspnet_bootstrap_cloudfoundry_extensions/tree/master/samples/Actuators/ActuatorSample

VenkateshSrini commented 4 years ago

Thanks alfus it worked