Skip to content

Commit

Permalink
Removed unnecessary dependency and cleaned up CouchbaseRecorder metri…
Browse files Browse the repository at this point in the history
…cs configuration. Removed try/catch in connection string helper for the Dev UI.
  • Loading branch information
emilienbev committed Jan 16, 2025
1 parent a89791f commit 45ce195
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.couchbase.quarkus.extension.deployment;

import com.couchbase.client.core.error.InvalidArgumentException;
import com.couchbase.client.core.util.ConnectionString;
import com.couchbase.quarkus.extension.runtime.CouchbaseConfig;

Expand Down Expand Up @@ -41,14 +40,10 @@ public CardPageBuildItem pages(CouchbaseConfig config) {
* Extracts the first hostname from the connection string to redirect to the Cluster UI Dashboard.
*
* @param connectionString The connection string specified in application.properties.
* @return The first hostname, or "localhost" by default.
* @return The first hostname.
*/
private String extractHostnameFromConnectionString(String connectionString) {
try {
ConnectionString connStr = ConnectionString.create(connectionString);
return connStr.hosts().get(0).host();
} catch (InvalidArgumentException e) {
return "localhost";
}
ConnectionString connStr = ConnectionString.create(connectionString);
return connStr.hosts().get(0).host();
}
}
5 changes: 0 additions & 5 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@
<artifactId>metrics-micrometer</artifactId>
<version>0.7.6</version>
</dependency>
<dependency>
<groupId>org.hdrhistogram</groupId>
<artifactId>HdrHistogram</artifactId>
<version>2.1.12</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
* Copyright (c) 2024 Couchbase, Inc.
*
* 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 com.couchbase.quarkus.extension.runtime;

import java.time.Duration;
Expand All @@ -33,17 +18,25 @@
public class CouchbaseRecorder {

public Supplier<Cluster> getCluster(CouchbaseConfig config, boolean metricsEnabled) {
var clusterOptions = ClusterOptions.clusterOptions(config.username(), config.password());
var clusterEnvironmentBuilder = ClusterEnvironment.builder();
final ClusterOptions clusterOptions = ClusterOptions.clusterOptions(config.username(), config.password());

if (metricsEnabled) {
configureMetrics(clusterEnvironmentBuilder, config.emitInterval());
clusterOptions.environment(env -> configureMetrics(env, config.emitInterval()));
}
clusterOptions.environment(clusterEnvironmentBuilder.build());

return () -> Cluster.connect(config.connectionString(), clusterOptions);
}

public void configureMetrics(ClusterEnvironment.Builder clusterEnvironmentBuilder, int emitInterval) {
//Micrometer won't create a histogram by default. Configuring it here.
private void configureMetrics(ClusterEnvironment.Builder env, int emitInterval) {
configureMicrometer();

env.meter(MicrometerMeter.wrap(Metrics.globalRegistry))
.loggingMeterConfig(meterConfig -> meterConfig
.enabled(true)
.emitInterval(Duration.ofSeconds(emitInterval)));
}

private void configureMicrometer() {
Metrics.globalRegistry.config().meterFilter(new MeterFilter() {
@Override
public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
Expand All @@ -56,11 +49,5 @@ public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticC
return config;
}
});

clusterEnvironmentBuilder.meter(MicrometerMeter.wrap(Metrics.globalRegistry))
.loggingMeterConfig(meterConfig -> meterConfig
.enabled(true)
.emitInterval(Duration.ofSeconds(emitInterval)));

}
}
}

0 comments on commit 45ce195

Please sign in to comment.