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

Logging configuration for specific declarative RestClient using named "client" properties aka quarkus.rest-client."client".logging.* #45520

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

lasteris
Copy link
Contributor

@lasteris lasteris commented Jan 11, 2025

Closes: #45519

Copy link

github-actions bot commented Jan 11, 2025

🙈 The PR is closed and the preview is expired.

This comment has been minimized.

This comment has been minimized.

@lasteris
Copy link
Contributor Author

lasteris commented Jan 11, 2025

Realized just now, that my solution also can be used via QuarkusRestClientBuilder.newBuilder()
.property(QuarkusRestClientProperties.LOGGING, ...) directly by users.
where ... is some implementation of RestClientsConfig.RestClientLoggingConfig interface :)

Comment on lines 443 to 446
RestClientsConfig.RestClientLoggingConfig logging = getConfiguration().hasProperty(QuarkusRestClientProperties.LOGGING)
? (RestClientsConfig.RestClientLoggingConfig) getConfiguration()
.getProperty(QuarkusRestClientProperties.LOGGING)
: restClients.logging();
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't say I understand this. I read the comment in the discussion, but I still don't understand why it's necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just not sure it's correct to read a property and try to cast it to a specific type if the property is not really exists in map here. I thought that this way is more safe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are about has property or about ternary ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RestClientsConfig.RestClientLoggingConfig logging =  (RestClientsConfig.RestClientLoggingConfig) getConfiguration() .getProperty(QuarkusRestClientProperties.LOGGING) : restClients.logging();

This is safe ?

Copy link
Contributor

Choose a reason for hiding this comment

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

My point is that I don't understand why this specific was change was made in the first place. What didn't work with the previous code?

Copy link
Contributor Author

@lasteris lasteris Jan 13, 2025

Choose a reason for hiding this comment

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

My point is that I don't understand why this specific was change was made in the first place. What didn't work with the previous code?

Maybe i am wrong...

But as i understand previous code it reads only Global config for all clients (e. g . quarkus.rest-client.logging, not quarkus.rest-client."name".logging), not specific. All specific properties read from getConfiguration().getProperty... (which previously set via quarkusrestclientbuildercdidelegate) am i wrong ?

Copy link
Contributor Author

@lasteris lasteris Jan 13, 2025

Choose a reason for hiding this comment

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

Sorry, i am trying to tell what i mean in another way :(
Previous code reads this:
io.quarkus.restclient.config.RestClientsConfig.logging()
but i wanted to propagate this:
io.quarkus.restclient.config.RestClientsConfig.clients[client].logging()

so, logging would work in the first place only for a specific declarative client, not for all like it works now

Copy link
Contributor

Choose a reason for hiding this comment

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

But as i understand previous code it reads only Global config for all clients (e. g . quarkus.rest-client.logging, not quarkus.rest-client."name".logging), not specific. All specific properties read from getConfiguration().getProperty... (which previously set via quarkusrestclientbuildercdidelegate) am i wrong ?

Correct, but the programmatic client doesn't have a name, so all it can do is read the global flag

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at what other config things do, I guess this is fine. But I would like to not pass the config object as I mention in https://github.com/quarkusio/quarkus/pull/45520/files#r1912958630

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But as i understand previous code it reads only Global config for all clients (e. g . quarkus.rest-client.logging, not quarkus.rest-client."name".logging), not specific. All specific properties read from getConfiguration().getProperty... (which previously set via quarkusrestclientbuildercdidelegate) am i wrong ?

Correct, but the programmatic client doesn't have a name, so all it can do is read the global flag

Yeah! That's why I've done it via

  1. trying to read named configuration
  2. if no property has read from named config, trying to read global (for programmatic api support).
    what am i missing ?

This comment has been minimized.

This comment has been minimized.

Comment on lines 88 to 96
private void configureLogging(QuarkusRestClientBuilder builder) {
Optional<RestClientsConfig.RestClientLoggingConfig> logging = restClientConfig.logging();
if (logging.isPresent()) {
builder.property(QuarkusRestClientProperties.LOGGING, logging.get());
} else if (configRoot.logging() != null) {
builder.property(QuarkusRestClientProperties.LOGGING, configRoot.logging());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We usually don't pass entire config objects like this, but only specific properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We usually don't pass entire config objects like this, but only specific properties.

yeah, I saw that. But really there are no configs here, grouped by object, except multipart. So, I thought that my choice won't be wrong...
but if you said so, I need to rethink code / add separate constants for body-limit and logging-scope

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer we have separate constants for scope and bodyLimit

Copy link
Contributor Author

@lasteris lasteris Jan 13, 2025

Choose a reason for hiding this comment

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

good, I will do it then

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 Author

@lasteris lasteris Jan 13, 2025

Choose a reason for hiding this comment

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

@geoand last question for now
what do you think about these lines anyway:

else if (configRoot.logging() != null) {
            builder.property(QuarkusRestClientProperties.LOGGING, configRoot.logging());
        }

maybe i should not try read global config thing, while it anyway would be read in RestClientBuilderImpl:

: restClients.logging();

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense

@lasteris lasteris force-pushed the QKS-45519 branch 2 times, most recently from f2b9547 to 1c22e49 Compare January 13, 2025 18:32

This comment has been minimized.

This comment has been minimized.

Comment on lines 90 to 95
restClientConfig.logging().ifPresent(logging -> {
builder.property(QuarkusRestClientProperties.LOGGING_SCOPE, logging.scope()
.map(LoggingScope::forName)
.orElse(LoggingScope.NONE));
builder.property(QuarkusRestClientProperties.LOGGING_BODY_LIMIT, logging.bodyLimit());
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get rid of the lambdas here please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

of course.
I've just thought, that it is better then get().somproperty.
is lambda blocked over all project ?

Copy link
Contributor

Choose a reason for hiding this comment

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

is lambda blocked over all project ?

Not strictly, it's just discouraged by some contributors (myself among them)

Copy link

quarkus-bot bot commented Jan 14, 2025

Status for workflow Quarkus Documentation CI

This is the status report for running Quarkus Documentation CI on commit f12169b.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

Warning

There are other workflow runs running, you probably need to wait for their status before merging.

Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

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

Thanks!

This comment has been minimized.

Copy link

quarkus-bot bot commented Jan 14, 2025

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit f12169b.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@geoand geoand merged commit c0b9484 into quarkusio:main Jan 14, 2025
35 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.18 - main milestone Jan 14, 2025
@quarkus-bot quarkus-bot bot added the kind/enhancement New feature or request label Jan 14, 2025
@lasteris lasteris changed the title Rest client per CDI injected client logging configuration Logging configuration for specific declarative RestClient using named "client" properties aka quarkus.rest-client."client".logging.* Jan 14, 2025
@lasteris lasteris deleted the QKS-45519 branch January 15, 2025 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logging configuration for specific declarative RestClient using named properties
2 participants