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

Hocon config map parsing issue #4398

Closed
aljawado700 opened this issue Jun 16, 2022 · 5 comments
Closed

Hocon config map parsing issue #4398

aljawado700 opened this issue Jun 16, 2022 · 5 comments
Assignees
Projects

Comments

@aljawado700
Copy link

Environment Details

  • Helidon Version: 2.5.0
  • Helidon SE
  • JDK version: Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)
  • OS: mac os monterey
  • Docker version (if applicable): N/A

Problem Description

When using hocon configs, helidon config parser maps full path to the keys and replaces dots with "~1"

Steps to reproduce

define a hocon config file test.conf with the following content:
ServiceConfig {
someConfig {
properties: {
"retries": 1
"request.timeout.ms": 10000
"delivery.timeout.ms": 30000
"buffer.memory": 335544320
"max.block.ms": 500
"max.request.size": 10485760
}
}
}
read the content using helidon config:
public static void main(String[] args) {
Config config = Config.builder()
.addSource(ConfigSources.file("./test.conf"))
.build();
Map<String, String> cfg = config.get("serviceConfig").detach().asMap().get();
cfg.forEach((key, value) -> System.out.println(key + ":" + value));
}

output:
someConfig.properties.max1block1ms:500
someConfig.properties.buffer1memory:335544320
someConfig.properties.delivery
1timeout1ms:30000
someConfig.properties.retries:1
someConfig.properties.request
1timeout1ms:10000
someConfig.properties.max
1request~1size:10485760

as you can see above, the last dot is replaced with ~1 and the key has the full path. The output we were expecting, however, is:

request.timeout.ms: 10000
delivery.timeout.ms: 30000
buffer.memory: 335544320
max.block.ms: 500
max.request.size: 10485760

@github-actions github-actions bot added this to Triage in Backlog Jun 16, 2022
@m0mus m0mus added the config label Jun 23, 2022
@m0mus m0mus moved this from Triage to Low priority in Backlog Jul 28, 2022
@m0mus m0mus moved this from Low priority to Sprint Scope in Backlog Jul 28, 2022
@klustria
Copy link
Member

klustria commented Aug 4, 2022

@aljawado700, ignoring ~1 as an issue, should the code above suppose to use:

Map<String, String> cfg = config.get("serviceConfig.someConfig.properties").detach().asMap().get();

rather than

Map<String, String> cfg = config.get("serviceConfig").detach().asMap().get();

to be able to extract this child key names:

request.timeout.ms: 10000
delivery.timeout.ms: 30000
buffer.memory: 335544320
max.block.ms: 500
max.request.size: 10485760

@klustria
Copy link
Member

klustria commented Aug 5, 2022

I think the problem if we don't include the full path in the key, say if we use below statement

Map<String, String> cfg = config.get("serviceConfig").detach().asMap().get();

is that, it will conflict with another property using the same name if for example we have this config:

serviceConfig {
    someConfig {
        properties: {
            "retries": 1
            "request.timeout.ms": 10000
            "delivery.timeout.ms": 30000
            "buffer.memory": 335544320
            "max.block.ms": 500
            "max.request.size": 10485760
        }
    }
    otherconfig {
        properties: {
            "retries": 1
            "request.timeout.ms": 10001
            "delivery.timeout.ms": 30001
            "buffer.memory": 335544321
            "max.block.ms": 501
            "max.request.size": 10485761
        }
    }    
}

right?

@klustria
Copy link
Member

klustria commented Aug 5, 2022

But we can extract them separately if we retrieve themfrom the actual parent node rather than the root node, like this:

Map<String, String> cfg = config.get("serviceConfig.someConfig.properties").detach().asMap().get();

and this:

Map<String, String> cfg = config.get("serviceConfig.otherConfig.properties").detach().asMap().get();

@aljawado700
Copy link
Author

@aljawado700, ignoring ~1 as an issue, should the code above suppose to use:

Map<String, String> cfg = config.get("serviceConfig.someConfig.properties").detach().asMap().get();

rather than

Map<String, String> cfg = config.get("serviceConfig").detach().asMap().get();

to be able to extract this child key names:

request.timeout.ms: 10000
delivery.timeout.ms: 30000
buffer.memory: 335544320
max.block.ms: 500
max.request.size: 10485760

You are correct and I am able to get the the properties map fine. The issue I guess is the ~1.

@klustria
Copy link
Member

Keys will be unescaped when the map is returned via:

  1. asMap()
  2. as(Map.class)
  3. as(new GenericType(){})

Backlog automation moved this from Sprint Scope to Closed Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Backlog
  
Closed
Development

No branches or pull requests

4 participants