未验证 提交 17e3fff8 编写于 作者: wu-sheng's avatar wu-sheng 提交者: GitHub

Refactor the storage to support `getSubsetOfMultipleLinearIntValues` (#4289)

上级 0e105a49
......@@ -97,6 +97,19 @@ public class MetricQueryService implements Service {
}
public List<IntValues> getMultipleLinearIntValues(final String indName, final String id, final int numOfLinear,
final Downsampling downsampling,
final long startTB,
final long endTB) throws IOException {
List<Integer> linearIndex = new ArrayList<>(numOfLinear);
for (int i = 0; i < numOfLinear; i++) {
linearIndex.add(i);
}
return getSubsetOfMultipleLinearIntValues(indName, id, linearIndex, downsampling, startTB, endTB);
}
public List<IntValues> getSubsetOfMultipleLinearIntValues(final String indName, final String id,
final List<Integer> linearIndex,
final Downsampling downsampling,
final long startTB,
final long endTB) throws IOException {
......@@ -108,9 +121,9 @@ public class MetricQueryService implements Service {
durationPoints.forEach(durationPoint -> ids.add(durationPoint.getPoint() + Const.ID_SPLIT + id));
}
IntValues[] multipleLinearIntValues = getMetricQueryDAO().getMultipleLinearIntValues(indName, downsampling, ids, numOfLinear, ValueColumnIds.INSTANCE.getValueCName(indName));
IntValues[] multipleLinearIntValues = getMetricQueryDAO().getMultipleLinearIntValues(indName, downsampling, ids, linearIndex, ValueColumnIds.INSTANCE.getValueCName(indName));
List<IntValues> response = new ArrayList<>(numOfLinear);
List<IntValues> response = new ArrayList<>(linearIndex.size());
Collections.addAll(response, multipleLinearIntValues);
return response;
}
......
......@@ -21,8 +21,10 @@ package org.apache.skywalking.oap.server.core.storage.query;
import java.io.IOException;
import java.util.List;
import org.apache.skywalking.oap.server.core.analysis.Downsampling;
import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.query.sql.*;
import org.apache.skywalking.oap.server.core.query.entity.IntValues;
import org.apache.skywalking.oap.server.core.query.entity.Thermodynamic;
import org.apache.skywalking.oap.server.core.query.sql.Function;
import org.apache.skywalking.oap.server.core.query.sql.Where;
import org.apache.skywalking.oap.server.core.storage.DAO;
/**
......@@ -30,11 +32,15 @@ import org.apache.skywalking.oap.server.core.storage.DAO;
*/
public interface IMetricsQueryDAO extends DAO {
IntValues getValues(String indName, Downsampling downsampling, long startTB, long endTB, Where where, String valueCName, Function function) throws IOException;
IntValues getValues(String indName, Downsampling downsampling, long startTB, long endTB, Where where,
String valueCName, Function function) throws IOException;
IntValues getLinearIntValues(String indName, Downsampling downsampling, List<String> ids, String valueCName) throws IOException;
IntValues getLinearIntValues(String indName, Downsampling downsampling, List<String> ids,
String valueCName) throws IOException;
IntValues[] getMultipleLinearIntValues(String indName, Downsampling downsampling, List<String> ids, int numOfLinear, String valueCName) throws IOException;
IntValues[] getMultipleLinearIntValues(String indName, Downsampling downsampling, List<String> ids,
List<Integer> linearIndex, String valueCName) throws IOException;
Thermodynamic getThermodynamic(String indName, Downsampling downsampling, List<String> ids, String valueCName) throws IOException;
Thermodynamic getThermodynamic(String indName, Downsampling downsampling, List<String> ids,
String valueCName) throws IOException;
}
......@@ -22,10 +22,15 @@ import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import org.apache.skywalking.oap.query.graphql.type.*;
import org.apache.skywalking.oap.query.graphql.type.BatchMetricConditions;
import org.apache.skywalking.oap.query.graphql.type.Duration;
import org.apache.skywalking.oap.query.graphql.type.MetricCondition;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.query.*;
import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.query.DurationUtils;
import org.apache.skywalking.oap.server.core.query.MetricQueryService;
import org.apache.skywalking.oap.server.core.query.StepToDownsampling;
import org.apache.skywalking.oap.server.core.query.entity.IntValues;
import org.apache.skywalking.oap.server.core.query.entity.Thermodynamic;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
/**
......@@ -54,21 +59,32 @@ public class MetricQuery implements GraphQLQueryResolver {
return getMetricQueryService().getValues(metrics.getName(), metrics.getIds(), StepToDownsampling.transform(duration.getStep()), startTimeBucket, endTimeBucket);
}
public IntValues getLinearIntValues(final MetricCondition metrics, final Duration duration) throws IOException, ParseException {
public IntValues getLinearIntValues(final MetricCondition metrics,
final Duration duration) throws IOException, ParseException {
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
return getMetricQueryService().getLinearIntValues(metrics.getName(), metrics.getId(), StepToDownsampling.transform(duration.getStep()), startTimeBucket, endTimeBucket);
}
public List<IntValues> getMultipleLinearIntValues(final MetricCondition metrics, final int numOfLinear, final Duration duration) throws IOException, ParseException {
public List<IntValues> getMultipleLinearIntValues(final MetricCondition metrics, final int numOfLinear,
final Duration duration) throws IOException, ParseException {
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
return getMetricQueryService().getMultipleLinearIntValues(metrics.getName(), metrics.getId(), numOfLinear, StepToDownsampling.transform(duration.getStep()), startTimeBucket, endTimeBucket);
}
public Thermodynamic getThermodynamic(final MetricCondition metrics, final Duration duration) throws IOException, ParseException {
public List<IntValues> getSubsetOfMultipleLinearIntValues(final MetricCondition metrics,
final List<Integer> linearIndex, final Duration duration) throws IOException, ParseException {
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
return getMetricQueryService().getSubsetOfMultipleLinearIntValues(metrics.getName(), metrics.getId(), linearIndex, StepToDownsampling.transform(duration.getStep()), startTimeBucket, endTimeBucket);
}
public Thermodynamic getThermodynamic(final MetricCondition metrics,
final Duration duration) throws IOException, ParseException {
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
......
Subproject commit 249addeaaf524c0dd990444e5f4bcaf355ce8e01
Subproject commit 03ed7858ea05ade81b9ceaa3abe468b422ce8110
......@@ -135,13 +135,13 @@ public class MetricsQueryEsDAO extends EsDAO implements IMetricsQueryDAO {
}
@Override public IntValues[] getMultipleLinearIntValues(String indName, Downsampling downsampling,
List<String> ids, int numOfLinear, String valueCName) throws IOException {
List<String> ids, List<Integer> linearIndex, String valueCName) throws IOException {
String indexName = ModelName.build(downsampling, indName);
SearchResponse response = getClient().ids(indexName, ids.toArray(new String[0]));
Map<String, Map<String, Object>> idMap = toMap(response);
IntValues[] intValuesArray = new IntValues[numOfLinear];
IntValues[] intValuesArray = new IntValues[linearIndex.size()];
for (int i = 0; i < intValuesArray.length; i++) {
intValuesArray[i] = new IntValues();
}
......@@ -159,8 +159,9 @@ public class MetricsQueryEsDAO extends EsDAO implements IMetricsQueryDAO {
IntKeyLongValueHashMap multipleValues = new IntKeyLongValueHashMap(5);
multipleValues.toObject((String)source.getOrDefault(valueCName, ""));
for (int i = 0; i < intValuesArray.length; i++) {
intValuesArray[i].getLast().setValue(multipleValues.get(i).getValue());
for (int i = 0; i < linearIndex.size(); i++) {
Integer index = linearIndex.get(i);
intValuesArray[i].getLast().setValue(multipleValues.get(index).getValue());
}
}
......
......@@ -145,7 +145,7 @@ public class H2MetricsQueryDAO extends H2SQLExecutor implements IMetricsQueryDAO
@Override public IntValues[] getMultipleLinearIntValues(String indName, Downsampling downsampling,
List<String> ids,
int numOfLinear,
final List<Integer> linearIndex,
String valueCName) throws IOException {
String tableName = ModelName.build(downsampling, indName);
......@@ -157,7 +157,7 @@ public class H2MetricsQueryDAO extends H2SQLExecutor implements IMetricsQueryDAO
idValues.append("'").append(ids.get(valueIdx)).append("'");
}
IntValues[] intValuesArray = new IntValues[numOfLinear];
IntValues[] intValuesArray = new IntValues[linearIndex.size()];
for (int i = 0; i < intValuesArray.length; i++) {
intValuesArray[i] = new IntValues();
}
......@@ -170,10 +170,11 @@ public class H2MetricsQueryDAO extends H2SQLExecutor implements IMetricsQueryDAO
IntKeyLongValueHashMap multipleValues = new IntKeyLongValueHashMap(5);
multipleValues.toObject(resultSet.getString(valueCName));
for (int i = 0; i < intValuesArray.length; i++) {
for (int i = 0; i < linearIndex.size(); i++) {
Integer index = linearIndex.get(i);
KVInt kv = new KVInt();
kv.setId(id);
kv.setValue(multipleValues.get(i).getValue());
kv.setValue(multipleValues.get(index).getValue());
intValuesArray[i].addKVInt(kv);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册