forked from helidon-io/helidon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue helidon-io#6991 - Blocking DB Client: Common metrics module
Signed-off-by: Tomas Kraus <tomas.kraus@oracle.com>
- Loading branch information
1 parent
760ce55
commit d54cc76
Showing
17 changed files
with
889 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2023 Oracle and/or its affiliates. | ||
Licensed 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.helidon.dbclient</groupId> | ||
<artifactId>helidon-dbclient-project</artifactId> | ||
<version>4.0.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>helidon-dbclient-metrics</artifactId> | ||
<name>Helidon DB Client Metrics</name> | ||
<description>Helidon Database Client Metrics</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.helidon.dbclient</groupId> | ||
<artifactId>helidon-dbclient-common</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.metrics</groupId> | ||
<artifactId>helidon-metrics-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.common.features</groupId> | ||
<artifactId>helidon-common-features-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.metrics</groupId> | ||
<artifactId>helidon-metrics</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.helidon.common.features</groupId> | ||
<artifactId>helidon-common-features-processor</artifactId> | ||
<version>${helidon.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
28 changes: 28 additions & 0 deletions
28
dbclient/metrics/src/main/java/io/helidon/dbclient/metrics/DbClientMetricBuilder.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.dbclient.metrics; | ||
|
||
import io.helidon.dbclient.common.CommonService; | ||
|
||
/** | ||
* DB Client metric builder. | ||
* | ||
* @param <B> type of the builder extending this class | ||
* @param <T> Type of the built {@link CommonService} instance | ||
*/ | ||
public abstract class DbClientMetricBuilder<B extends DbClientMetricBuilder<B, T>, T extends CommonService> | ||
extends MetricBuilderBase<B, T> { | ||
} |
69 changes: 69 additions & 0 deletions
69
dbclient/metrics/src/main/java/io/helidon/dbclient/metrics/DbClientMetrics.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.dbclient.metrics; | ||
|
||
import io.helidon.dbclient.common.CommonService; | ||
|
||
/** | ||
* Utility class to obtain various types of metrics to register | ||
* with {@link io.helidon.dbclient.DbClient.Builder#addService(io.helidon.dbclient.DbClientService)}. | ||
* Metrics can be limited to a set of statement types or statement names, and also configured to | ||
* meter success, failure or both. | ||
* | ||
* @see DbClientMetricBuilder#statementTypes(io.helidon.dbclient.DbStatementType...) | ||
* @see DbClientMetricBuilder#statementNames(String...) | ||
* @see DbClientMetricBuilder#statementPredicate(java.util.function.Predicate) | ||
* @see DbClientMetricBuilder#success(boolean) | ||
* @see DbClientMetricBuilder#errors(boolean) | ||
*/ | ||
public class DbClientMetrics { | ||
private DbClientMetrics() { | ||
} | ||
|
||
/** | ||
* Create a counter builder, to be registered | ||
* with {@link io.helidon.dbclient.DbClient.Builder#addService(java.util.function.Supplier)}. | ||
* | ||
* @return a new counter builder | ||
* @see org.eclipse.microprofile.metrics.Counter | ||
*/ | ||
public static DbClientMetricBuilder<? extends DbClientMetricBuilder<?, ?>, ? extends CommonService> counter() { | ||
return MetricCounter.builder(); | ||
} | ||
|
||
/** | ||
* Create a meter builder, to be registered | ||
* with {@link io.helidon.dbclient.DbClient.Builder#addService(java.util.function.Supplier)}. | ||
* | ||
* @return a new meter builder | ||
* @see org.eclipse.microprofile.metrics.Meter | ||
*/ | ||
public static DbClientMetricBuilder<? extends DbClientMetricBuilder<?, ?>, ? extends CommonService> meter() { | ||
return MetricMeter.builder(); | ||
} | ||
|
||
/** | ||
* Create a timer builder, to be registered | ||
* with {@link io.helidon.dbclient.DbClient.Builder#addService(java.util.function.Supplier)}. | ||
* | ||
* @return a new timer builder | ||
* @see org.eclipse.microprofile.metrics.Timer | ||
*/ | ||
public static DbClientMetricBuilder<? extends DbClientMetricBuilder<?, ?>, ? extends CommonService> timer() { | ||
return MetricTimer.builder(); | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
dbclient/metrics/src/main/java/io/helidon/dbclient/metrics/DbClientMetricsProvider.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.dbclient.metrics; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import io.helidon.config.Config; | ||
import io.helidon.dbclient.DbClientException; | ||
import io.helidon.dbclient.DbClientService; | ||
import io.helidon.dbclient.spi.DbClientServiceProvider; | ||
|
||
/** | ||
* Java service loader service for DB metrics. | ||
*/ | ||
public class DbClientMetricsProvider implements DbClientServiceProvider { | ||
private static final System.Logger LOGGER = System.getLogger(DbClientMetricsProvider.class.getName()); | ||
|
||
@Override | ||
public String configKey() { | ||
return "metrics"; | ||
} | ||
|
||
@Override | ||
public Collection<DbClientService> create(Config config) { | ||
List<Config> metricConfigs = config.asNodeList().orElseGet(List::of); | ||
List<DbClientService> result = new LinkedList<>(); | ||
|
||
for (Config metricConfig : metricConfigs) { | ||
result.add(fromConfig(metricConfig)); | ||
} | ||
|
||
if (result.isEmpty()) { | ||
LOGGER.log(System.Logger.Level.INFO, "DB Client metrics are enabled, yet none are configured in config."); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private DbClientService fromConfig(Config config) { | ||
String type = config.get("type").asString().orElse("COUNTER"); | ||
switch (type) { | ||
case "COUNTER": | ||
return DbClientMetrics.counter().config(config).build(); | ||
case "METER": | ||
return DbClientMetrics.meter().config(config).build(); | ||
case "TIMER": | ||
return DbClientMetrics.timer().config(config).build(); | ||
default: | ||
throw new DbClientException("Metrics type " + type + " is not supported through service loader"); | ||
} | ||
} | ||
} |
Oops, something went wrong.