mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-11 20:59:00 +08:00
refactor: conditional based apdex on metrics and trace query range (#4395)
* refactor: conditional based apdex on metrics and trace query range * chore: add invalid float conversion * Revert "refactor: conditional based apdex on metrics and trace query range" This reverts commit ca44a7aedd9d5635fe28c65f1608f4822a6bf204. * refactor: added servicename to the query params --------- Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
This commit is contained in:
parent
51c1f88593
commit
4a7d972c85
@ -4,5 +4,6 @@ import { MetricMetaProps } from 'types/api/metrics/getApDex';
|
||||
|
||||
export const getMetricMeta = (
|
||||
metricName: string,
|
||||
servicename: string,
|
||||
): Promise<AxiosResponse<MetricMetaProps>> =>
|
||||
axios.get(`/metric_meta?metricName=${metricName}`);
|
||||
axios.get(`/metric_meta?metricName=${metricName}&serviceName=${servicename}`);
|
||||
|
@ -1,7 +1,9 @@
|
||||
import Spinner from 'components/Spinner';
|
||||
import { useGetMetricMeta } from 'hooks/apDex/useGetMetricMeta';
|
||||
import useErrorNotification from 'hooks/useErrorNotification';
|
||||
import { useParams } from 'react-router-dom';
|
||||
|
||||
import { IServiceName } from '../../types';
|
||||
import ApDexMetrics from './ApDexMetrics';
|
||||
import { metricMeta } from './constants';
|
||||
import { ApDexDataSwitcherProps } from './types';
|
||||
@ -13,7 +15,8 @@ function ApDexMetricsApplication({
|
||||
thresholdValue,
|
||||
topLevelOperationsRoute,
|
||||
}: ApDexDataSwitcherProps): JSX.Element {
|
||||
const { data, isLoading, error } = useGetMetricMeta(metricMeta);
|
||||
const { servicename } = useParams<IServiceName>();
|
||||
const { data, isLoading, error } = useGetMetricMeta(metricMeta, servicename);
|
||||
useErrorNotification(error);
|
||||
|
||||
if (isLoading) {
|
||||
|
@ -5,8 +5,9 @@ import { MetricMetaProps } from 'types/api/metrics/getApDex';
|
||||
|
||||
export const useGetMetricMeta = (
|
||||
metricName: string,
|
||||
servicename: string,
|
||||
): UseQueryResult<AxiosResponse<MetricMetaProps>, AxiosError> =>
|
||||
useQuery<AxiosResponse<MetricMetaProps>, AxiosError>({
|
||||
queryKey: [{ metricName }],
|
||||
queryFn: async () => getMetricMeta(metricName),
|
||||
queryKey: [{ metricName, servicename }],
|
||||
queryFn: async () => getMetricMeta(metricName, servicename),
|
||||
});
|
||||
|
@ -36,7 +36,8 @@ func (aH *APIHandler) getApdexSettings(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (aH *APIHandler) getLatencyMetricMetadata(w http.ResponseWriter, r *http.Request) {
|
||||
metricName := r.URL.Query().Get("metricName")
|
||||
metricMetadata, err := aH.reader.GetLatencyMetricMetadata(r.Context(), metricName, aH.preferDelta)
|
||||
serviceName := r.URL.Query().Get("serviceName")
|
||||
metricMetadata, err := aH.reader.GetLatencyMetricMetadata(r.Context(), metricName, serviceName, aH.preferDelta)
|
||||
if err != nil {
|
||||
RespondError(w, &model.ApiError{Err: err, Typ: model.ErrorInternal}, nil)
|
||||
return
|
||||
|
@ -4057,8 +4057,8 @@ func (r *ClickHouseReader) GetMetricAttributeValues(ctx context.Context, req *v3
|
||||
return &attributeValues, nil
|
||||
}
|
||||
|
||||
func (r *ClickHouseReader) GetLatencyMetricMetadata(ctx context.Context, metricName string, preferDelta bool) (*v3.LatencyMetricMetadataResponse, error) {
|
||||
query := fmt.Sprintf("SELECT DISTINCT(temporality) from %s.%s WHERE metric_name='%s'", signozMetricDBName, signozTSTableName, metricName)
|
||||
func (r *ClickHouseReader) GetLatencyMetricMetadata(ctx context.Context, metricName, serviceName string, preferDelta bool) (*v3.LatencyMetricMetadataResponse, error) {
|
||||
query := fmt.Sprintf("SELECT DISTINCT(temporality) from %s.%s WHERE metric_name='%s' AND JSONExtractString(labels, 'service_name') = '%s'", signozMetricDBName, signozTSTableName, metricName, serviceName)
|
||||
rows, err := r.db.Query(ctx, query, metricName)
|
||||
if err != nil {
|
||||
zap.S().Error(err)
|
||||
@ -4077,7 +4077,7 @@ func (r *ClickHouseReader) GetLatencyMetricMetadata(ctx context.Context, metricN
|
||||
}
|
||||
}
|
||||
|
||||
query = fmt.Sprintf("SELECT DISTINCT(toFloat64(JSONExtractString(labels, 'le'))) as le from %s.%s WHERE metric_name='%s' ORDER BY le", signozMetricDBName, signozTSTableName, metricName)
|
||||
query = fmt.Sprintf("SELECT DISTINCT(JSONExtractString(labels, 'le')) as le from %s.%s WHERE metric_name='%s' AND JSONExtractString(labels, 'service_name') = '%s' ORDER BY le", signozMetricDBName, signozTSTableName, metricName, serviceName)
|
||||
rows, err = r.db.Query(ctx, query, metricName)
|
||||
if err != nil {
|
||||
zap.S().Error(err)
|
||||
@ -4087,10 +4087,18 @@ func (r *ClickHouseReader) GetLatencyMetricMetadata(ctx context.Context, metricN
|
||||
|
||||
var leFloat64 []float64
|
||||
for rows.Next() {
|
||||
var le float64
|
||||
if err := rows.Scan(&le); err != nil {
|
||||
var leStr string
|
||||
if err := rows.Scan(&leStr); err != nil {
|
||||
return nil, fmt.Errorf("error while scanning rows: %s", err.Error())
|
||||
}
|
||||
le, err := strconv.ParseFloat(leStr, 64)
|
||||
// ignore the error and continue if the value is not a float
|
||||
// ideally this should not happen but we have seen ClickHouse
|
||||
// returning empty string for some values
|
||||
if err != nil {
|
||||
zap.S().Error("error while parsing le value: ", err)
|
||||
continue
|
||||
}
|
||||
if math.IsInf(le, 0) {
|
||||
continue
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ type Reader interface {
|
||||
QueryDashboardVars(ctx context.Context, query string) (*model.DashboardVar, error)
|
||||
CheckClickHouse(ctx context.Context) error
|
||||
|
||||
GetLatencyMetricMetadata(context.Context, string, bool) (*v3.LatencyMetricMetadataResponse, error)
|
||||
GetLatencyMetricMetadata(context.Context, string, string, bool) (*v3.LatencyMetricMetadataResponse, error)
|
||||
}
|
||||
|
||||
type Querier interface {
|
||||
|
Loading…
x
Reference in New Issue
Block a user