helidon-io / helidon

Java libraries for writing microservices
https://helidon.io
Apache License 2.0
3.52k stars 564 forks source link

Extra quote appended in the logging path #9254

Closed shalabh2101 closed 1 month ago

shalabh2101 commented 1 month ago

While upgrading the Helidon version from 2.5.0 to 2.6.9 , we have observed an extra quote appended to the logging path. We have our logging directory defined in the configuration file. With the new version , somehow , the logging directory has an extra quote appended to it. So all our new logs are going to this new directory.

We were using this code to get the file path as a string from the Helidon Config: config.get(key).asString().orElse(defaultValue)

In Helidon 2.5 the path was as expected with no extra quote. In 2.6.4 and 2.6.9 snapshot versions, we observed that the path had an extra quote appended to it.

Environment Details

Config File Structure


logging {
  level: INFO
   appenders: [{
      type: file
      currentLogFilename: ${LOG_DIR}/application.log
      archive: true
romain-grecourt commented 1 month ago

Reproducer:

@Test
void testHoconExpansion() {
    Config config = Config.create(ConfigSources.create("foo: ${VAR1}/bar", "application/hocon"));
    assertThat(config.get("foo").asString().orElseThrow(NoSuchElementException::new), is("./bar"));
}
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <environmentVariables>
            <VAR1>.</VAR1>
        </environmentVariables>
    </configuration>
</plugin>

Works with 2.5.0, fails with 2.5.1. Changelog for 2.5.1 shows 2 updates to io.helidon.config:helidon-config-hocon:

spericas commented 1 month ago

In 2.5.1 we have turned off the Hocon parser substitution feature so that we could support substitution across config sources of potentially different types, such as Hocon and Yaml. We need this for MicroProfile.

Unfortunately, ${VAR1}/bar is not a legal Hocon unquoted string (because it contains $ or { etc.) and as a result of that the Hocon parser returns a concatenation of two values and adds quotes to the second part of it when rendering, so it becomes ${VAR1}"/bar". This behavior cannot be altered using the Hocon parser's public API. Note that Helidon would handle the use of ${VAR1} unquoted but cannot affect the rendering of a concatenated value such as ${VAR1}/bar.

When quoting the entire string (the workaround) as "{$VAR1}/bar" then the substitution is untouched and resolved at a later time by the Helidon config machinery, so everything works as expected. Due to the lack of a proper API, I don't see a way for Helidon to improve handling of this use case.

spericas commented 1 month ago

@romain-grecourt A hacky solution would be to just remove any "'s introduced by the rendering step that we do. This would handle this use case and others but it is a hack.