Skip to content
New issue

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

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

Already on GitHub? # to your account

Highlight enums with String values correctly #1488

Merged
merged 5 commits into from
Jul 12, 2022

Conversation

aaronweissler
Copy link
Member

@aaronweissler aaronweissler commented Jun 27, 2022

Closes #1436


This change is Reviewable

@heiko-holz heiko-holz self-assigned this Jul 11, 2022
Copy link
Contributor

@heiko-holz heiko-holz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @aaronweissler)


components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/yamlhighlighter/HighlightRulesMapController.java line 170 at r1 (raw file):

    private List<String> extractEnumValues(Class<?> currentEnum) {
        List<String> allFields = Arrays.stream(currentEnum.getDeclaredFields()).map(Field::getName).collect(Collectors.toList());
        if (allFields.contains("values")){

The field values is specific to the TransportProtocol.

In case of the TransportProtocol it would also be sufficient to just map to the toString method instead of the getName.

Assuming that the other Enums do not override the toString method to express something different, we can use

 private List<String> extractEnumValues(Class<?> currentEnum) {
        return Arrays.stream(currentEnum.getEnumConstants()).map(Object::toString).collect(Collectors.toList());
    }
``

(in order to make the test pass, the order of the expected values for `TransportProtocol` need to be adjusted in `HighlightRulesMapControllerIntTest`

Alternatively, we can also add the edge case of the `TransportProcotol` directly into the `extractEnumValues` method:

private List extractEnumValues(Class currentEnum) { Class> clazz = (Class>) currentEnum;
if (currentEnum.equals(TransportProtocol.class)) {
return Arrays.stream(clazz.getEnumConstants()).map(Enum::toString).collect(Collectors.toList());
} else {
return Arrays.stream(clazz.getEnumConstants()).map(Enum::name).collect(Collectors.toList());
}
}

@aaronweissler aaronweissler marked this pull request as ready for review July 11, 2022 15:33
@codecov
Copy link

codecov bot commented Jul 11, 2022

Codecov Report

Merging #1488 (b962b19) into master (945412d) will increase coverage by 0.01%.
The diff coverage is n/a.

❗ Current head b962b19 differs from pull request most recent head 80490dd. Consider uploading reports for the commit 80490dd to get more accurate results

@@             Coverage Diff              @@
##             master    #1488      +/-   ##
============================================
+ Coverage     79.26%   79.27%   +0.01%     
  Complexity     2254     2254              
============================================
  Files           231      230       -1     
  Lines          7305     7304       -1     
  Branches        867      867              
============================================
  Hits           5790     5790              
+ Misses         1157     1156       -1     
  Partials        358      358              

Using toString, empty values could not be parsed correctly by gson
Copy link
Member Author

@aaronweissler aaronweissler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 3 files reviewed, 1 unresolved discussion (waiting on @heiko-holz)


components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/yamlhighlighter/HighlightRulesMapController.java line 170 at r1 (raw file):

Previously, heiko-holz (Heiko Holz) wrote…

The field values is specific to the TransportProtocol.

In case of the TransportProtocol it would also be sufficient to just map to the toString method instead of the getName.

Assuming that the other Enums do not override the toString method to express something different, we can use

 private List<String> extractEnumValues(Class<?> currentEnum) {
        return Arrays.stream(currentEnum.getEnumConstants()).map(Object::toString).collect(Collectors.toList());
    }
``

(in order to make the test pass, the order of the expected values for `TransportProtocol` need to be adjusted in `HighlightRulesMapControllerIntTest`

Alternatively, we can also add the edge case of the `TransportProcotol` directly into the `extractEnumValues` method:

private List extractEnumValues(Class currentEnum) { Class> clazz = (Class>) currentEnum;
if (currentEnum.equals(TransportProtocol.class)) {
return Arrays.stream(clazz.getEnumConstants()).map(Enum::toString).collect(Collectors.toList());
} else {
return Arrays.stream(clazz.getEnumConstants()).map(Enum::name).collect(Collectors.toList());
}
}

Yes, exactly this problem/limitation I would have mentioned when turning it from draft to reviewable, that right now it assumes that any other Enums using this functionality would also save their values in a values field.

Simply using toString seems like a really good idea to me though, since it should be correct for any Enums used in this context, since the values for configurations are also defined as Strings.
And I like it more than defining an exception specifically for TransportProtocol, since it would just work for new Enums working the same way without additional code changes.

Copy link
Contributor

@heiko-holz heiko-holz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @aaronweissler)


components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/yamlhighlighter/HighlightRulesMapController.java line 170 at r1 (raw file):

Previously, aaronweissler wrote…

Yes, exactly this problem/limitation I would have mentioned when turning it from draft to reviewable, that right now it assumes that any other Enums using this functionality would also save their values in a values field.

Simply using toString seems like a really good idea to me though, since it should be correct for any Enums used in this context, since the values for configurations are also defined as Strings.
And I like it more than defining an exception specifically for TransportProtocol, since it would just work for new Enums working the same way without additional code changes.

Yep, I also like the implementation with toString

@heiko-holz heiko-holz merged commit 2e32730 into inspectIT:master Jul 12, 2022
@aaronweissler aaronweissler deleted the fix/enum-highlights branch July 18, 2022 08:36
salim-1997 pushed a commit to salim-1997/inspectit-ocelot that referenced this pull request Aug 15, 2022
versions(inspectIT#1507)

Highlight enums with String values correctly (inspectIT#1488)

* Treat enums with values-field differently

* Fix default config exporters.yml

* Fix order of possible values in test

* Use toString instead of getName

* Fix JSON parsing of Maps in test

Using toString, empty values could not be parsed correctly by gson

update patches

update minor versions

update eslint dependencies

update @babel/core dependency

re-update eslint

update primeinons

update primeflex

update react-timeago

update react-syntax-highligter

update react-redux
aaronweissler added a commit that referenced this pull request Sep 5, 2022
versions(#1507)

Highlight enums with String values correctly (#1488)

* Treat enums with values-field differently

* Fix default config exporters.yml

* Fix order of possible values in test

* Use toString instead of getName

* Fix JSON parsing of Maps in test

Using toString, empty values could not be parsed correctly by gson

update patches

update minor versions

update eslint dependencies

update @babel/core dependency

re-update eslint

update primeinons

update primeflex

update react-timeago

update react-syntax-highligter

update react-redux
aaronweissler pushed a commit that referenced this pull request Sep 5, 2022
… of Config Server UI dependencies (#1510)

* update patches

* update minor versions

* update eslint dependencies

* update @babel/core dependency

* re-update eslint

* update primeinons

* update primeflex

* update react-timeago

* update react-syntax-highligter

* update react-redux

* update jwt-decode

* Merge branch 'master' of https://github.com/inspectIT/inspectit-ocelot into dependencies-update

* Closes #1507 : Update minor versions, patches and some major
versions(#1507)

Highlight enums with String values correctly (#1488)

* Treat enums with values-field differently

* Fix default config exporters.yml

* Fix order of possible values in test

* Use toString instead of getName

* Fix JSON parsing of Maps in test

Using toString, empty values could not be parsed correctly by gson

update patches

update minor versions

update eslint dependencies

update @babel/core dependency

re-update eslint

update primeinons

update primeflex

update react-timeago

update react-syntax-highligter

update react-redux

* update jwt-decode

* Add settings and info for developing UI in IntelliJ (#1496)

* Activate formatter tags by default

* Add indentation settings for JS

* Add to CONTRIBUTING regarding JavaScript linting

* Fix eol linting of .js files on Windows

* Add yarn lint and format:write to README

* Add section in CONTRIBUTING.md

* Add to CONTRIBUTING based on comments

* Fix linting command in README

Co-authored-by: Heiko Holz <heiko.holz@novatec-gmbh.de>

* [skip ci] Publish documentation v2.1.0

* Fix release notes links (#1503)

* Closes #1507 - Update minor versions, patches and some major versions

* Closes #1507 - Update minor versions, patches and some major versions

* Delete package-lock.json

Only one lock-file should be in project, which is yarn.lock in our case.

* Small fix to next.config

* Fix license string

* Change parser to babel/eslint-parser

* Add peer dependencies

* Merge branch 'master' into dependencies-update

* Fix linting errors

* Move babel eslint to devdependencies, remove old version

* Add helper-string-parser to devdependencies
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] - Config Server falsely marks grpc as a wrong protocol label.
2 participants