From 4d5f4195db368ecda4710a9e39f04f5a0f5f4d76 Mon Sep 17 00:00:00 2001 From: SunnyBoy-WYH <48077841+SunnyBoy-WYH@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:15:32 +0800 Subject: [PATCH 1/2] chore(api): add swagger desc for Arthas & Metric & Cypher & White API (#2337) add swagger belong for arthas API --------- Co-authored-by: imbajin --- .github/workflows/ci.yml | 6 ++-- hugegraph-api/pom.xml | 2 +- .../hugegraph/api/arthas/ArthasAPI.java | 5 ++++ .../hugegraph/api/cypher/CypherAPI.java | 3 ++ .../hugegraph/api/job/AlgorithmAPI.java | 3 ++ .../hugegraph/api/metrics/MetricsAPI.java | 11 +++++++ .../hugegraph/api/profile/WhiteIpListAPI.java | 6 ++++ .../scripts/dependency/known-dependencies.txt | 29 ++++++++++--------- pom.xml | 1 + 9 files changed, 49 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 414fd4a3f7..b67021fab9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: HEAD_BRANCH_NAME: ${{ github.head_ref }} BASE_BRANCH_NAME: ${{ github.base_ref }} TARGET_BRANCH_NAME: ${{ github.base_ref != '' && github.base_ref || github.ref_name }} - RELEASE_BRANCH: ${{ startsWith(github.ref_name, 'release-') || startsWith(github.ref_name, 'test-') || startsWith(github.base_ref, 'release-') }} + RELEASE_BRANCH: ${{ startsWith(github.ref_name, 'release-') || startsWith(github.ref_name, 'test-') }} strategy: fail-fast: false @@ -42,7 +42,7 @@ jobs: restore-keys: ${{ runner.os }}-m2 - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 2 @@ -88,6 +88,6 @@ jobs: $TRAVIS_DIR/run-tinkerpop-test.sh $BACKEND tinkerpop - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3.0.0 + uses: codecov/codecov-action@v3 with: file: ${{ env.REPORT_DIR }}/*.xml diff --git a/hugegraph-api/pom.xml b/hugegraph-api/pom.xml index b99cde52cf..ad397f18ee 100644 --- a/hugegraph-api/pom.xml +++ b/hugegraph-api/pom.xml @@ -151,7 +151,7 @@ io.swagger.core.v3 swagger-jaxrs2-jakarta - 2.1.9 + ${swagger.version} diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/api/arthas/ArthasAPI.java b/hugegraph-api/src/main/java/org/apache/hugegraph/api/arthas/ArthasAPI.java index 549f9de0a8..67e65a31a8 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/api/arthas/ArthasAPI.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/api/arthas/ArthasAPI.java @@ -27,6 +27,9 @@ import com.codahale.metrics.annotation.Timed; import com.taobao.arthas.agent.attach.ArthasAgent; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; + import jakarta.inject.Singleton; import jakarta.ws.rs.PUT; import jakarta.ws.rs.Path; @@ -35,6 +38,7 @@ @Path("arthas") @Singleton +@Tag(name = "ArthasAPI") public class ArthasAPI extends API { @Context @@ -43,6 +47,7 @@ public class ArthasAPI extends API { @PUT @Timed @Produces(APPLICATION_JSON_WITH_CHARSET) + @Operation(summary = "start arthas agent") public Object startArthas() { HugeConfig config = this.configProvider.get(); HashMap configMap = new HashMap<>(4); diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/api/cypher/CypherAPI.java b/hugegraph-api/src/main/java/org/apache/hugegraph/api/cypher/CypherAPI.java index bf43d6af44..0018bcd2f2 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/api/cypher/CypherAPI.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/api/cypher/CypherAPI.java @@ -33,6 +33,8 @@ import com.codahale.metrics.annotation.Timed; +import io.swagger.v3.oas.annotations.tags.Tag; + import jakarta.inject.Singleton; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.GET; @@ -47,6 +49,7 @@ @Path("graphs/{graph}/cypher") @Singleton +@Tag(name = "CypherAPI") public class CypherAPI extends API { private static final Logger LOG = Log.logger(CypherAPI.class); diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/AlgorithmAPI.java b/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/AlgorithmAPI.java index 8e0e7d10c3..8341adad8b 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/AlgorithmAPI.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/AlgorithmAPI.java @@ -36,6 +36,8 @@ import com.codahale.metrics.annotation.Timed; import com.google.common.collect.ImmutableMap; +import io.swagger.v3.oas.annotations.tags.Tag; + import jakarta.inject.Singleton; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.NotFoundException; @@ -47,6 +49,7 @@ @Path("graphs/{graph}/jobs/algorithm") @Singleton +@Tag(name = "AlgorithmAPI") public class AlgorithmAPI extends API { private static final Logger LOG = Log.logger(RestServer.class); diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/api/metrics/MetricsAPI.java b/hugegraph-api/src/main/java/org/apache/hugegraph/api/metrics/MetricsAPI.java index f74286b5f8..952ac90eeb 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/api/metrics/MetricsAPI.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/api/metrics/MetricsAPI.java @@ -70,7 +70,9 @@ import com.codahale.metrics.Metric; import com.codahale.metrics.annotation.Timed; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; + import jakarta.annotation.security.RolesAllowed; import jakarta.inject.Singleton; import jakarta.ws.rs.GET; @@ -103,6 +105,7 @@ public MetricsAPI() { @Path("system") @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin", "$owner= $action=metrics_read"}) + @Operation(summary = "get the system metrics") public String system() { return JsonUtil.toJson(this.systemMetrics.metrics()); } @@ -112,6 +115,7 @@ public String system() { @Path("backend") @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin", "$owner= $action=metrics_read"}) + @Operation(summary = "get the backend metrics") public String backend(@Context GraphManager manager) { Map> results = InsertionOrderUtil.newMap(); for (String graph : manager.graphs()) { @@ -134,6 +138,7 @@ public String backend(@Context GraphManager manager) { @Path("gauges") @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin", "$owner= $action=metrics_read"}) + @Operation(summary = "get the gauges metrics") public String gauges() { ServerReporter reporter = ServerReporter.instance(); return JsonUtil.toJson(reporter.gauges()); @@ -144,6 +149,7 @@ public String gauges() { @Path("counters") @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin", "$owner= $action=metrics_read"}) + @Operation(summary = "get the counters metrics") public String counters() { ServerReporter reporter = ServerReporter.instance(); return JsonUtil.toJson(reporter.counters()); @@ -154,6 +160,7 @@ public String counters() { @Path("histograms") @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin", "$owner= $action=metrics_read"}) + @Operation(summary = "get the histograms metrics") public String histograms() { ServerReporter reporter = ServerReporter.instance(); return JsonUtil.toJson(reporter.histograms()); @@ -164,6 +171,7 @@ public String histograms() { @Path("meters") @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin", "$owner= $action=metrics_read"}) + @Operation(summary = "get the meters metrics") public String meters() { ServerReporter reporter = ServerReporter.instance(); return JsonUtil.toJson(reporter.meters()); @@ -174,6 +182,7 @@ public String meters() { @Path("timers") @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin", "$owner= $action=metrics_read"}) + @Operation(summary = "get the timers metrics") public String timers() { ServerReporter reporter = ServerReporter.instance(); return JsonUtil.toJson(reporter.timers()); @@ -183,6 +192,7 @@ public String timers() { @Timed @Produces(APPLICATION_TEXT_WITH_CHARSET) @RolesAllowed({"admin", "$owner= $action=metrics_read"}) + @Operation(summary = "get all base metrics") public String all(@Context GraphManager manager, @QueryParam("type") String type) { if (type != null && type.equals(JSON_STR)) { @@ -197,6 +207,7 @@ public String all(@Context GraphManager manager, @Timed @Produces(APPLICATION_TEXT_WITH_CHARSET) @RolesAllowed({"admin", "$owner= $action=metrics_read"}) + @Operation(summary = "get all statistics metrics") public String statistics(@QueryParam("type") String type) { Map> metricMap = statistics(); diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/api/profile/WhiteIpListAPI.java b/hugegraph-api/src/main/java/org/apache/hugegraph/api/profile/WhiteIpListAPI.java index 7503e13822..860da55750 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/api/profile/WhiteIpListAPI.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/api/profile/WhiteIpListAPI.java @@ -37,6 +37,8 @@ import com.codahale.metrics.annotation.Timed; import com.google.common.collect.ImmutableMap; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.security.RolesAllowed; import jakarta.inject.Singleton; import jakarta.ws.rs.Consumes; @@ -50,6 +52,7 @@ @Path("whiteiplist") @Singleton +@Tag(name = "WhiteIpListAPI") public class WhiteIpListAPI extends API { private static final Logger LOG = Log.logger(WhiteIpListAPI.class); @@ -58,6 +61,7 @@ public class WhiteIpListAPI extends API { @Timed @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed("admin") + @Operation(summary = "list white ips") public Map list(@Context GraphManager manager) { LOG.debug("List white ips"); AuthManager authManager = manager.authManager(); @@ -71,6 +75,7 @@ public Map list(@Context GraphManager manager) { @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed("admin") + @Operation(summary = "update white ip list") public Map updateWhiteIPs(@Context GraphManager manager, Map actionMap) { E.checkArgument(actionMap != null, "Missing argument: actionMap"); @@ -131,6 +136,7 @@ public Map updateWhiteIPs(@Context GraphManager manager, Map updateStatus(@Context GraphManager manager, @QueryParam("status") String status) { LOG.debug("Enable or disable white ip list"); E.checkArgument("true".equals(status) || diff --git a/hugegraph-dist/scripts/dependency/known-dependencies.txt b/hugegraph-dist/scripts/dependency/known-dependencies.txt index f1388437c7..d40b204333 100644 --- a/hugegraph-dist/scripts/dependency/known-dependencies.txt +++ b/hugegraph-dist/scripts/dependency/known-dependencies.txt @@ -32,7 +32,7 @@ chronicle-core-2.20.126.jar chronicle-queue-5.20.123.jar chronicle-threads-2.20.111.jar chronicle-wire-2.20.117.jar -classgraph-4.8.95.jar +classgraph-4.8.162.jar commons-beanutils-1.9.4.jar commons-cli-1.1.jar commons-codec-1.11.jar @@ -112,14 +112,16 @@ jackson-annotations-2.13.2.jar jackson-annotations-2.14.0-rc1.jar jackson-core-2.13.2.jar jackson-core-2.14.0-rc1.jar -jackson-databind-2.12.1.jar jackson-databind-2.13.2.2.jar jackson-databind-2.14.0-rc1.jar +jackson-databind-2.15.2.jar jackson-dataformat-yaml-2.9.3.jar -jackson-datatype-jsr310-2.12.1.jar +jackson-datatype-jsr310-2.15.2.jar +jackson-jakarta-rs-base-2.15.2.jar +jackson-jakarta-rs-json-provider-2.15.2.jar jackson-jaxrs-base-2.14.0-rc1.jar -jackson-jaxrs-json-provider-2.12.1-jakarta.jar jackson-jaxrs-json-provider-2.14.0-rc1.jar +jackson-module-jakarta-xmlbind-annotations-2.15.2.jar jackson-module-jaxb-annotations-2.14.0-rc1.jar jakarta.activation-2.0.1.jar jakarta.activation-api-1.2.2.jar @@ -131,7 +133,6 @@ jakarta.ws.rs-api-3.0.0.jar jakarta.xml.bind-api-4.0.0-RC2.jar jamm-0.3.2.jar java-cup-runtime-11b-20160615.jar -jcommander-1.30.jar javapoet-1.8.0.jar javassist-3.21.0-GA.jar javatuples-1.2.jar @@ -146,6 +147,7 @@ jcabi-log-0.14.jar jcabi-manifests-1.1.jar jcip-annotations-1.0-1.jar jcl-over-slf4j-1.7.25.jar +jcommander-1.30.jar jcseg-core-2.6.2.jar jctools-core-2.1.1.jar jctools-core-3.1.0.jar @@ -175,12 +177,12 @@ jna-5.12.1.jar jnr-ffi-2.1.7.jar jnr-x86asm-1.0.2.jar joda-time-2.10.8.jar -jvm-attach-api-1.5.jar jraft-core-1.3.11.jar json-simple-1.1.jar json-smart-2.3.jar jsr305-3.0.1.jar junit-4.12.jar +jvm-attach-api-1.5.jar kerb-admin-2.0.0.jar kerb-client-2.0.0.jar kerb-common-2.0.0.jar @@ -245,14 +247,15 @@ rocksdbjni-7.2.2.jar scala-java8-compat_2.12-0.8.0.jar scala-library-2.12.7.jar scala-reflect-2.12.7.jar +sigar-1.6.4.jar sjk-cli-0.14.jar sjk-core-0.14.jar sjk-json-0.14.jar sjk-stacktrace-0.14.jar -sigar-1.6.4.jar slf4j-api-1.7.25.jar snakeyaml-1.26.jar snakeyaml-1.27.jar +snakeyaml-2.2.jar snappy-java-1.1.2.6.jar snowball-stemmer-1.3.0.581.1.jar sofa-common-tools-1.0.12.jar @@ -260,18 +263,18 @@ sofa-rpc-all-5.7.6.jar sourcecode_2.12-0.1.4.jar stream-2.5.2.jar swagger-annotations-1.5.18.jar -swagger-annotations-jakarta-2.1.9.jar +swagger-annotations-jakarta-2.2.18.jar swagger-core-1.5.18.jar -swagger-core-jakarta-2.1.9.jar -swagger-integration-jakarta-2.1.9.jar -swagger-jaxrs2-jakarta-2.1.9.jar +swagger-core-jakarta-2.2.18.jar +swagger-integration-jakarta-2.2.18.jar +swagger-jaxrs2-jakarta-2.2.18.jar swagger-models-1.5.18.jar -swagger-models-jakarta-2.1.9.jar +swagger-models-jakarta-2.2.18.jar tinkergraph-gremlin-3.5.1.jar token-provider-2.0.0.jar tracer-core-3.0.8.jar translation-1.0.4.jar util-9.0-9.0.20190305.jar validation-api-1.1.0.Final.jar -zt-zip-1.14.jar zstd-jni-1.5.5-1.jar +zt-zip-1.14.jar diff --git a/pom.xml b/pom.xml index 242263c196..270182e0fa 100644 --- a/pom.xml +++ b/pom.xml @@ -116,6 +116,7 @@ 3.21.7 1.36 3.7.1 + 2.2.18 From 69e6b461add1051831dd6cc0c36a5e249a3b3176 Mon Sep 17 00:00:00 2001 From: SunnyBoy-WYH <48077841+SunnyBoy-WYH@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:34:12 +0800 Subject: [PATCH 2/2] feat(api): support recording slow query log (#2327) * chore(api): code style for cr --------- Co-authored-by: imbajin --- .../hugegraph/api/filter/AccessLogFilter.java | 46 ++++++++++++++++++- .../hugegraph/api/filter/PathFilter.java | 24 ++++++++++ .../hugegraph/config/ServerOptions.java | 9 ++++ .../hugegraph/metrics/SlowQueryLog.java | 43 +++++++++++++++++ .../src/assembly/static/conf/log4j2.xml | 27 +++++++++++ .../static/conf/rest-server.properties | 3 ++ hugegraph-dist/src/main/resources/log4j2.xml | 28 +++++++++++ hugegraph-test/src/main/resources/log4j2.xml | 28 +++++++++++ 8 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 hugegraph-api/src/main/java/org/apache/hugegraph/metrics/SlowQueryLog.java diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AccessLogFilter.java b/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AccessLogFilter.java index ba9c981186..3b529cf0a3 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AccessLogFilter.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AccessLogFilter.java @@ -17,6 +17,7 @@ package org.apache.hugegraph.api.filter; +import static org.apache.hugegraph.api.filter.PathFilter.REQUEST_PARAMS_JSON; import static org.apache.hugegraph.api.filter.PathFilter.REQUEST_TIME; import static org.apache.hugegraph.metrics.MetricsUtil.METRICS_PATH_FAILED_COUNTER; import static org.apache.hugegraph.metrics.MetricsUtil.METRICS_PATH_RESPONSE_TIME_HISTOGRAM; @@ -25,12 +26,20 @@ import java.io.IOException; +import org.apache.hugegraph.config.HugeConfig; +import org.apache.hugegraph.config.ServerOptions; import org.apache.hugegraph.metrics.MetricsUtil; +import org.apache.hugegraph.metrics.SlowQueryLog; +import org.apache.hugegraph.util.JsonUtil; +import org.apache.hugegraph.util.Log; +import org.slf4j.Logger; import jakarta.inject.Singleton; +import jakarta.ws.rs.HttpMethod; import jakarta.ws.rs.container.ContainerRequestContext; import jakarta.ws.rs.container.ContainerResponseContext; import jakarta.ws.rs.container.ContainerResponseFilter; +import jakarta.ws.rs.core.Context; import jakarta.ws.rs.ext.Provider; @@ -39,6 +48,14 @@ public class AccessLogFilter implements ContainerResponseFilter { private static final String DELIMETER = "/"; + private static final String GRAPHS = "graphs"; + private static final String GREMLIN = "gremlin"; + private static final String CYPHER = "cypher"; + + private static final Logger LOG = Log.logger(AccessLogFilter.class); + + @Context + private jakarta.inject.Provider configProvider; /** * Use filter to log request info @@ -62,13 +79,24 @@ public void filter(ContainerRequestContext requestContext, ContainerResponseCont // get responseTime Object requestTime = requestContext.getProperty(REQUEST_TIME); - if(requestTime!=null){ + if(requestTime != null){ long now = System.currentTimeMillis(); - long responseTime = (now - (long)requestTime); + long start = (Long) requestTime; + long responseTime = now - start; MetricsUtil.registerHistogram( join(metricsName, METRICS_PATH_RESPONSE_TIME_HISTOGRAM)) .update(responseTime); + + HugeConfig config = configProvider.get(); + long timeThreshold = config.get(ServerOptions.SLOW_QUERY_LOG_TIME_THRESHOLD); + + // record slow query log + if (timeThreshold > 0 && isSlowQueryLogWhiteAPI(requestContext) && responseTime > timeThreshold) { + SlowQueryLog log = new SlowQueryLog(responseTime, start, (String) requestContext.getProperty(REQUEST_PARAMS_JSON), + method, timeThreshold, path); + LOG.info("Slow query: {}", JsonUtil.toJson(log)); + } } } @@ -79,4 +107,18 @@ private String join(String path1, String path2) { private boolean statusOk(int status){ return status == 200 || status == 201 || status == 202; } + + public static boolean isSlowQueryLogWhiteAPI(ContainerRequestContext context) { + String path = context.getUriInfo().getPath(); + String method = context.getRequest().getMethod(); + + // GraphsAPI/CypherAPI/Job GremlinAPI + if (path.startsWith(GRAPHS)) { + if (method.equals(HttpMethod.GET) || path.endsWith(CYPHER) || path.endsWith(GREMLIN) ){ + return true; + } + } + // Raw GremlinAPI + return path.startsWith(GREMLIN); + } } diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/PathFilter.java b/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/PathFilter.java index 3414d6831b..e1e449ef26 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/PathFilter.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/PathFilter.java @@ -17,12 +17,20 @@ package org.apache.hugegraph.api.filter; +import static org.apache.hugegraph.api.API.CHARSET; + import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; import jakarta.inject.Singleton; +import jakarta.ws.rs.HttpMethod; import jakarta.ws.rs.container.ContainerRequestContext; import jakarta.ws.rs.container.ContainerRequestFilter; import jakarta.ws.rs.container.PreMatching; +import jakarta.ws.rs.core.MultivaluedMap; import jakarta.ws.rs.ext.Provider; @Provider @@ -31,10 +39,26 @@ public class PathFilter implements ContainerRequestFilter { public static final String REQUEST_TIME = "request_time"; + public static final String REQUEST_PARAMS_JSON = "request_params_json"; @Override public void filter(ContainerRequestContext context) throws IOException { context.setProperty(REQUEST_TIME, System.currentTimeMillis()); + + // record the request json + String method = context.getMethod(); + String requestParamsJson = ""; + if (method.equals(HttpMethod.POST)) { + requestParamsJson = IOUtils.toString(context.getEntityStream(), Charsets.toCharset(CHARSET)); + // replace input stream because we have already read it + InputStream in = IOUtils.toInputStream(requestParamsJson, Charsets.toCharset(CHARSET)); + context.setEntityStream(in); + } else if(method.equals(HttpMethod.GET)){ + MultivaluedMap pathParameters = context.getUriInfo().getPathParameters(); + requestParamsJson = pathParameters.toString(); + } + + context.setProperty(REQUEST_PARAMS_JSON, requestParamsJson); } } diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java b/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java index e8b999fb56..a8bbe5a5f2 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java @@ -304,4 +304,13 @@ public static synchronized ServerOptions instance() { null, "jad" ); + + public static final ConfigOption SLOW_QUERY_LOG_TIME_THRESHOLD = + new ConfigOption<>( + "log.slow_query_threshold", + "The threshold time(ms) of logging slow query, " + + "0 means logging slow query is disabled.", + nonNegativeInt(), + 1000L + ); } diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/metrics/SlowQueryLog.java b/hugegraph-api/src/main/java/org/apache/hugegraph/metrics/SlowQueryLog.java new file mode 100644 index 0000000000..cb3f1c7125 --- /dev/null +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/metrics/SlowQueryLog.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * 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 + * + * http://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 org.apache.hugegraph.metrics; + + +public class SlowQueryLog { + + public Long executeTime; + + public Long startTime; + + public String rawQuery; + + public String method; + + public Long threshold; + + public String path; + + public SlowQueryLog(Long executeTime, Long startTime, String rawQuery, String method, Long threshold, + String path) { + this.executeTime = executeTime; + this.startTime = startTime; + this.rawQuery = rawQuery; + this.method = method; + this.threshold = threshold; + this.path = path; + } +} diff --git a/hugegraph-dist/src/assembly/static/conf/log4j2.xml b/hugegraph-dist/src/assembly/static/conf/log4j2.xml index 985ab78b2f..db58e89112 100644 --- a/hugegraph-dist/src/assembly/static/conf/log4j2.xml +++ b/hugegraph-dist/src/assembly/static/conf/log4j2.xml @@ -76,6 +76,30 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -113,5 +137,8 @@ + + + diff --git a/hugegraph-dist/src/assembly/static/conf/rest-server.properties b/hugegraph-dist/src/assembly/static/conf/rest-server.properties index f6444f84fb..23f78c5824 100644 --- a/hugegraph-dist/src/assembly/static/conf/rest-server.properties +++ b/hugegraph-dist/src/assembly/static/conf/rest-server.properties @@ -48,3 +48,6 @@ rpc.server_port=8091 # lightweight load balancing (beta) server.id=server-1 server.role=master + +# slow query log +log.slow_query_threshold=1000 diff --git a/hugegraph-dist/src/main/resources/log4j2.xml b/hugegraph-dist/src/main/resources/log4j2.xml index bdd391e58b..5d80816291 100644 --- a/hugegraph-dist/src/main/resources/log4j2.xml +++ b/hugegraph-dist/src/main/resources/log4j2.xml @@ -76,6 +76,30 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -124,5 +148,9 @@ + + + + diff --git a/hugegraph-test/src/main/resources/log4j2.xml b/hugegraph-test/src/main/resources/log4j2.xml index e830c6248e..284f53487c 100644 --- a/hugegraph-test/src/main/resources/log4j2.xml +++ b/hugegraph-test/src/main/resources/log4j2.xml @@ -76,6 +76,30 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -124,5 +148,9 @@ + + + +