Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.gluten.table.runtime.metrics;

import io.github.zhztheplayer.velox4j.query.SerialTask;

import org.apache.flink.metrics.Counter;
import org.apache.flink.metrics.groups.OperatorMetricGroup;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class SourceTaskMetrics {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does flink have some class that could be used for source metrics?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, such as KafkaSourceReaderMetrics. But it is a single class that can not be reused here, so we create this class which is smilar to flink's.


private final String keyOperatorType = "operatorType";
private final String sourceOperatorName = "TableScan";
private final String keyInputRows = "rawInputRows";
private final String keyInputBytes = "rawInputBytes";
private final long metricUpdateInterval = 2000;
private Counter sourceNumRecordsOut;
private Counter sourceNumBytesOut;
private long lastUpdateTime = System.currentTimeMillis();

public SourceTaskMetrics(OperatorMetricGroup metricGroup) {
sourceNumRecordsOut = metricGroup.getIOMetricGroup().getNumRecordsOutCounter();
sourceNumBytesOut = metricGroup.getIOMetricGroup().getNumBytesOutCounter();
}

public boolean updateMetrics(SerialTask task, String planId) {
long currentTime = System.currentTimeMillis();
if (currentTime - lastUpdateTime < metricUpdateInterval) {
return false;
}
try {
ObjectNode planStats = task.collectStats().planStats(planId);
JsonNode jsonNode = planStats.get(keyOperatorType);
if (jsonNode.asText().equals(sourceOperatorName)) {
long numRecordsOut = planStats.get(keyInputRows).asInt();
long numBytesOut = planStats.get(keyInputBytes).asInt();
sourceNumRecordsOut.inc(numRecordsOut - sourceNumRecordsOut.getCount());
sourceNumBytesOut.inc(numBytesOut - sourceNumBytesOut.getCount());
}
} catch (Exception e) {
return false;
}
lastUpdateTime = currentTime;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.gluten.table.runtime.operators;

import org.apache.gluten.table.runtime.config.VeloxQueryConfig;
import org.apache.gluten.table.runtime.metrics.SourceTaskMetrics;

import io.github.zhztheplayer.velox4j.Velox4j;
import io.github.zhztheplayer.velox4j.config.ConnectorConfig;
Expand Down Expand Up @@ -66,6 +67,7 @@ public class GlutenVectorSourceFunction extends RichParallelSourceFunction<State
private BufferAllocator allocator;
private MemoryManager memoryManager;
private SerialTask task;
private SourceTaskMetrics taskMetrics;

public GlutenVectorSourceFunction(
StatefulPlanNode planNode,
Expand Down Expand Up @@ -108,6 +110,7 @@ public void open(Configuration parameters) throws Exception {
task.addSplit(id, split);
task.noMoreSplits(id);
}
taskMetrics = new SourceTaskMetrics(getRuntimeContext().getMetricGroup());
}

@Override
Expand All @@ -128,6 +131,7 @@ public void run(SourceContext<StatefulElement> sourceContext) throws Exception {
LOG.info("Velox task finished");
break;
}
taskMetrics.updateMetrics(task, id);
}

task.close();
Expand Down