Rajat Dabade 562621a117
Service layer to metrics using USE_SPAN_METRIC feature flag (#3196)
* refactor: remove the dependency of services using redux

* refactor: seperated columns and unit test case

* refactor: move the constant to other file

* refactor: updated test case

* refactor: removed the duplicate enum

* fix: removed the inline function

* fix: removed the inline function

* refactor: removed the magic string

* fix: change the name from matrics to metrics

* fix: one on one mapping of props

* refactor: created a hook to getting services through api call

* fix: linter error

* refactor: renamed the file according to functionality

* refactor: renamed more file according to functionality

* refactor: generic querybuilderWithFormula

* refactor: added generic datasource

* refactor: dynamic disabled in getQueryBuilderQueriesWithFormula

* refactor: generic legend for building query with formulas

* feat: added new TopOperationMetrics component for key operation

* refactor: added feature flag for key operation

* refactor: shifted types and fixed typos

* refactor: separated types and renamed file

* refactor: one on one mapping

* refactor: removed unwanted interfaces and renamed files

* refactor: separated types

* chore: done with basic struction and moving up the files

* chore: moved some files to proper places

* feat: added the support for metrics in service layer

* refactor: shifted SkipOnBoardingModal logic to parent

* refactor: created object to send as an augument for getQueryRangeRequestData

* refactor: changes from columns to getColumns

* refactor: updated the utils function getServiceListFromQuery

* refactor: added memo to getQueryRangeRequestData in serive metrics application

* refactor: separated constants from ServiceMetricsQuery.ts

* refactor: separated mock data and updated test case

* refactor: added useMemo on getColumns

* refactor: made the use of useErrorNotification for show error

* refactor: handled the error case

* refactor: one on one mapping

* chore: useGetQueriesRange hooks type is updated

* refactor: review changes

* chore: update type for columnconstants

* chore: reverted back the changes lost in merge conflicts

---------

Co-authored-by: Vishal Sharma <makeavish786@gmail.com>
Co-authored-by: Palash Gupta <palashgdev@gmail.com>
Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
2023-08-02 15:00:58 +05:30

125 lines
2.8 KiB
TypeScript

import { OPERATORS } from 'constants/queryBuilder';
import { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse';
import { TagFilterItem } from 'types/api/queryBuilder/queryBuilderData';
import {
DataSource,
MetricAggregateOperator,
QueryBuilderData,
} from 'types/common/queryBuilder';
import { DataType, FORMULA, MetricsType, WidgetKeys } from '../constant';
import { DatabaseCallProps, DatabaseCallsRPSProps } from '../types';
import {
getQueryBuilderQueries,
getQueryBuilderQuerieswithFormula,
} from './MetricsPageQueriesFactory';
export const databaseCallsRPS = ({
servicename,
legend,
tagFilterItems,
}: DatabaseCallsRPSProps): QueryBuilderData => {
const autocompleteData: BaseAutocompleteData[] = [
{
key: WidgetKeys.SignozDBLatencyCount,
dataType: DataType.FLOAT64,
isColumn: true,
type: null,
},
];
const groupBy: BaseAutocompleteData[] = [
{ dataType: DataType.STRING, isColumn: false, key: 'db_system', type: 'tag' },
];
const filterItems: TagFilterItem[][] = [
[
{
id: '',
key: {
key: WidgetKeys.Service_name,
dataType: DataType.STRING,
isColumn: false,
type: MetricsType.Resource,
},
op: OPERATORS.IN,
value: [`${servicename}`],
},
...tagFilterItems,
],
];
const legends = [legend];
const dataSource = DataSource.METRICS;
return getQueryBuilderQueries({
autocompleteData,
groupBy,
legends,
filterItems,
dataSource,
});
};
export const databaseCallsAvgDuration = ({
servicename,
tagFilterItems,
}: DatabaseCallProps): QueryBuilderData => {
const autocompleteDataA: BaseAutocompleteData = {
key: WidgetKeys.SignozDbLatencySum,
dataType: DataType.FLOAT64,
isColumn: true,
type: null,
};
const autocompleteDataB: BaseAutocompleteData = {
key: WidgetKeys.SignozDBLatencyCount,
dataType: DataType.FLOAT64,
isColumn: true,
type: null,
};
const additionalItemsA: TagFilterItem[] = [
{
id: '',
key: {
key: WidgetKeys.Service_name,
dataType: DataType.STRING,
isColumn: false,
type: MetricsType.Resource,
},
op: OPERATORS.IN,
value: [`${servicename}`],
},
...tagFilterItems,
];
const autocompleteData: BaseAutocompleteData[] = [
autocompleteDataA,
autocompleteDataB,
];
const additionalItems: TagFilterItem[][] = [
additionalItemsA,
additionalItemsA,
];
const legends = ['', ''];
const disabled = [true, true];
const legendFormulas = ['Average Duration'];
const expressions = [FORMULA.DATABASE_CALLS_AVG_DURATION];
const aggregateOperators = [
MetricAggregateOperator.SUM,
MetricAggregateOperator.SUM,
];
const dataSource = DataSource.METRICS;
return getQueryBuilderQuerieswithFormula({
autocompleteData,
additionalItems,
legends,
disabled,
expressions,
legendFormulas,
aggregateOperators,
dataSource,
});
};