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

[SCB-2813]fix access log related problems #4032

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package org.apache.servicecomb.common.accessLog;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AccessLogConfiguration {
@Bean
public AccessLogBootListener accessLogBootListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.servicecomb.common.accessLog.AccessLogInitializer;
import org.apache.servicecomb.common.accessLog.core.AccessLogGenerator;
import org.apache.servicecomb.core.event.InvocationFinishEvent;

import org.apache.servicecomb.swagger.invocation.InvocationType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -31,7 +30,7 @@
import com.google.common.eventbus.Subscribe;

public class ClientDefaultInitializer implements AccessLogInitializer {
private static final Logger LOGGER = LoggerFactory.getLogger("requestlog");
private static final Logger LOGGER = LoggerFactory.getLogger("scb-access");

private AccessLogGenerator accessLogGenerator;

Expand All @@ -48,7 +47,7 @@ public void init(EventBus eventBus, AccessLogConfig accessLogConfig) {
@AllowConcurrentEvents
public void onRequestOut(InvocationFinishEvent finishEvent) {
if (InvocationType.CONSUMER.equals(finishEvent.getInvocation().getInvocationType())) {
LOGGER.info(accessLogGenerator.generateClientLog(finishEvent));
LOGGER.info(accessLogGenerator.generateClientLog(finishEvent));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.servicecomb.core.definition.SchemaMeta;
import org.apache.servicecomb.core.event.InvocationFinishEvent;
import org.apache.servicecomb.core.event.ServerAccessLogEvent;
import org.apache.servicecomb.swagger.SwaggerUtils;
import org.apache.servicecomb.transport.rest.client.RestClientRequestParameters;

import io.vertx.core.http.HttpServerRequest;
Expand All @@ -50,7 +49,7 @@ public void appendClientFormattedItem(InvocationFinishEvent finishEvent, StringB
OperationMeta operationMeta = finishEvent.getInvocation().getOperationMeta();
SchemaMeta schemaMeta = finishEvent.getInvocation().getSchemaMeta();
if (operationMeta != null && schemaMeta != null && schemaMeta.getSwagger() != null) {
builder.append(SwaggerUtils.getBasePath(schemaMeta.getSwagger())).append(operationMeta.getOperationPath());
builder.append(operationMeta.getOperationPath());
return;
}
RestClientRequestParameters restRequestImpl = (RestClientRequestParameters) finishEvent.getInvocation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

public class ServerDefaultInitializer implements AccessLogInitializer {

private static final Logger LOGGER = LoggerFactory.getLogger("accesslog");
private static final Logger LOGGER = LoggerFactory.getLogger("scb-access");

private AccessLogGenerator accessLogGenerator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -36,7 +35,6 @@
import org.mockito.Mockito;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.servers.Server;
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.ext.web.RoutingContext;
Expand Down Expand Up @@ -85,14 +83,11 @@ public void initStrBuilder() {

@Test
public void clientFormattedElement() {
String uri = "/base/test";
String uri = "/test";
when(finishEvent.getInvocation()).thenReturn(invocation);
when(invocation.getOperationMeta()).thenReturn(operationMeta);
when(invocation.getSchemaMeta()).thenReturn(schemaMeta);
when(schemaMeta.getSwagger()).thenReturn(swagger);
Server server = Mockito.mock(Server.class);
when(server.getUrl()).thenReturn("/base");
when(swagger.getServers()).thenReturn(Arrays.asList(server));
when(operationMeta.getOperationPath()).thenReturn("/test");

ITEM.appendClientFormattedItem(finishEvent, strBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.apache.servicecomb.config.file.MicroserviceConfigLoader;
import org.apache.servicecomb.foundation.bootstrap.BootStrapService;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -47,6 +48,7 @@ public class ConfigEnvironmentPostProcessor implements EnvironmentPostProcessor

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
LegacyPropertyFactory.setEnvironment(environment);
addMicroserviceDefinitions(environment);
startupBootStrapService(environment);
addDynamicConfigurationToSpring(environment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.servicecomb.config.priority.ConfigObjectFactory;
import org.apache.servicecomb.config.priority.PriorityPropertyFactory;
import org.apache.servicecomb.config.priority.PriorityPropertyManager;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -60,11 +59,6 @@ public DataCenterProperties dataCenterProperties() {
return new DataCenterProperties();
}

@Bean
public LegacyPropertyFactory legacyPropertyFactory(Environment environment) {
return new LegacyPropertyFactory(environment);
}

@Bean
public InMemoryDynamicPropertiesSource inMemoryDynamicPropertiesSource() {
return new InMemoryDynamicPropertiesSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static void logSlowProvider(Invocation invocation, Response response, Op
.append(formatPair(" ", "http method", restOperationMeta.getHttpMethod()))
.append(formatPair(" ", "url", restOperationMeta.getAbsolutePath()))
.append(formatPair(" ", "endpoint", collectClientAddress(invocation)))
.append(formatPair(" ", "status code", response.getStatusCode()))
.append(formatPair(" ", "status code", String.valueOf(response.getStatusCode())))

.append(formatPair(" ", STAGE_TOTAL, stageTrace.calcTotal()))
.append(formatPair(" ", STAGE_PREPARE, stageTrace.calcPrepare()))
Expand Down Expand Up @@ -141,7 +141,7 @@ private static void logSlowConsumer(Invocation invocation, Response response, Op
.append(formatPair(" ", "http method", restOperationMeta.getHttpMethod()))
.append(formatPair(" ", "url", restOperationMeta.getAbsolutePath()))
.append(formatPair(" ", "endpoint", collectTargetAddress(invocation)))
.append(formatPair(" ", "status code", response.getStatusCode()))
.append(formatPair(" ", "status code", String.valueOf(response.getStatusCode())))
.append(formatPair(" ", STAGE_TOTAL, stageTrace.calcTotal()))
.append(formatPair(" ", STAGE_PREPARE, stageTrace.calcPrepare()))
.append(formatPair(" ", STAGE_CONSUMER_CONNECTION, stageTrace.calcConnection()))
Expand Down Expand Up @@ -169,7 +169,7 @@ private static void logSlowEdge(Invocation invocation, Response response, Operat
.append(formatPair(" ", "http method", restOperationMeta.getHttpMethod()))
.append(formatPair(" ", "url", restOperationMeta.getAbsolutePath()))
.append(formatPair(" ", "endpoint", collectTargetAddress(invocation)))
.append(formatPair(" ", "status code", response.getStatusCode()))
.append(formatPair(" ", "status code", String.valueOf(response.getStatusCode())))
.append(formatPair(" ", STAGE_TOTAL, stageTrace.calcTotal()))
.append(formatPair(" ", STAGE_PREPARE, stageTrace.calcPrepare()))
.append(formatPair(" ", STAGE_PROVIDER_DECODE_REQUEST, stageTrace.calcProviderDecodeRequest()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void consumerSlow(@Mocked Endpoint endpoint) {
http method : null
url : null
endpoint : rest://1.1.1.1:1234
status code : 0.0ms
status code : 0
total : 0.0ms
prepare : 0.0ms
connection : 0.0ms
Expand Down Expand Up @@ -168,7 +168,7 @@ public void edgeSlow(@Mocked Endpoint endpoint) {
http method : null
url : null
endpoint : rest://1.1.1.1:1234
status code : 0.0ms
status code : 0
total : 0.0ms
prepare : 0.0ms
provider-decode : 0.0ms
Expand Down Expand Up @@ -212,7 +212,7 @@ public void producerSlow(@Mocked HttpServletRequestEx requestEx) {
http method : null
url : null
endpoint : 1.1.1.1:1234
status code : 0.0ms
status code : 0
total : 0.0ms
prepare : 0.0ms
provider-decode : 0.0ms
Expand Down
6 changes: 4 additions & 2 deletions solutions/solution-basic/src/main/resources/microservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ servicecomb:
# metrics and access log
accesslog:
enabled: true
pattern: "|%h|%r|%s|%D"

metrics:
window_time: 60000
window_time: 300000
invocation:
latencyDistribution: 0,1,10,100,1000
latencyDistribution: 0,10,50,100,1000
Consumer.invocation.slow:
enabled: true
msTime: 1000
Expand Down
Loading