File
Methods
|
Async
fetchCostMetricsForSync
|
fetchCostMetricsForSync(costEndpoint: any, queryOptions: literal type)
|
|
|
Parameters :
| Name |
Type |
Optional |
| costEndpoint |
any
|
No
|
| queryOptions |
literal type
|
No
|
Returns : unknown
|
|
Async
fetchMetricsFromSource
|
fetchMetricsFromSource(model: Model)
|
|
|
Parameters :
| Name |
Type |
Optional |
| model |
Model
|
No
|
|
|
Async
fetchModelMetricsForSync
|
fetchModelMetricsForSync(model: Model, queryOptions: literal type)
|
|
|
Parameters :
| Name |
Type |
Optional |
| model |
Model
|
No
|
| queryOptions |
literal type
|
No
|
Returns : unknown
|
|
Async
fetchModelMetricsFromStore
|
fetchModelMetricsFromStore(model: Model, queryOptions: literal type)
|
|
|
Parameters :
| Name |
Type |
Optional |
| model |
Model
|
No
|
| queryOptions |
literal type
|
No
|
Returns : unknown
|
|
Async
getModelInfo
|
getModelInfo(model: Model)
|
|
|
Parameters :
| Name |
Type |
Optional |
| model |
Model
|
No
|
|
|
Async
saveMetrics
|
saveMetrics(metrics, turoAttributes: any)
|
|
|
Parameters :
| Name |
Type |
Optional |
| metrics |
|
No
|
| turoAttributes |
any
|
No
|
Returns : unknown
|
|
Static
METRICS_PROTO_MESSAGE_NAME
|
Type : string
|
Default value : "MetricsData"
|
|
|
|
Static
METRICS_PROTO_PATH
|
Type : string
|
Default value : "providers/opentelemetry/proto/metrics.proto"
|
|
|
|
Private
metricsEndpoint
|
Type : string
|
Default value : "/v1/metrics"
|
|
|
|
Private
otelCollectorUrl
|
Default value : process.env.OTEL_URL
|
|
|
|
Private
tracesEndpoint
|
Type : string
|
Default value : "/v1/traces"
|
|
|
import { ForbiddenException, Injectable } from "@nestjs/common";
import { Model } from "../../models/entities/model.entity";
import { InfluxDbProvider } from "../influxDB/influxdb.provider";
@Injectable()
export class OpentelemetryProvider {
constructor(private readonly influxDbProvider: InfluxDbProvider) {}
private otelCollectorUrl = process.env.OTEL_URL;
private metricsEndpoint = "/v1/metrics";
private tracesEndpoint = "/v1/traces";
public static METRICS_PROTO_PATH =
"providers/opentelemetry/proto/metrics.proto";
public static METRICS_PROTO_MESSAGE_NAME = "MetricsData";
async saveMetrics(metrics, turoAttributes: any) {
if ("resourceMetrics" in metrics) {
metrics["resourceMetrics"].forEach((resourceMetric) => {
if ("attributes" in resourceMetric["resource"]) {
resourceMetric["resource"]["attributes"].push(...turoAttributes);
}
});
}
const metricsUrl = `${this.otelCollectorUrl}${this.metricsEndpoint}`;
const response = await fetch(metricsUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(metrics),
});
return response;
}
async getModelInfo(model: Model) {
throw new ForbiddenException(
`Model: ${model.slug} - Can't get model info from source when provider is OPENTELEMETRY`,
);
}
async fetchMetricsFromSource(model: Model) {
throw new ForbiddenException(
`Model: ${model.slug} - Can't fetch metrics from source when provider is OPENTELEMETRY`,
);
}
async fetchModelMetricsFromStore(
model: Model,
queryOptions: {
startTime: number;
endTime: number;
},
) {
const start = new Date(queryOptions.startTime);
const end = new Date(queryOptions.endTime);
return await this.influxDbProvider.fetchModelMetricsFromStore(
model,
start,
end,
);
}
async fetchModelMetricsForSync(
model: Model,
queryOptions: {
startTime: number;
endTime: number;
},
) {
const start = new Date(queryOptions.startTime);
const end = new Date(queryOptions.endTime);
return await this.influxDbProvider.fetchModelMetricsForSync(
model,
start,
end,
);
}
async fetchCostMetricsForSync(
costEndpoint: any,
queryOptions: {
startTime: number;
endTime: number;
},
) {
const start = new Date(queryOptions.startTime);
const end = new Date(queryOptions.endTime);
return await this.influxDbProvider.fetchCostMetricsForSync(
costEndpoint,
start,
end,
);
}
}