mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
refactor: Add isMonotonic column to Metric model
This code change adds a new column, 'isMonotonic', to the Metric model in the AnalyticsModels directory. The column is optional and represents whether the metric is monotonic. This change ensures that the necessary data is captured and stored correctly for metrics in the system.
This commit is contained in:
parent
77f1262ff5
commit
55d947fb39
@ -0,0 +1,34 @@
|
||||
import DataMigrationBase from './DataMigrationBase';
|
||||
import AnalyticsTableColumn from 'Common/Types/AnalyticsDatabase/TableColumn';
|
||||
import TableColumnType from 'Common/Types/AnalyticsDatabase/TableColumnType';
|
||||
import MetricService from 'CommonServer/Services/MetricService';
|
||||
import Metric from 'Model/AnalyticsModels/Metric';
|
||||
|
||||
export default class AddIsMonotonicToMetric extends DataMigrationBase {
|
||||
public constructor() {
|
||||
super('AddIsMonotonicToMetric');
|
||||
}
|
||||
|
||||
public override async migrate(): Promise<void> {
|
||||
const column: AnalyticsTableColumn | undefined =
|
||||
new Metric().tableColumns.find((column: AnalyticsTableColumn) => {
|
||||
return column.key === 'isMonotonic';
|
||||
});
|
||||
|
||||
if (!column) {
|
||||
return;
|
||||
}
|
||||
|
||||
const columnType: TableColumnType | null =
|
||||
await MetricService.getColumnTypeInDatabase(column);
|
||||
|
||||
if (!columnType) {
|
||||
await MetricService.dropColumnInDatabase('isMonotonic');
|
||||
await MetricService.addColumnInDatabase(column);
|
||||
}
|
||||
}
|
||||
|
||||
public override async rollback(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import AddEndDateToMonitorStatusTimeline from './AddEndDateToMonitorStatusTimeli
|
||||
import AddEndDateToMonitorStatusTimelineWhereEndDateIsMissing from './AddEndDateToMonitorStatusTimelineWhereEndDateIsMissing';
|
||||
import AddEndDateToScheduledEventsStateTimeline from './AddEndDateToScheduledEventsStateTimeline';
|
||||
import AddEndedState from './AddEndedState';
|
||||
import AddIsMonotonicToMetric from './AddIsMonotonicToMetric';
|
||||
import AddMonitoringDatesToMonitor from './AddMonitoringDatesToMonitors';
|
||||
import AddOwnerInfoToProjects from './AddOwnerInfoToProject';
|
||||
import AddPointTypeToMetric from './AddPointTypeToMetric';
|
||||
@ -65,6 +66,7 @@ const DataMigrations: Array<DataMigrationBase> = [
|
||||
new ChangeMetricColumnTypeToDecimal(),
|
||||
new AddAggregationTemporalityToMetric(),
|
||||
new AddPointTypeToMetric(),
|
||||
new AddIsMonotonicToMetric(),
|
||||
];
|
||||
|
||||
export default DataMigrations;
|
||||
|
@ -45,16 +45,6 @@ export default class StatusAPI {
|
||||
description: 'Live check counter',
|
||||
});
|
||||
|
||||
public static statusGuage = Telemetry.getGauge({
|
||||
name: 'status.guage',
|
||||
description: 'Status guage',
|
||||
});
|
||||
|
||||
public static stausHistogram = Telemetry.getHistogram({
|
||||
name: 'status.histogram',
|
||||
description: 'Status histogram',
|
||||
});
|
||||
|
||||
public static init(options: StatusAPIOptions): ExpressRouter {
|
||||
const router: ExpressRouter = Express.getRouter();
|
||||
|
||||
@ -69,14 +59,6 @@ export default class StatusAPI {
|
||||
router.get('/status', (req: ExpressRequest, res: ExpressResponse) => {
|
||||
this.statusCheckSuccessCounter.add(1);
|
||||
|
||||
this.statusGuage.addCallback((observableResult)=>{
|
||||
console.log(observableResult);
|
||||
observableResult.observe(1.354);
|
||||
});
|
||||
|
||||
|
||||
this.stausHistogram.record(1.354);
|
||||
|
||||
logger.info('Status check: ok');
|
||||
|
||||
Response.sendJsonObjectResponse(req, res, {
|
||||
|
@ -1,7 +1,9 @@
|
||||
import TelemetryIngest, {
|
||||
TelemetryRequest,
|
||||
} from '../Middleware/TelemetryIngest';
|
||||
import OTelIngestService from '../Service/OTelIngest';
|
||||
import OTelIngestService, {
|
||||
OtelAggregationTemporality,
|
||||
} from '../Service/OTelIngest';
|
||||
import OneUptimeDate from 'Common/Types/Date';
|
||||
import BadRequestException from 'Common/Types/Exception/BadRequestException';
|
||||
import { JSONArray, JSONObject } from 'Common/Types/JSON';
|
||||
@ -19,7 +21,7 @@ import Express, {
|
||||
import logger from 'CommonServer/Utils/Logger';
|
||||
import Response from 'CommonServer/Utils/Response';
|
||||
import Log, { LogSeverity } from 'Model/AnalyticsModels/Log';
|
||||
import Metric, { AggregationTemporality, MetricPointType } from 'Model/AnalyticsModels/Metric';
|
||||
import Metric, { MetricPointType } from 'Model/AnalyticsModels/Metric';
|
||||
import Span, { SpanKind, SpanStatus } from 'Model/AnalyticsModels/Span';
|
||||
import protobuf from 'protobufjs';
|
||||
|
||||
@ -134,18 +136,18 @@ router.post(
|
||||
if (
|
||||
resourceSpan['resource'] &&
|
||||
(resourceSpan['resource'] as JSONObject)[
|
||||
'attributes'
|
||||
'attributes'
|
||||
] &&
|
||||
(
|
||||
(resourceSpan['resource'] as JSONObject)[
|
||||
'attributes'
|
||||
'attributes'
|
||||
] as JSONArray
|
||||
).length > 0
|
||||
) {
|
||||
attributesObject['resource'] =
|
||||
OTelIngestService.getAttributes(
|
||||
(resourceSpan['resource'] as JSONObject)[
|
||||
'attributes'
|
||||
'attributes'
|
||||
] as JSONArray
|
||||
);
|
||||
}
|
||||
@ -193,7 +195,7 @@ router.post(
|
||||
span['status'] &&
|
||||
(span['status'] as JSONObject)?.['code'] &&
|
||||
typeof (span['status'] as JSONObject)?.['code'] ===
|
||||
'number'
|
||||
'number'
|
||||
) {
|
||||
spanStatusCode = (span['status'] as JSONObject)?.[
|
||||
'code'
|
||||
@ -204,7 +206,7 @@ router.post(
|
||||
span['status'] &&
|
||||
(span['status'] as JSONObject)?.['code'] &&
|
||||
typeof (span['status'] as JSONObject)?.['code'] ===
|
||||
'string'
|
||||
'string'
|
||||
) {
|
||||
if (
|
||||
(span['status'] as JSONObject)?.['code'] ===
|
||||
@ -388,14 +390,14 @@ router.post(
|
||||
if (
|
||||
resourceMetric['resource'] &&
|
||||
(resourceMetric['resource'] as JSONObject)[
|
||||
'attributes'
|
||||
'attributes'
|
||||
] &&
|
||||
((resourceMetric['resource'] as JSONObject)[
|
||||
'attributes'
|
||||
] as JSONArray) instanceof Array &&
|
||||
(
|
||||
(resourceMetric['resource'] as JSONObject)[
|
||||
'attributes'
|
||||
'attributes'
|
||||
] as JSONArray
|
||||
).length > 0
|
||||
) {
|
||||
@ -403,7 +405,7 @@ router.post(
|
||||
...attributesObject,
|
||||
resource: OTelIngestService.getAttributes(
|
||||
(resourceMetric['resource'] as JSONObject)[
|
||||
'attributes'
|
||||
'attributes'
|
||||
] as JSONArray
|
||||
),
|
||||
};
|
||||
@ -428,7 +430,7 @@ router.post(
|
||||
(metric['sum'] as JSONObject)['dataPoints'] &&
|
||||
(
|
||||
(metric['sum'] as JSONObject)[
|
||||
'dataPoints'
|
||||
'dataPoints'
|
||||
] as JSONArray
|
||||
).length > 0
|
||||
) {
|
||||
@ -439,8 +441,14 @@ router.post(
|
||||
OTelIngestService.getMetricFromDatapoint({
|
||||
dbMetric: dbMetric,
|
||||
datapoint: datapoint,
|
||||
aggregationTemporality: (metric['sum'] as JSONObject)['aggregationTemporality'] as AggregationTemporality,
|
||||
isMonotonic: (metric['sum'] as JSONObject)['isMonotonic'] as boolean | undefined
|
||||
aggregationTemporality: (
|
||||
metric['sum'] as JSONObject
|
||||
)[
|
||||
'aggregationTemporality'
|
||||
] as OtelAggregationTemporality,
|
||||
isMonotonic: (
|
||||
metric['sum'] as JSONObject
|
||||
)['isMonotonic'] as boolean | undefined,
|
||||
});
|
||||
|
||||
sumMetric.metricPointType = MetricPointType.Sum;
|
||||
@ -452,7 +460,7 @@ router.post(
|
||||
(metric['gauge'] as JSONObject)['dataPoints'] &&
|
||||
(
|
||||
(metric['gauge'] as JSONObject)[
|
||||
'dataPoints'
|
||||
'dataPoints'
|
||||
] as JSONArray
|
||||
).length > 0
|
||||
) {
|
||||
@ -463,8 +471,14 @@ router.post(
|
||||
OTelIngestService.getMetricFromDatapoint({
|
||||
dbMetric: dbMetric,
|
||||
datapoint: datapoint,
|
||||
aggregationTemporality: (metric['gauge'] as JSONObject)['aggregationTemporality'] as AggregationTemporality,
|
||||
isMonotonic: (metric['gauge'] as JSONObject)['isMonotonic'] as boolean | undefined
|
||||
aggregationTemporality: (
|
||||
metric['gauge'] as JSONObject
|
||||
)[
|
||||
'aggregationTemporality'
|
||||
] as OtelAggregationTemporality,
|
||||
isMonotonic: (
|
||||
metric['gauge'] as JSONObject
|
||||
)['isMonotonic'] as boolean | undefined,
|
||||
});
|
||||
|
||||
guageMetric.metricPointType =
|
||||
@ -477,7 +491,7 @@ router.post(
|
||||
(metric['histogram'] as JSONObject)['dataPoints'] &&
|
||||
(
|
||||
(metric['histogram'] as JSONObject)[
|
||||
'dataPoints'
|
||||
'dataPoints'
|
||||
] as JSONArray
|
||||
).length > 0
|
||||
) {
|
||||
@ -488,8 +502,14 @@ router.post(
|
||||
OTelIngestService.getMetricFromDatapoint({
|
||||
dbMetric: dbMetric,
|
||||
datapoint: datapoint,
|
||||
aggregationTemporality: (metric['histogram'] as JSONObject)['aggregationTemporality'] as AggregationTemporality,
|
||||
isMonotonic: (metric['histogram'] as JSONObject)['isMonotonic'] as boolean | undefined
|
||||
aggregationTemporality: (
|
||||
metric['histogram'] as JSONObject
|
||||
)[
|
||||
'aggregationTemporality'
|
||||
] as OtelAggregationTemporality,
|
||||
isMonotonic: (
|
||||
metric['histogram'] as JSONObject
|
||||
)['isMonotonic'] as boolean | undefined,
|
||||
});
|
||||
|
||||
histogramMetric.metricPointType =
|
||||
@ -582,11 +602,11 @@ router.post(
|
||||
if (
|
||||
resourceLog['resource'] &&
|
||||
(resourceLog['resource'] as JSONObject)[
|
||||
'attributes'
|
||||
'attributes'
|
||||
] &&
|
||||
(
|
||||
(resourceLog['resource'] as JSONObject)[
|
||||
'attributes'
|
||||
'attributes'
|
||||
] as JSONArray
|
||||
).length > 0
|
||||
) {
|
||||
@ -594,7 +614,7 @@ router.post(
|
||||
...attributesObject,
|
||||
resource: OTelIngestService.getAttributes(
|
||||
(resourceLog['resource'] as JSONObject)[
|
||||
'attributes'
|
||||
'attributes'
|
||||
] as JSONArray
|
||||
),
|
||||
};
|
||||
|
@ -3,6 +3,11 @@ import { JSONArray, JSONObject, JSONValue } from 'Common/Types/JSON';
|
||||
import JSONFunctions from 'Common/Types/JSONFunctions';
|
||||
import Metric, { AggregationTemporality } from 'Model/AnalyticsModels/Metric';
|
||||
|
||||
export enum OtelAggregationTemporality {
|
||||
Cumulative = 'AGGREGATION_TEMPORALITY_CUMULATIVE',
|
||||
Delta = 'AGGREGATION_TEMPORALITY_DELTA',
|
||||
}
|
||||
|
||||
export default class OTelIngestService {
|
||||
public static getAttributes(items: JSONArray): JSONObject {
|
||||
const finalObj: JSONObject = {};
|
||||
@ -29,14 +34,13 @@ export default class OTelIngestService {
|
||||
}
|
||||
|
||||
public static getMetricFromDatapoint(data: {
|
||||
dbMetric: Metric,
|
||||
datapoint: JSONObject,
|
||||
aggregationTemporality: AggregationTemporality,
|
||||
isMonotonic: boolean | undefined
|
||||
}
|
||||
): Metric {
|
||||
|
||||
const { dbMetric, datapoint, aggregationTemporality, isMonotonic } = data;
|
||||
dbMetric: Metric;
|
||||
datapoint: JSONObject;
|
||||
aggregationTemporality: OtelAggregationTemporality;
|
||||
isMonotonic: boolean | undefined;
|
||||
}): Metric {
|
||||
const { dbMetric, datapoint, aggregationTemporality, isMonotonic } =
|
||||
data;
|
||||
|
||||
const newDbMetric: Metric = Metric.fromJSON(
|
||||
dbMetric.toJSON(),
|
||||
@ -91,14 +95,23 @@ export default class OTelIngestService {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// aggregationTemporality
|
||||
|
||||
if (aggregationTemporality) {
|
||||
newDbMetric.aggregationTemporality = aggregationTemporality;
|
||||
if (
|
||||
aggregationTemporality === OtelAggregationTemporality.Cumulative
|
||||
) {
|
||||
newDbMetric.aggregationTemporality =
|
||||
AggregationTemporality.Cumulative;
|
||||
}
|
||||
|
||||
if (aggregationTemporality === OtelAggregationTemporality.Delta) {
|
||||
newDbMetric.aggregationTemporality =
|
||||
AggregationTemporality.Delta;
|
||||
}
|
||||
}
|
||||
|
||||
if(isMonotonic !== undefined) {
|
||||
if (isMonotonic !== undefined) {
|
||||
newDbMetric.isMonotonic = isMonotonic;
|
||||
}
|
||||
|
||||
|
@ -336,7 +336,6 @@ export default class Metric extends AnalyticsBaseModel {
|
||||
},
|
||||
}),
|
||||
|
||||
|
||||
new AnalyticsTableColumn({
|
||||
key: 'isMonotonic',
|
||||
title: 'Is Monotonic',
|
||||
|
Loading…
Reference in New Issue
Block a user