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

Provide a consistent configuration to Armeria Dropwizard #2373

Merged
merged 12 commits into from
Jan 13, 2020

Conversation

ikhoon
Copy link
Contributor

@ikhoon ikhoon commented Jan 4, 2020

Motivation:
Armeria's Spring Boot auto configure module offers to customize the Armeria server from JSON YAML.
Dropwizard module has been added to Armeria by #2236. It can also customize Armeria Server from YAML.
But the configuration style is different between Spring Boot and Dropwizard.
The user should learn how to configure Armeria in each module. It may confuse the user.

Modification:

  • Apply Spring Boot's YAML convention to the Dropwizard module.
  • Add ArmeriaConfigurationUtil for applying ArmeriaSettings to
    ServerBuilder.
  • Copy CustomAliasKeyManagerFactory and CustomAliasX509ExtendedKeyManager from
    amreria/spring/boot-autoconfigure to configure TLS fluenltly.
  • Add meter exporsition for DropwizardMeterRegistry.
  • Remove unused configuration files.

Result:
Provide a consistent configuration to Armeria Dropwizard.

Motivation:
Armeria's Spring Boot auto configure module offers to customize the Armeria server from JSON YAML.
Dropwizard module has been added to Armeria by line#2236. It can also customize Armeria Server from YAML.
But the configuration style is different.
Sometimes it may confuse the user.

Modification:
* Apply Spring Boot's YAML convention to the Dropwizard module.
* Add ArmeriaConfigurationUtil for applying ArmeriaSettings to
* ServerBuilder.
* Copy `CustomAliasKeyManagerFactory` and `CustomAliasX509ExtendedKeyManager` from
 `amreria/spring/boot-autoconfigure` to configure TLS fluenltly.
* Add meter exporsition for `DropwizardMeterRegistry`
* Remove unused configuration files.

Result:
Provide a consistent configuration to Armeria Dropwizard.
@ikhoon ikhoon added the cleanup label Jan 4, 2020
@ikhoon ikhoon requested review from minwoox and trustin as code owners January 4, 2020 18:22
@trustin
Copy link
Member

trustin commented Jan 6, 2020

Test failure:

com.linecorp.armeria.dropwizard.ArmeriaConfigurationUtilTest > configureServer() FAILED
    org.opentest4j.AssertionFailedError: 
    Expecting:
     <true>
    to be equal to:
     <false>
    but was not.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at com.linecorp.armeria.dropwizard.ArmeriaConfigurationUtilTest.configureServer(ArmeriaConfigurationUtilTest.java:61)

@trustin
Copy link
Member

trustin commented Jan 6, 2020

@Cricket007 PTAL

@ikhoon
Copy link
Contributor Author

ikhoon commented Jan 6, 2020

com.linecorp.armeria.dropwizard.ArmeriaConfigurationUtilTest > configureServer() FAILED

Oops... let me take a look. 😅

Copy link
Contributor

@OneCricketeer OneCricketeer left a comment

Choose a reason for hiding this comment

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

Not really a fan of this redundancy

type: armeria
armeria: 
   ... settings... 

If it cannot be flattened, that's fine

@OneCricketeer
Copy link
Contributor

My initial intention was to have a minimal rewrite from existing dropwizard http configuration to just replace the server type, not match any Spring config similarities

@ikhoon
Copy link
Contributor Author

ikhoon commented Jan 6, 2020

Not really a fan of this redundancy

type: armeria
armeria: 
   ... settings... 

I agreed, wanted to remove it but... I think we need own name to avoid conflict.

a-z seems rather broad, assuming just (kMGTP)?(Bb)

That is a nice suggestion. This is a fork of the original code.

private static final Pattern DATA_SIZE_PATTERN = Pattern.compile("^([+]?\\d+)([a-zA-Z]{0,2})$");

There are lots of duplication code between Dropwizard and Spring Boot configure.
After releasing 1.0 we plan to merge that APIs to provide a general interface. But now we decided to keep the code as equal as possible.

Let me add your review to TODO for further refactoring.

Simplify with Math.pow?

This one too.

My initial intention was to have a minimal rewrite from existing dropwizard http configuration to just replace the server type, not match any Spring config similarities

I understand your intention. As you mentioned in advanced-dropwizard-integration.rst, Armeria supports multiple protocols over the same port. I think the Dropwizard users could take advantage of that by this style configuration.

@OneCricketeer
Copy link
Contributor

I think we need own name to avoid conflict.

I'm not sure there's a conflict, I simply mean move "up" all properties of the ArmeriaSettings class directly into the ServerFactory.

@ikhoon
Copy link
Contributor Author

ikhoon commented Jan 6, 2020

I'm not sure there's a conflict, I simply mean move "up" all properties of the ArmeriaSettings class directly into the ServerFactory.

Let me remove the armeria namespace. I'm working on now. :-)

- Remove  `armeria` namespace in ArmeriaServerFactory
- Document `accessLog` property
- Add TODO commented by @Cricket007
@codecov
Copy link

codecov bot commented Jan 6, 2020

Codecov Report

Merging #2373 into master will decrease coverage by 0.17%.
The diff coverage is 73.34%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2373      +/-   ##
============================================
- Coverage     73.49%   73.32%   -0.18%     
- Complexity    10620    10690      +70     
============================================
  Files           928      934       +6     
  Lines         40845    41193     +348     
  Branches       5048     5142      +94     
============================================
+ Hits          30021    30206     +185     
- Misses         8272     8370      +98     
- Partials       2552     2617      +65
Impacted Files Coverage Δ Complexity Δ
...necorp/armeria/client/DecoratingClientFactory.java 50% <ø> (ø) 6 <0> (ø) ⬇️
...meria/common/metric/PrometheusMeterRegistries.java 90.9% <ø> (-0.76%) 5 <0> (ø)
...om/linecorp/armeria/common/logging/RequestLog.java 23.52% <ø> (ø) 8 <0> (ø) ⬇️
.../main/java/com/linecorp/armeria/common/Cookie.java 28.57% <ø> (ø) 22 <0> (ø) ⬇️
...ava/com/linecorp/armeria/server/RoutingResult.java 63.46% <ø> (ø) 20 <0> (ø) ⬇️
.../main/java/com/linecorp/armeria/client/Client.java 100% <ø> (ø) 1 <0> (ø) ⬇️
...p/armeria/dropwizard/ArmeriaConfigurationUtil.java 38.34% <ø> (-3.55%) 16 <0> (-1)
...linecorp/armeria/common/AggregatedHttpMessage.java 80% <ø> (ø) 4 <0> (ø) ⬇️
...etrofit2/RetrofitMeterIdPrefixFunctionBuilder.java 100% <ø> (ø) 3 <0> (ø) ⬇️
...com/linecorp/armeria/common/QueryParamGetters.java 66.66% <ø> (ø) 2 <0> (ø) ⬇️
... and 190 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7738209...2f77a76. Read the comment docs.

@trustin
Copy link
Member

trustin commented Jan 6, 2020

Sorry about the conflict. 😅

@ikhoon
Copy link
Contributor Author

ikhoon commented Jan 6, 2020

Sorry about the conflict. 😅

No worries. Let me resolve it :-)

Copy link
Contributor

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

some nits. 😄

@OneCricketeer
Copy link
Contributor

Hey, btw, I noticed the docs aren't on the main page yet

@ikhoon
Copy link
Contributor Author

ikhoon commented Jan 7, 2020

Hey, btw, I noticed the docs aren't on the main page yet

Did you mean the Armeria official homepage?
https://line.github.io/armeria/
Our latest version is 0.97.0. We didn’t release 0.98.0 yet. It will be seen after releasing the next version. 😉

@ikhoon ikhoon added this to the 0.98.0 milestone Jan 9, 2020
Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

Nice work, @ikhoon !

Copy link
Contributor

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Oops forgot to approve this.
Thanks @ikhoon!

@trustin
Copy link
Member

trustin commented Jan 10, 2020

Any other comments, @Cricket007 ? Would like to pull this in once you approve.

Copy link
Contributor

@OneCricketeer OneCricketeer left a comment

Choose a reason for hiding this comment

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

Minor feedback. Good work, otherwise

@@ -1 +0,0 @@
com.linecorp.armeria.dropwizard.logging.AccessLogWriterFactory
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this (and related files) really not needed?

Or did you just remove the @JsonTypeInfo usages?

Copy link
Contributor Author

@ikhoon ikhoon Jan 13, 2020

Choose a reason for hiding this comment

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

@JsonTypeInfo for AccessLogWriter has been removed, so I think we can remove it.
Because:

  1. The AccessLogWriter type and format can be configured via AccessLog in ArmeriaSettings.
    /**
    * Configurations for the access log.
    */
    static class AccessLog {
    /**
    * The access log type that is supposed to be one of
    * {@code "common"} {@code "combined"} or {@code "custom"}.
    */
    @Nullable
    private String type;
    /**
    * The access log format string.
    */
    @Nullable
    private String format;
    @Nullable
    String getType() {
    return type;
    }
    void setType(String type) {
    this.type = type;
    }
    @Nullable
    String getFormat() {
    return format;
    }
    void setFormat(String format) {
    this.format = format;
    }
    }
    }
  2. The AccessLogWriter is set to ServerBuilder statically in configureAccessLog
    private static void configureAccessLog(ServerBuilder serverBuilder, AccessLog accessLog) {
    if ("common".equals(accessLog.getType())) {
    serverBuilder.accessLogWriter(AccessLogWriter.common(), true);
    } else if ("combined".equals(accessLog.getType())) {
    serverBuilder.accessLogWriter(AccessLogWriter.combined(), true);
    } else if ("custom".equals(accessLog.getType())) {
    serverBuilder
    .accessLogWriter(AccessLogWriter.custom(accessLog.getFormat()), true);
    }
    }

Let me know if there is something I missed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I think statically assigned if-else (or switch on string) are code-smells.

https://refactoring.guru/replace-conditional-with-polymorphism

- Remove unused code
- Use MediaType constants for compresssion
@trustin trustin merged commit 29c82d8 into line:master Jan 13, 2020
@trustin
Copy link
Member

trustin commented Jan 13, 2020

Thanks a lot, @ikhoon and reviewers!

@ikhoon ikhoon deleted the dropwizard-configure branch January 15, 2020 06:41
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
Motivation:
Armeria's Spring Boot auto configure module offers to customize the Armeria server from JSON YAML.
Dropwizard module has been added to Armeria by line#2236. It can also customize Armeria Server from YAML.
But the configuration style is different between Spring Boot and Dropwizard.
The user should learn how to configure Armeria in each module. It may confuse the user.

Modification:
* Apply Spring Boot's YAML convention to the Dropwizard module.
* Add ArmeriaConfigurationUtil for applying ArmeriaSettings to
  ServerBuilder.
* Copy `CustomAliasKeyManagerFactory` and `CustomAliasX509ExtendedKeyManager` from
 `amreria/spring/boot-autoconfigure` to configure TLS fluenltly.
* Add meter exporsition for `DropwizardMeterRegistry`.
* Remove unused configuration files.

Result:
Provide a consistent configuration to Armeria Dropwizard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants