Skip to content

Commit

Permalink
Migrate SysMetricsTableInfo to SystemTable
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger authored and mergify[bot] committed Mar 16, 2020
1 parent 3e40d02 commit 8465e92
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 92 deletions.
124 changes: 35 additions & 89 deletions sql/src/main/java/io/crate/metadata/sys/SysMetricsTableInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,104 +22,50 @@

package io.crate.metadata.sys;

import io.crate.action.sql.SessionContext;
import io.crate.analyze.WhereClause;
import io.crate.metadata.ColumnIdent;
import io.crate.metadata.RelationName;
import io.crate.metadata.Routing;
import io.crate.metadata.RoutingProvider;
import io.crate.metadata.RowGranularity;
import io.crate.metadata.expressions.RowCollectExpressionFactory;
import io.crate.metadata.table.ColumnRegistrar;
import io.crate.metadata.table.StaticTableInfo;
import io.crate.types.ObjectType;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.node.DiscoveryNode;

import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

import static io.crate.execution.engine.collect.NestableCollectExpression.forFunction;
import static io.crate.types.DataTypes.DOUBLE;
import static io.crate.types.DataTypes.LONG;
import static io.crate.types.DataTypes.STRING;
import static io.crate.types.DataTypes.STRING_ARRAY;

public class SysMetricsTableInfo extends StaticTableInfo<MetricsView> {

public static final RelationName NAME = new RelationName(SysSchemaInfo.NAME, "jobs_metrics");

private static ColumnRegistrar<MetricsView> columnRegistrar(Supplier<DiscoveryNode> localNode) {
return new ColumnRegistrar<MetricsView>(NAME, RowGranularity.DOC)
.register("total_count", LONG, () -> forFunction(MetricsView::totalCount))
.register("sum_of_durations", LONG, () -> forFunction(MetricsView::sumOfDurations))
.register("failed_count", LONG, () -> forFunction(MetricsView::failedCount))
.register("mean", DOUBLE, () -> forFunction(MetricsView::mean))
.register("stdev", DOUBLE, () -> forFunction(MetricsView::stdDeviation))
.register("max", LONG, () -> forFunction(MetricsView::maxValue))
.register("min", LONG, () -> forFunction(MetricsView::minValue))
.register(
"percentiles",
ObjectType.builder()
.setInnerType("25", LONG)
.setInnerType("50", LONG)
.setInnerType("75", LONG)
.setInnerType("90", LONG)
.setInnerType("95", LONG)
.setInnerType("99", LONG)
.build(),
() -> forFunction(m -> Map.of(
"25", m.getValueAtPercentile(25.0),
"50", m.getValueAtPercentile(50.0),
"75", m.getValueAtPercentile(75.0),
"90", m.getValueAtPercentile(90.0),
"95", m.getValueAtPercentile(95.0),
"99", m.getValueAtPercentile(99.0)
)
))
.register("percentiles", "25", LONG, () -> forFunction(m -> m.getValueAtPercentile(25.0)))
.register("percentiles", "50", LONG, () -> forFunction(m -> m.getValueAtPercentile(50.0)))
.register("percentiles", "75", LONG, () -> forFunction(m -> m.getValueAtPercentile(75.0)))
.register("percentiles", "90", LONG, () -> forFunction(m -> m.getValueAtPercentile(90.0)))
.register("percentiles", "95", LONG, () -> forFunction(m -> m.getValueAtPercentile(95.0)))
.register("percentiles", "99", LONG, () -> forFunction(m -> m.getValueAtPercentile(99.0)))

.register("node", ObjectType.builder()
.setInnerType("id", STRING)
.setInnerType("name", STRING)
.build(), () -> forFunction(ignored -> Map.of(
"id", localNode.get().getId(),
"name", localNode.get().getName()
)
import java.util.List;
import java.util.function.Supplier;

))
.register("node", "id", STRING, () -> forFunction(ignored -> localNode.get().getId()))
.register("node", "name", STRING, () -> forFunction(ignored -> localNode.get().getName()))
.register(
"classification",
ColumnRegistrar.object(
ColumnRegistrar.entry("type", STRING, x -> x.classification().type().name()),
ColumnRegistrar.entry("labels", STRING_ARRAY, x -> List.copyOf(x.classification().labels())
)
));
}
import org.elasticsearch.cluster.node.DiscoveryNode;

SysMetricsTableInfo(Supplier<DiscoveryNode> localNode) {
super(NAME, columnRegistrar(localNode));
}
import io.crate.metadata.RelationName;
import io.crate.metadata.Routing;
import io.crate.metadata.SystemTable;

static Map<ColumnIdent, RowCollectExpressionFactory<MetricsView>> expressions(Supplier<DiscoveryNode> localNode) {
return columnRegistrar(localNode).expressions();
}
public class SysMetricsTableInfo {

@Override
public Routing getRouting(ClusterState state, RoutingProvider routingProvider, WhereClause whereClause, RoutingProvider.ShardSelection shardSelection, SessionContext sessionContext) {
return Routing.forTableOnAllNodes(NAME, state.getNodes());
}
public static final RelationName NAME = new RelationName(SysSchemaInfo.NAME, "jobs_metrics");

@Override
public RowGranularity rowGranularity() {
return RowGranularity.DOC;
public static SystemTable<MetricsView> create(Supplier<DiscoveryNode> localNode) {
return SystemTable.<MetricsView>builder()
.add("total_count", LONG, MetricsView::totalCount)
.add("sum_of_durations", LONG, MetricsView::sumOfDurations)
.add("failed_count", LONG, MetricsView::failedCount)
.add("mean", DOUBLE, MetricsView::mean)
.add("stdev", DOUBLE, MetricsView::stdDeviation)
.add("max", LONG, MetricsView::maxValue)
.add("min", LONG, MetricsView::minValue)
.startObject("percentiles")
.add("25", LONG, x -> x.getValueAtPercentile(25.0))
.add("50", LONG, x -> x.getValueAtPercentile(50.0))
.add("75", LONG, x -> x.getValueAtPercentile(75.0))
.add("90", LONG, x -> x.getValueAtPercentile(90.0))
.add("95", LONG, x -> x.getValueAtPercentile(95.0))
.add("99", LONG, x -> x.getValueAtPercentile(99.0))
.endObject()
.startObject("node")
.add("id", STRING, ignored -> localNode.get().getId())
.add("name", STRING, ignored -> localNode.get().getName())
.endObject()
.startObject("classification")
.add("type", STRING, x -> x.classification().type().name())
.add("labels", STRING_ARRAY, x -> List.copyOf(x.classification().labels()))
.endObject()
.withRouting(nodes -> Routing.forTableOnAllNodes(NAME, nodes))
.build(NAME);
}
}
3 changes: 1 addition & 2 deletions sql/src/main/java/io/crate/metadata/sys/SysSchemaInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ public SysSchemaInfo(ClusterService clusterService, CrateSettings crateSettings,
tableInfos.put(SysSummitsTableInfo.IDENT.name(), new SysSummitsTableInfo());
tableInfos.put(SysAllocationsTableInfo.IDENT.name(), new SysAllocationsTableInfo());
tableInfos.put(SysHealth.IDENT.name(), SysHealth.create());
tableInfos.put(SysMetricsTableInfo.NAME.name(), new SysMetricsTableInfo(localNode));
tableInfos.put(SysMetricsTableInfo.NAME.name(), SysMetricsTableInfo.create(localNode));
tableInfos.put(SysSegmentsTableInfo.IDENT.name(), new SysSegmentsTableInfo(clusterService::localNode));
tableInfos.put(SysMetricsTableInfo.NAME.name(), new SysMetricsTableInfo(clusterService::localNode));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public SysTableDefinitions(JobsLogs jobsLogs,
);
tableDefinitions.put(SysMetricsTableInfo.NAME, new StaticTableDefinition<>(
() -> completedFuture(jobsLogs.metrics()),
SysMetricsTableInfo.expressions(localNode),
SysMetricsTableInfo.create(localNode).expressions(),
false));
tableDefinitions.put(SysSegmentsTableInfo.IDENT, new StaticTableDefinition<>(
() -> completedFuture(shardSegmentInfos),
Expand Down

0 comments on commit 8465e92

Please sign in to comment.