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 { interface EntityExtensionTimeSeriesDAO {
enum OrderBy {
ASC,
DESC
};
@ConnectionAwareSqlUpdate( @ConnectionAwareSqlUpdate(
value = value =
"INSERT INTO entity_extension_time_series(entityFQN, extension, jsonSchema, json) " "INSERT INTO entity_extension_time_series(entityFQN, extension, jsonSchema, json) "
@ -3036,6 +3041,16 @@ public interface CollectionDAO {
@Bind("extension") String extension, @Bind("extension") String extension,
@Bind("startTs") Long startTs, @Bind("startTs") Long startTs,
@Bind("endTs") long endTs); @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> { 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); 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; List<KpiResult> kpiResults;
kpiResults = kpiResults =
JsonUtils.readObjects( JsonUtils.readObjects(
daoCollection daoCollection
.entityExtensionTimeSeriesDao() .entityExtensionTimeSeriesDao()
.listBetweenTimestamps(fqn, KPI_RESULT_EXTENSION, startTs, endTs), .listBetweenTimestampsByOrder(fqn, KPI_RESULT_EXTENSION, startTs, endTs, orderBy),
KpiResult.class); KpiResult.class);
return new ResultList<>(kpiResults, String.valueOf(startTs), String.valueOf(endTs), kpiResults.size()); 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")) @Parameter(description = "Filter kpi results before the given end timestamp", schema = @Schema(type = "number"))
@NonNull @NonNull
@QueryParam("endTs") @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 { throws IOException {
return dao.getKpiResults(fqn, startTs, endTs); return dao.getKpiResults(fqn, startTs, endTs, orderBy);
} }
@GET @GET

View File

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

View File

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