Add orderby for listing KpiResult Times Series (#8942)

* Add orderby for listing KpiResult Times Series

* Add order by param for kpi results

Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com>
This commit is contained in:
Mohit Yadav 2022-11-22 22:18:47 +05:30 committed by GitHub
parent 68e6ed5421
commit 67cd61cf79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 13 deletions

View File

@ -2953,6 +2953,11 @@ public interface CollectionDAO {
}
interface EntityExtensionTimeSeriesDAO {
enum OrderBy {
ASC,
DESC
};
@ConnectionAwareSqlUpdate(
value =
"INSERT INTO entity_extension_time_series(entityFQN, extension, jsonSchema, json) "
@ -3036,6 +3041,16 @@ public interface CollectionDAO {
@Bind("extension") String extension,
@Bind("startTs") Long startTs,
@Bind("endTs") long endTs);
@SqlQuery(
"SELECT json FROM entity_extension_time_series where entityFQN = :entityFQN and extension = :extension "
+ " AND timestamp >= :startTs and timestamp <= :endTs ORDER BY timestamp <orderBy>")
List<String> listBetweenTimestampsByOrder(
@Bind("entityFQN") String entityFQN,
@Bind("extension") String extension,
@Bind("startTs") Long startTs,
@Bind("endTs") long endTs,
@Define("orderBy") OrderBy orderBy);
}
class EntitiesCountRowMapper implements RowMapper<EntitiesCount> {

View File

@ -185,13 +185,15 @@ public class KpiRepository extends EntityRepository<Kpi> {
daoCollection.entityExtensionTimeSeriesDao().getLatestExtension(fqn, KPI_RESULT_EXTENSION), KpiResult.class);
}
public ResultList<KpiResult> getKpiResults(String fqn, Long startTs, Long endTs) throws IOException {
public ResultList<KpiResult> getKpiResults(
String fqn, Long startTs, Long endTs, CollectionDAO.EntityExtensionTimeSeriesDAO.OrderBy orderBy)
throws IOException {
List<KpiResult> kpiResults;
kpiResults =
JsonUtils.readObjects(
daoCollection
.entityExtensionTimeSeriesDao()
.listBetweenTimestamps(fqn, KPI_RESULT_EXTENSION, startTs, endTs),
.listBetweenTimestampsByOrder(fqn, KPI_RESULT_EXTENSION, startTs, endTs, orderBy),
KpiResult.class);
return new ResultList<>(kpiResults, String.valueOf(startTs), String.valueOf(endTs), kpiResults.size());
}

View File

@ -423,9 +423,14 @@ public class KpiResource extends EntityResource<Kpi, KpiRepository> {
@Parameter(description = "Filter kpi results before the given end timestamp", schema = @Schema(type = "number"))
@NonNull
@QueryParam("endTs")
Long endTs)
Long endTs,
@Parameter(description = "Order the result ", schema = @Schema(type = "string"))
@Valid
@QueryParam("orderBy")
@DefaultValue("DESC")
CollectionDAO.EntityExtensionTimeSeriesDAO.OrderBy orderBy)
throws IOException {
return dao.getKpiResults(fqn, startTs, endTs);
return dao.getKpiResults(fqn, startTs, endTs, orderBy);
}
@GET

View File

@ -77,10 +77,14 @@ export const getKPIByName = async (kpiName: string, params?: ListParams) => {
return response.data;
};
export const getListKpiResult = async (fqn: string, params: KpiResultParam) => {
export const getListKpiResult = async (
fqn: string,
params: KpiResultParam,
orderBy = 'ASC'
) => {
const response = await APIClient.get<PagingResponse<KpiResult[]>>(
`/kpi/${fqn}/kpiResult`,
{ params }
{ params: { ...params, orderBy } }
);
return response.data;

View File

@ -53,9 +53,9 @@ import {
KpiTargetType,
} from '../../generated/api/dataInsight/kpi/createKpiRequest';
import {
ChartDataType,
ChartParameterValues,
DataInsightChart,
DataType,
} from '../../generated/dataInsight/dataInsightChart';
import { DataInsightChartType } from '../../generated/dataInsight/dataInsightChartResult';
import { Kpi } from '../../generated/dataInsight/kpi/kpi';
@ -103,8 +103,8 @@ const AddKPIPage = () => {
() =>
(selectedChart?.metrics ?? []).filter((metric) =>
// only return supported data type
[DataType.Number, DataType.Percentage].includes(
metric.dataType as DataType
[ChartDataType.Number, ChartDataType.Percentage].includes(
metric.chartDataType as ChartDataType
)
),
[selectedChart]
@ -166,7 +166,8 @@ const AddKPIPage = () => {
const handleSubmit: FormProps['onFinish'] = async (values) => {
const startDate = getTimeStampByDateTime(kpiDates.startDate);
const endDate = getTimeStampByDateTime(kpiDates.endDate);
const metricType = selectedMetric?.dataType as unknown as KpiTargetType;
const metricType =
selectedMetric?.chartDataType as unknown as KpiTargetType;
const targetValue = getKpiTargetValueByMetricType(metricType, metricValue);
@ -300,7 +301,7 @@ const AddKPIPage = () => {
onChange={handleMetricSelect}>
{metricTypes.map((metric) => (
<Option key={metric.name}>
{`${metric.name} (${metric.dataType})`}
{`${metric.name} (${metric.chartDataType})`}
</Option>
))}
</Select>
@ -323,7 +324,8 @@ const AddKPIPage = () => {
},
]}>
<>
{selectedMetric.dataType === DataType.Percentage && (
{selectedMetric.chartDataType ===
ChartDataType.Percentage && (
<Row gutter={20}>
<Col span={20}>
<Slider
@ -356,7 +358,7 @@ const AddKPIPage = () => {
</Col>
</Row>
)}
{selectedMetric.dataType === DataType.Number && (
{selectedMetric.chartDataType === ChartDataType.Number && (
<InputNumber
className="w-full"
min={0}