Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actuator env endpoint is not resilient with dashes #36072

Closed
antechrestos opened this issue Jun 26, 2023 · 2 comments
Closed

Actuator env endpoint is not resilient with dashes #36072

antechrestos opened this issue Jun 26, 2023 · 2 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@antechrestos
Copy link

Version: springboot: 3.1 (don't think it is the point)

Let's declare two properties

my:
  properties:
    with-dashes: 1
    withoutDashes: 2

As documented, we can override properties values by sing environment. This part work well.

The problem is with actuator endpoint /actuator/env and /actuator/env/{toMatch}.

When I run my code with following environment variables MY_PROPERTIES_WITHDASHES=666 and MY_PROPERTIES_WITHOUTDASHES=777, on actuator I observe that without dashes, the endpoint /actuaor/env/my.properties.withoutDashes displays all sources of value, even the computed value

{
  "property": {
    "source": "systemEnvironment",
    "value": "777"
  },
  "activeProfiles": [],
  "propertySources": [
    {
      "name": "server.ports"
    },
    {
      "name": "systemProperties"
    },
    {
      "name": "systemEnvironment",
      "property": {
        "value": "777",
        "origin": "System Environment Property \"MY_PROPERTIES_WITHOUTDASHES\""
      }
    },
    {
      "name": "random"
    },
    {
      "name": "Config resource class path resource [application.yml] via location optional:classpath:/",
      "property": {
        "value": 2,
        "origin": "class path resource [application.yml] - 4:20"
      }
    },
    {
      "name": "Management Server"
    }
  ]
}

However, with the dashed property, I have /actuator/env/my.properties.with-dashes

{
  "property": {
    "source": "Config resource class path resource [application.yml] via location optional:classpath:/",
    "value": 1
  },
  "activeProfiles": [],
  "propertySources": [
    {
      "name": "server.ports"
    },
    {
      "name": "systemProperties"
    },
    {
      "name": "systemEnvironment"
    },
    {
      "name": "random"
    },
    {
      "name": "Config resource class path resource [application.yml] via location optional:classpath:/",
      "property": {
        "value": 1,
        "origin": "class path resource [application.yml] - 3:18"
      }
    },
    {
      "name": "Management Server"
    }
  ]
}

The value displayed contains neither the real value used by application (I exposed it with a controller which returns 666as expected) nor the reference of the environment variable.

The reference to the environment variable can be seen by requesting

/actuator/env/my.properties.withdashes (remove the dash)

{
  "property": {
    "source": "systemEnvironment",
    "value": "666"
  },
  "activeProfiles": [],
  "propertySources": [
    {
      "name": "server.ports"
    },
    {
      "name": "systemProperties"
    },
    {
      "name": "systemEnvironment",
      "property": {
        "value": "666",
        "origin": "System Environment Property \"MY_PROPERTIES_WITHDASHES\""
      }
    },
    {
      "name": "random"
    },
    {
      "name": "Config resource class path resource [application.yml] via location optional:classpath:/"
    },
    {
      "name": "Management Server"
    }
  ]
}

This behaviour can be quite troublesome, as it may lead to a misunderstanding of the real behaviour of an application. I can try to provide a fix if you confirm the unwilling behaviour.

I provided a sample project to display the behaviour.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 26, 2023
@philwebb
Copy link
Member

The env endpoint here is actually working as designed and providing details about what values are returned when you make a call to Environment.getValue or use the @Value annotation.

The "Binding From Environment Variables" section is talking exclusively about @ConfigurationProperties binding, where additional logic is implemented to deal with the various different formats we support.

If you want to find out about what's actually been bound, the configprops endpoint is a better choice.

If you update the sample to expose the configprops endpoint and also set management.endpoint.configprops.show-values to always you can open http://localhost:8080/actuator/configprops/my.properties to see what is actually bound.

Your sample did highlight one problem: we're not currently displaying wrapper types correctly. I've opened #36076 to fix that.

@philwebb philwebb closed this as not planned Won't fix, can't repro, duplicate, stale Jun 26, 2023
@philwebb philwebb added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 26, 2023
@philwebb philwebb changed the title [actuator] Env endpoint is not resilient with dashes Actuator env endpoint is not resilient with dashes Jun 26, 2023
@antechrestos
Copy link
Author

Thank you @philwebb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants