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

[JAV-589] provide vertx access log handler component #441

Merged

Conversation

yhs0092
Copy link
Member

@yhs0092 yhs0092 commented Dec 15, 2017

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [JAV-XXX] Fixes bug in ApproximateQuantiles, where you replace JAV-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

see details in https://servicecomb.atlassian.net/browse/JAV-589.
this PR provides a vertx access log printer.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 86.957% when pulling 52e20e5 on yhs0092:JAV-561_provide_vertx_access_log_component into 9f50bc0 on ServiceComb:master.

@@ -0,0 +1,38 @@
package io.servicecomb.transport.rest.vertx.accesslog;
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.";
Copy link
Member

Choose a reason for hiding this comment

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

This should be configurable.

Copy link
Member Author

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;
Copy link
Member

Choose a reason for hiding this comment

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

license header.

Copy link
Member Author

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:
Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

Choose a reason for hiding this comment

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

License header.

Copy link
Member Author

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 {
Copy link
Member

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?

Copy link
Member Author

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;
Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

Choose a reason for hiding this comment

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

License header.

Copy link
Member Author

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
Copy link
Member

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

Copy link
Member Author

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.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 86.956% when pulling c410a1e on yhs0092:JAV-561_provide_vertx_access_log_component into 9f50bc0 on ServiceComb:master.

@yhs0092
Copy link
Member Author

yhs0092 commented Dec 18, 2017

@WillemJiang New commit has passed ci, please review it again.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 86.971% when pulling 98071dc on yhs0092:JAV-561_provide_vertx_access_log_component into 9f50bc0 on ServiceComb:master.

@yhs0092 yhs0092 closed this Dec 19, 2017
@yhs0092 yhs0092 reopened this Dec 19, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 87.07% when pulling 394a199 on yhs0092:JAV-561_provide_vertx_access_log_component into 9f50bc0 on ServiceComb:master.


private String getProperty(String defaultValue, String key) {
String property = DynamicPropertyFactory.getInstance().getStringProperty(key, defaultValue).get();
if (null == property) {
Copy link
Contributor

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?

Copy link
Member Author

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);
Copy link
Contributor

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?

Copy link
Member Author

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> {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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 {
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Member Author

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;
Copy link
Contributor

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?

Copy link
Member Author

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.

@wujimin
Copy link
Contributor

wujimin commented Dec 21, 2017

where is traceId?
where is accessLog for highway?

do we have issues to trace this?

@yhs0092
Copy link
Member Author

yhs0092 commented Dec 21, 2017

@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.

@wujimin
Copy link
Contributor

wujimin commented Dec 22, 2017

ok
561 is a story
i think it's better to create subTasks in it. this PR is the first subTask

we need these subTasks at least:
1.highway support accesslog
2.generate traceId not depend on trace/access mechanism
3.support log traceId in accesslog

@WillemJiang WillemJiang reopened this Dec 22, 2017
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling d7ae8da on yhs0092:JAV-561_provide_vertx_access_log_component into ** on apache:master**.

@yhs0092 yhs0092 changed the title [JAV-561] provide access log handler component [JAV-589] provide access log handler component Dec 22, 2017
@yhs0092 yhs0092 changed the title [JAV-589] provide access log handler component [JAV-589] provide vertx access log handler component Dec 22, 2017
@yhs0092 yhs0092 force-pushed the JAV-561_provide_vertx_access_log_component branch from d7ae8da to 3546b3b Compare December 22, 2017 06:44
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 87.201% when pulling 3546b3b on yhs0092:JAV-561_provide_vertx_access_log_component into bdc2fd3 on apache:master.

@yhs0092 yhs0092 closed this Dec 22, 2017
@yhs0092 yhs0092 reopened this Dec 22, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 87.201% when pulling cc98df1 on yhs0092:JAV-561_provide_vertx_access_log_component into bdc2fd3 on apache:master.

@WillemJiang WillemJiang merged commit e4611cd into apache:master Dec 22, 2017
@yhs0092 yhs0092 deleted the JAV-561_provide_vertx_access_log_component branch July 23, 2018 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants