Skip to content

Commit

Permalink
Moved metrics endpoint from metrics.thrift to process.thrift file
Browse files Browse the repository at this point in the history
  • Loading branch information
dlmarion committed Jan 31, 2025
1 parent eeb3d42 commit bef486d
Show file tree
Hide file tree
Showing 25 changed files with 1,313 additions and 1,536 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public abstract class ThriftClientTypes<C extends TServiceClient> {

public static final ManagerThriftClient MANAGER = new ManagerThriftClient("mgr");

public static final MetricsThriftClient METRICS = new MetricsThriftClient("metrics");

public static final TabletServerThriftClient TABLET_SERVER =
new TabletServerThriftClient("tserver");

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scripts/generate-thrift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
[[ -z $REQUIRED_THRIFT_VERSION ]] && REQUIRED_THRIFT_VERSION='0.17.0'
[[ -z $INCLUDED_MODULES ]] && INCLUDED_MODULES=()
[[ -z $BASE_OUTPUT_PACKAGE ]] && BASE_OUTPUT_PACKAGE='org.apache.accumulo.core'
[[ -z $PACKAGES_TO_GENERATE ]] && PACKAGES_TO_GENERATE=(process gc manager tabletserver securityImpl clientImpl dataImpl compaction tabletingest tablet tabletscan metrics)
[[ -z $PACKAGES_TO_GENERATE ]] && PACKAGES_TO_GENERATE=(process gc manager tabletserver securityImpl clientImpl dataImpl compaction tabletingest tablet tabletscan)
[[ -z $BUILD_DIR ]] && BUILD_DIR='target'
[[ -z $LANGUAGES_TO_GENERATE ]] && LANGUAGES_TO_GENERATE=(java)
[[ -z $FINAL_DIR ]] && FINAL_DIR='src/main'
Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

50 changes: 0 additions & 50 deletions core/src/main/thrift/metrics.thrift

This file was deleted.

24 changes: 24 additions & 0 deletions core/src/main/thrift/process.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,34 @@
namespace java org.apache.accumulo.core.process.thrift
namespace cpp org.apache.accumulo.core.process.thrift

include "client.thrift"
include "security.thrift"

enum MetricSource {
COMPACTOR
GARBAGE_COLLECTOR
MANAGER
SCAN_SERVER
TABLET_SERVER
}

struct MetricResponse {
1:MetricSource serverType
2:string server
3:string resourceGroup
4:i64 timestamp
5:list<binary> metrics
}

service ServerProcessService {

MetricResponse getMetrics(
1:client.TInfo tinfo
2:security.TCredentials credentials
) throws (
1:client.ThriftSecurityException sec
)

oneway void gracefulShutdown(
1:security.TCredentials credentials
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@
import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.classloader.ClassLoaderUtil;
import org.apache.accumulo.core.cli.ConfigOpts;
import org.apache.accumulo.core.client.admin.servers.ServerId;
import org.apache.accumulo.core.clientImpl.thrift.SecurityErrorCode;
import org.apache.accumulo.core.clientImpl.thrift.TInfo;
import org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.conf.SiteConfiguration;
import org.apache.accumulo.core.conf.cluster.ClusterConfigParser;
import org.apache.accumulo.core.lock.ServiceLock;
import org.apache.accumulo.core.metrics.MetricsProducer;
import org.apache.accumulo.core.metrics.thrift.MetricSource;
import org.apache.accumulo.core.process.thrift.MetricResponse;
import org.apache.accumulo.core.process.thrift.MetricSource;
import org.apache.accumulo.core.process.thrift.ServerProcessService;
import org.apache.accumulo.core.securityImpl.thrift.TCredentials;
import org.apache.accumulo.core.trace.TraceUtil;
Expand All @@ -46,22 +50,27 @@
import org.apache.accumulo.core.util.threads.ThreadPools;
import org.apache.accumulo.core.util.threads.Threads;
import org.apache.accumulo.server.mem.LowMemoryDetector;
import org.apache.accumulo.server.metrics.MetricServiceHandler;
import org.apache.accumulo.server.metrics.MetricResponseWrapper;
import org.apache.accumulo.server.metrics.ProcessMetrics;
import org.apache.accumulo.server.security.SecurityUtil;
import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;
import com.google.common.net.HostAndPort;
import com.google.flatbuffers.FlatBufferBuilder;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;

public abstract class AbstractServer
implements AutoCloseable, MetricsProducer, Runnable, ServerProcessService.Iface {

private final MetricSource metricSource;
private final ServerContext context;
protected final String applicationName;
private final String hostname;
private String hostname;
private final String resourceGroup;
private final Logger log;
private final ProcessMetrics processMetrics;
Expand All @@ -72,10 +81,10 @@ public abstract class AbstractServer
private final AtomicBoolean shutdownRequested = new AtomicBoolean(false);
private final AtomicBoolean shutdownComplete = new AtomicBoolean(false);

protected AbstractServer(String appName, ConfigOpts opts,
protected AbstractServer(ServerId.Type serverType, ConfigOpts opts,
Function<SiteConfiguration,ServerContext> serverContextFactory, String[] args) {
this.applicationName = appName;
opts.parseArgs(appName, args);
this.applicationName = serverType.name();
opts.parseArgs(applicationName, args);
var siteConfig = opts.getSiteConfiguration();
this.hostname = siteConfig.get(Property.GENERAL_PROCESS_BIND_ADDRESS);
this.resourceGroup = getResourceGroupPropertyValue(siteConfig);
Expand All @@ -85,7 +94,7 @@ protected AbstractServer(String appName, ConfigOpts opts,
log = LoggerFactory.getLogger(getClass());
log.info("Version " + Constants.VERSION);
log.info("Instance " + context.getInstanceID());
context.init(appName);
context.init(applicationName);
ClassLoaderUtil.initContextFactory(context.getConfiguration());
TraceUtil.initializeTracer(context.getConfiguration());
if (context.getSaslParams() != null) {
Expand All @@ -100,6 +109,28 @@ protected AbstractServer(String appName, ConfigOpts opts,
processMetrics = new ProcessMetrics(context);
idleReportingPeriodMillis =
context.getConfiguration().getTimeInMillis(Property.GENERAL_IDLE_PROCESS_INTERVAL);
switch (serverType) {
case COMPACTOR:
metricSource = MetricSource.COMPACTOR;
break;
case GARBAGE_COLLECTOR:
metricSource = MetricSource.GARBAGE_COLLECTOR;
break;
case MANAGER:
metricSource = MetricSource.MANAGER;
break;
case MONITOR:
metricSource = null;
break;
case SCAN_SERVER:
metricSource = MetricSource.SCAN_SERVER;
break;
case TABLET_SERVER:
metricSource = MetricSource.TABLET_SERVER;
break;
default:
throw new IllegalArgumentException("Unhandled server type: " + serverType);
}
}

/**
Expand Down Expand Up @@ -233,6 +264,10 @@ public String getHostname() {
return hostname;
}

public void setHostname(HostAndPort address) {
hostname = address.toString();
}

public ServerContext getContext() {
return context;
}
Expand All @@ -245,8 +280,45 @@ public String getApplicationName() {
return applicationName;
}

protected MetricServiceHandler createMetricServiceHandler(MetricSource serverType) {
return new MetricServiceHandler(serverType, getResourceGroup(), context);
@Override
public MetricResponse getMetrics(TInfo tinfo, TCredentials credentials) throws TException {

if (!context.getSecurityOperation().authenticateUser(credentials, credentials)) {
throw new ThriftSecurityException(credentials.getPrincipal(),
SecurityErrorCode.PERMISSION_DENIED);
}

final FlatBufferBuilder builder = new FlatBufferBuilder(1024);
final MetricResponseWrapper response = new MetricResponseWrapper(builder);

if (getHostname().startsWith(Property.GENERAL_PROCESS_BIND_ADDRESS.getDefaultValue())) {
log.error("Host is not set, this should have been done after starting the Thrift service.");
return response;
}

if (metricSource == null) {
// Metrics not reported for Monitor type
return response;
}

response.setServerType(metricSource);
response.setServer(getHostname());
response.setResourceGroup(getResourceGroup());
response.setTimestamp(System.currentTimeMillis());

if (context.getMetricsInfo().isMetricsEnabled()) {
Metrics.globalRegistry.getMeters().forEach(m -> {
if (m.getId().getName().startsWith("accumulo.")) {
m.match(response::writeMeter, response::writeMeter, response::writeTimer,
response::writeDistributionSummary, response::writeLongTaskTimer,
response::writeMeter, response::writeMeter, response::writeFunctionTimer,
response::writeMeter);
}
});
}

builder.clear();
return response;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.accumulo.core.metrics.MetricsInfo;
import org.apache.accumulo.core.metrics.flatbuffers.FMetric;
import org.apache.accumulo.core.metrics.flatbuffers.FTag;
import org.apache.accumulo.core.metrics.thrift.MetricResponse;
import org.apache.accumulo.core.process.thrift.MetricResponse;
import org.apache.accumulo.core.util.ByteBufferUtil;

import com.google.flatbuffers.FlatBufferBuilder;
Expand Down
Loading

0 comments on commit bef486d

Please sign in to comment.