Skip to content
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

Detailed tasks information as metrics #371

Merged
merged 10 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions management-api-agent-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import org.apache.cassandra.utils.Pair;

public class JobExecutor {
ExecutorService executorService = Executors.newFixedThreadPool(1);
Cache<String, Job> jobCache = CacheBuilder.newBuilder().maximumSize(1000).build();
Cache<String, Job> jobCache = CacheBuilder.newBuilder().recordStats().maximumSize(1000).build();

public Pair<String, CompletableFuture<Void>> submit(String jobType, Runnable runnable) {
// Where do I create the job details? Here? Add it to the Cache first?
Expand Down Expand Up @@ -45,4 +46,12 @@ public Pair<String, CompletableFuture<Void>> submit(String jobType, Runnable run
public Job getJobWithId(String jobId) {
return jobCache.getIfPresent(jobId);
}

public int runningTasks() {
return ((ThreadPoolExecutor) executorService).getActiveCount();
}

public int queuedTasks() {
return ((ThreadPoolExecutor) executorService).getQueue().size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public CassandraMetricNameParser(
}
}

public static CassandraMetricNameParser getDefaultParser(Configuration config) {
return new CassandraMetricNameParser(
CassandraMetricsTools.DEFAULT_LABEL_NAMES,
CassandraMetricsTools.DEFAULT_LABEL_VALUES,
config);
}

private void parseEnvVariablesAsLabels(Map<String, String> envSettings) {
for (Map.Entry<String, String> entry : envSettings.entrySet()) {
String envValue = System.getenv(entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ public class CassandraMetricRegistryListener implements MetricRegistryListener {
public CassandraMetricRegistryListener(
ConcurrentHashMap<String, RefreshableMetricFamilySamples> familyCache, Configuration config)
throws NoSuchMethodException {
parser =
new CassandraMetricNameParser(
CassandraMetricsTools.DEFAULT_LABEL_NAMES,
CassandraMetricsTools.DEFAULT_LABEL_VALUES,
config);
parser = CassandraMetricNameParser.getDefaultParser(config);
cache = new ConcurrentHashMap<>();

this.familyCache = familyCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class Configuration {
@JsonProperty("labels")
private LabelConfiguration labels;

@JsonProperty("extended_metrics_disabled")
private boolean extendedDisabled;

public Configuration() {
relabels = new ArrayList<>();
}
Expand All @@ -44,4 +47,12 @@ public void setRelabels(List<RelabelSpec> relabels) {
public void setLabels(LabelConfiguration labels) {
this.labels = labels;
}

public boolean isExtendedDisabled() {
return extendedDisabled;
}

public void setExtendedDisabled(boolean extendedDisabled) {
this.extendedDisabled = extendedDisabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.k8ssandra.metrics.config.Configuration;
import io.k8ssandra.metrics.http.NettyMetricsHttpServer;
import io.k8ssandra.metrics.prometheus.CassandraDropwizardExports;
import io.k8ssandra.metrics.prometheus.CassandraTasksExports;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.prometheus.client.hotspot.DefaultExports;
Expand Down Expand Up @@ -72,6 +73,11 @@ public static void intercept(@SuperCall Callable<Void> zuper) throws Exception {
// Add JVM metrics
DefaultExports.initialize();

// Add task metrics
if (!config.isExtendedDisabled()) {
new CassandraTasksExports(CassandraMetricsRegistry.Metrics, config).register();
}

// Create /metrics handler. Note, this doesn't support larger than nThreads=1
final EventLoopGroup httpGroup = new EpollEventLoopGroup(1);

Expand All @@ -81,12 +87,7 @@ public static void intercept(@SuperCall Callable<Void> zuper) throws Exception {

logger.info("Metrics collector started");

Runtime.getRuntime()
.addShutdownHook(
new Thread(
() -> {
httpGroup.shutdownGracefully();
}));
Runtime.getRuntime().addShutdownHook(new Thread(httpGroup::shutdownGracefully));
} catch (Throwable t) {
logger.error("Unable to start metrics endpoint", t);
}
Expand Down
Loading