-
Notifications
You must be signed in to change notification settings - Fork 801
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
[JAV-589] provide vertx access log handler component #441
[JAV-589] provide vertx access log handler component #441
Conversation
@@ -0,0 +1,38 @@ | |||
package io.servicecomb.transport.rest.vertx.accesslog; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the license header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License header has been added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the new add Apache license, you can get it from the master code.
import io.servicecomb.core.BootListener.BootEvent; | ||
|
||
public final class AccessLogConfiguration { | ||
private static final String BASE = "cse.accesslog."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be configurable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the name prefix of configuration item. It has been renamed to "servicecomb.accesslog."
@@ -0,0 +1,8 @@ | |||
package io.servicecomb.transport.rest.vertx.accesslog; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
license header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License header has been added.
|
||
To enable access log printing, you can config access log in microservice.yaml like below: | ||
```yaml | ||
cse: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to use servicecomb prefix instead of cse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prefix "cse" has been replaced with "servicecomb".
@@ -0,0 +1,16 @@ | |||
package io.servicecomb.transport.rest.vertx.accesslog.element; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License header has been added.
import io.servicecomb.transport.rest.vertx.accesslog.element.AccessLogElement; | ||
import io.vertx.core.http.HttpServerResponse; | ||
|
||
public class BytesWrittenV2Element implements AccessLogElement { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we have two versions of bytes written element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They will return different result when bytes written is zero. v1 is "0" and v2 is "-".
|
||
import java.util.Set; | ||
|
||
import com.sun.org.apache.regexp.internal.RE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use the internal API which may not be compatible with other JDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is added by mistake. Has been removed.
@@ -0,0 +1,97 @@ | |||
package io.servicecomb.transport.rest.vertx.accesslog.element.impl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License header has been added.
@@ -0,0 +1,13 @@ | |||
# access log default configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log configure should be provide from the Application level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User can override the access log configuration in their log4j.properties. Or totally replace Log4j with other log printer framework, since this AccessLogHandlerImpl just depends on slf4j.
@WillemJiang New commit has passed ci, please review it again. |
|
||
private String getProperty(String defaultValue, String key) { | ||
String property = DynamicPropertyFactory.getInstance().getStringProperty(key, defaultValue).get(); | ||
if (null == property) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can we got null in this place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this null check has been removed.
|
||
public boolean getAccessLogEnabled() { | ||
String enabled = getProperty("false", ACCESSLOG_ENABLED); | ||
return Boolean.parseBoolean(enabled); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while not just DynamicPropertyFactory.getInstance().getBooleanProperty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been changed to use DynamicPropertyFactory.getInstance().getBooleanProperty()
import io.vertx.core.Handler; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public interface AccessLogHandler extends Handler<RoutingContext> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the purpose of this interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interface has been removed. Now, it's implementation AccessLogHandlerImpl implements the interface Handler directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class AccessLogHandlerImpl is renamed to AccessLogHandler since this interface no longer exists.
long bytesWritten = response.bytesWritten(); | ||
if (0 == bytesWritten) { | ||
return ZERO_BYTES; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already return, no need else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If bytesWritten equals to 0, "-" will be returned instead of "0". So there should be this check logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check is no problem
"else" is unnecessary
@Override | ||
public String getFormattedElement(AccessLogParam accessLogParam) { | ||
RoutingContext context = accessLogParam.getRoutingContext(); | ||
if (null == context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can we got a null context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This null check has been removed.
import io.vertx.core.AbstractVerticle; | ||
import io.vertx.core.Context; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.http.HttpServer; | ||
import io.vertx.core.http.HttpServerOptions; | ||
import io.vertx.ext.web.Router; | ||
import io.vertx.ext.web.handler.LoggerFormat; | ||
import io.vertx.ext.web.handler.impl.LoggerHandlerImpl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import but not used
so you did not resolve compile warnings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These unused imports have been removed, I will take care in the next time.
where is traceId? do we have issues to trace this? |
@wujimin The issue JAV-561 is still in progress. Other features you mentioned are still in developing. I create this PR to commit the first part of this issue(access log of vertx) because it's too large to commit all content in one PR. |
ok we need these subTasks at least: |
Changes Unknown when pulling d7ae8da on yhs0092:JAV-561_provide_vertx_access_log_component into ** on apache:master**. |
… setting variety.
…to unit test file.
d7ae8da
to
3546b3b
Compare
Follow this checklist to help us incorporate your contribution quickly and easily:
[JAV-XXX] Fixes bug in ApproximateQuantiles
, where you replaceJAV-XXX
with the appropriate JIRA issue.mvn clean install
to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.see details in https://servicecomb.atlassian.net/browse/JAV-589.
this PR provides a vertx access log printer.