-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce AccessLogWriterUtil and Remove Unnecessary RequestContext P…
…ush/Pop (#5985) Motivation: As described in #5984, there are instances of unnecessary request context push/pop operations related to access logging when the access log writer is disabled. These operations are redundant since the logging path does not need to be triggered when the writer is disabled. Optimizing this behavior reduces unnecessary overhead in such cases. Modifications: - Added `AccessLogWriterUtil#maybeWriteAccessLog` - Writes access log only when `TransientServiceOption#WITH_ACCESS_LOGGING` is enabled and the access log writer is not disabled. - Updated `AbstractHttpResponseHandler` and `HttpServerHandler` Result: - Closes #5984. - Removes unnecessary context push/pop operations for access logging when the access log writer is disabled, resulting in a more efficient request handling process.
- Loading branch information
1 parent
095bcae
commit 6b40f84
Showing
7 changed files
with
149 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
core/src/main/java/com/linecorp/armeria/server/AccessLogWriterUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2024 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.linecorp.armeria.server; | ||
|
||
import com.linecorp.armeria.common.util.SafeCloseable; | ||
import com.linecorp.armeria.server.logging.AccessLogWriter; | ||
|
||
/** | ||
* Utility class for {@link AccessLogWriter}. | ||
*/ | ||
final class AccessLogWriterUtil { | ||
|
||
/** | ||
* Writes an access log if the {@link TransientServiceOption#WITH_ACCESS_LOGGING} option is enabled | ||
* for the {@link ServiceConfig#transientServiceOptions()} and the {@link ServiceConfig#accessLogWriter()} | ||
* is not {@link AccessLogWriter#disabled()} for the given {@link ServiceRequestContext#config()}. | ||
*/ | ||
static void maybeWriteAccessLog(ServiceRequestContext reqCtx) { | ||
final ServiceConfig config = reqCtx.config(); | ||
if (shouldWriteAccessLog(config)) { | ||
reqCtx.log().whenComplete().thenAccept(log -> { | ||
try (SafeCloseable ignored = reqCtx.push()) { | ||
config.accessLogWriter().log(log); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Returns whether an access log should be written. | ||
* | ||
*/ | ||
private static boolean shouldWriteAccessLog(ServiceConfig config) { | ||
return config.accessLogWriter() != AccessLogWriter.disabled() && | ||
config.transientServiceOptions().contains(TransientServiceOption.WITH_ACCESS_LOGGING); | ||
} | ||
|
||
private AccessLogWriterUtil() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters