-
Notifications
You must be signed in to change notification settings - Fork 133
Provide a way to log successful and failed requests #719
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
Open
ikhoon
wants to merge
3
commits into
line:main
Choose a base branch
from
ikhoon:logging-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import static com.google.common.base.Strings.isNullOrEmpty; | ||
| import static com.linecorp.centraldogma.internal.api.v1.HttpApiV1Constants.API_V0_PATH_PREFIX; | ||
| import static com.linecorp.centraldogma.internal.api.v1.HttpApiV1Constants.API_V1_PATH_PREFIX; | ||
| import static com.linecorp.centraldogma.internal.api.v1.HttpApiV1Constants.DOCS_PATH; | ||
| import static com.linecorp.centraldogma.internal.api.v1.HttpApiV1Constants.HEALTH_CHECK_PATH; | ||
| import static com.linecorp.centraldogma.internal.api.v1.HttpApiV1Constants.METRICS_PATH; | ||
| import static com.linecorp.centraldogma.server.auth.AuthProvider.BUILTIN_WEB_BASE_PATH; | ||
|
|
@@ -38,6 +39,7 @@ | |
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.CompletionStage; | ||
| import java.util.concurrent.Executor; | ||
|
|
@@ -88,6 +90,7 @@ | |
| import com.linecorp.armeria.server.ServerPort; | ||
| import com.linecorp.armeria.server.ServiceNaming; | ||
| import com.linecorp.armeria.server.ServiceRequestContext; | ||
| import com.linecorp.armeria.server.TransientServiceOption; | ||
| import com.linecorp.armeria.server.auth.AuthService; | ||
| import com.linecorp.armeria.server.auth.Authorizer; | ||
| import com.linecorp.armeria.server.docs.DocService; | ||
|
|
@@ -96,6 +99,7 @@ | |
| import com.linecorp.armeria.server.file.HttpFile; | ||
| import com.linecorp.armeria.server.healthcheck.HealthCheckService; | ||
| import com.linecorp.armeria.server.logging.AccessLogWriter; | ||
| import com.linecorp.armeria.server.logging.LoggingService; | ||
| import com.linecorp.armeria.server.metric.MetricCollectingService; | ||
| import com.linecorp.armeria.server.metric.PrometheusExpositionService; | ||
| import com.linecorp.armeria.server.thrift.THttpService; | ||
|
|
@@ -147,11 +151,11 @@ | |
|
|
||
| import io.micrometer.core.instrument.MeterRegistry; | ||
| import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics; | ||
| import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics; | ||
| import io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics; | ||
| import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics; | ||
| import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; | ||
| import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics; | ||
| import io.micrometer.core.instrument.binder.system.DiskSpaceMetrics; | ||
| import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics; | ||
| import io.micrometer.core.instrument.binder.system.ProcessorMetrics; | ||
| import io.micrometer.core.instrument.binder.system.UptimeMetrics; | ||
|
|
@@ -206,6 +210,8 @@ public static CentralDogma forConfig(File configFile) throws IOException { | |
| private PrometheusMeterRegistry meterRegistry; | ||
| @Nullable | ||
| private SessionManager sessionManager; | ||
| @Nullable | ||
| private JvmGcMetrics jvmGcMetrics; | ||
|
|
||
| CentralDogma(CentralDogmaConfig cfg) { | ||
| this.cfg = requireNonNull(cfg, "cfg"); | ||
|
|
@@ -385,13 +391,13 @@ private CommandExecutor startCommandExecutor( | |
| logger.info("Starting plugins on the leader replica .."); | ||
| pluginsForLeaderOnly | ||
| .start(cfg, pm, exec, meterRegistry, purgeWorker).handle((unused, cause) -> { | ||
| if (cause == null) { | ||
| logger.info("Started plugins on the leader replica."); | ||
| } else { | ||
| logger.error("Failed to start plugins on the leader replica..", cause); | ||
| } | ||
| return null; | ||
| }); | ||
| if (cause == null) { | ||
| logger.info("Started plugins on the leader replica."); | ||
| } else { | ||
| logger.error("Failed to start plugins on the leader replica..", cause); | ||
| } | ||
| return null; | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -521,9 +527,67 @@ private Server startServer(ProjectManager pm, CommandExecutor executor, | |
|
|
||
| sb.service("/title", webAppTitleFile(cfg.webAppTitle(), SystemInfo.hostname()).asService()); | ||
|
|
||
| sb.service(HEALTH_CHECK_PATH, HealthCheckService.of()); | ||
| final RequestLogConfig requestLogConfig = cfg.requestLogConfig(); | ||
| boolean logHealthCheck = false; | ||
| boolean logMetrics = false; | ||
| if (requestLogConfig != null) { | ||
| final Function<? super HttpService, LoggingService> loggingService = | ||
| LoggingService.builder() | ||
| .logger(requestLogConfig.loggerName()) | ||
| .requestLogLevel(requestLogConfig.requestLogLevel()) | ||
| .successfulResponseLogLevel(requestLogConfig.successfulResponseLogLevel()) | ||
| .failureResponseLogLevel(requestLogConfig.failureResponseLogLevel()) | ||
| .successSamplingRate(requestLogConfig.successSamplingRate()) | ||
| .failureSamplingRate(requestLogConfig.failureSamplingRate()) | ||
| .newDecorator(); | ||
| final Set<RequestLogGroup> requestLogGroups = requestLogConfig.targetGroups(); | ||
| if (requestLogGroups.contains(RequestLogGroup.ALL)) { | ||
| sb.decorator(loggingService); | ||
| logHealthCheck = true; | ||
| logMetrics = true; | ||
| } else { | ||
| for (RequestLogGroup logGroup : requestLogGroups) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about also supporting the specified path? e.g. |
||
| switch (logGroup) { | ||
| case API: | ||
| sb.decoratorUnder("/api", loggingService); | ||
| break; | ||
| case METRICS: | ||
| sb.decorator(METRICS_PATH, loggingService); | ||
| logMetrics = true; | ||
| break; | ||
| case HEALTH: | ||
| sb.decorator(HEALTH_CHECK_PATH, loggingService); | ||
| logHealthCheck = true; | ||
| break; | ||
| case DOCS: | ||
| sb.decoratorUnder(DOCS_PATH, loggingService); | ||
| break; | ||
| case WEB: | ||
| for (String webResources : ImmutableList.of("/web", "/vendor", | ||
| "/scripts", "/styles")) { | ||
| sb.decoratorUnder(webResources, loggingService); | ||
| } | ||
| break; | ||
| case ALL: | ||
| // Should never reach here. | ||
| throw new Error(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| final HealthCheckService healthCheckService; | ||
| if (logHealthCheck) { | ||
| healthCheckService = | ||
| HealthCheckService.builder() | ||
| .transientServiceOptions(TransientServiceOption.WITH_SERVICE_LOGGING) | ||
| .build(); | ||
| } else { | ||
| healthCheckService = HealthCheckService.of(); | ||
| } | ||
| sb.service(HEALTH_CHECK_PATH, healthCheckService); | ||
|
|
||
| sb.serviceUnder("/docs/", | ||
| sb.serviceUnder(DOCS_PATH, | ||
| DocService.builder() | ||
| .exampleHeaders(CentralDogmaService.class, | ||
| HttpHeaders.of(HttpHeaderNames.AUTHORIZATION, | ||
|
|
@@ -532,7 +596,7 @@ private Server startServer(ProjectManager pm, CommandExecutor executor, | |
|
|
||
| configureHttpApi(sb, pm, executor, watchService, mds, authProvider, sessionManager); | ||
|
|
||
| configureMetrics(sb, meterRegistry); | ||
| configureMetrics(sb, meterRegistry, logMetrics); | ||
|
|
||
| // Configure access log format. | ||
| final String accessLogFormat = cfg.accessLogFormat(); | ||
|
|
@@ -776,9 +840,18 @@ private static Function<? super HttpService, EncodingService> contentEncodingDec | |
| .build(delegate); | ||
| } | ||
|
|
||
| private void configureMetrics(ServerBuilder sb, PrometheusMeterRegistry registry) { | ||
| private void configureMetrics(ServerBuilder sb, PrometheusMeterRegistry registry, boolean logMetrics) { | ||
| sb.meterRegistry(registry); | ||
| sb.service(METRICS_PATH, new PrometheusExpositionService(registry.getPrometheusRegistry())); | ||
| final PrometheusExpositionService expositionService; | ||
| if (logMetrics) { | ||
| expositionService = PrometheusExpositionService.builder(registry.getPrometheusRegistry()) | ||
| .transientServiceOptions( | ||
| TransientServiceOption.WITH_SERVICE_LOGGING) | ||
| .build(); | ||
| } else { | ||
| expositionService = PrometheusExpositionService.of(registry.getPrometheusRegistry()); | ||
| } | ||
| sb.service(METRICS_PATH, expositionService); | ||
| sb.decorator(MetricCollectingService.newDecorator(MeterIdPrefixFunction.ofDefault("api"))); | ||
|
|
||
| // Bind system metrics. | ||
|
|
@@ -787,7 +860,8 @@ private void configureMetrics(ServerBuilder sb, PrometheusMeterRegistry registry | |
| new ClassLoaderMetrics().bindTo(registry); | ||
| new UptimeMetrics().bindTo(registry); | ||
| new DiskSpaceMetrics(cfg.dataDir()).bindTo(registry); | ||
| new JvmGcMetrics().bindTo(registry); | ||
| jvmGcMetrics = new JvmGcMetrics(); | ||
| jvmGcMetrics.bindTo(registry); | ||
| new JvmMemoryMetrics().bindTo(registry); | ||
| new JvmThreadMetrics().bindTo(registry); | ||
|
|
||
|
|
@@ -817,6 +891,11 @@ private void doStop() { | |
| meterRegistry = null; | ||
| } | ||
|
|
||
| if (jvmGcMetrics != null) { | ||
| jvmGcMetrics.close(); | ||
| jvmGcMetrics = null; | ||
| } | ||
|
|
||
| logger.info("Stopping the Central Dogma .."); | ||
| if (!doStop(server, executor, pm, repositoryWorker, purgeWorker, sessionManager)) { | ||
| logger.warn("Stopped the Central Dogma with failure."); | ||
|
|
||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Question: Is it possible that users may want to configure different logging parameters for different paths?
e.g.
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.
Oh... It is so nice! 👍
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.
We can implement it by adding different
LoggingServices.