Set error fields to have type text and add hostname field

This commit is contained in:
William Oldham
2023-11-11 16:02:37 +00:00
parent f7074157c2
commit f1f7660ea2
6 changed files with 46 additions and 8 deletions

View File

@@ -363,20 +363,29 @@
},
"error_message": {
"name": "error_message",
"type": "varchar(255)",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "string"
"mappedType": "text"
},
"full_error": {
"name": "full_error",
"type": "varchar(255)",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"hostname": {
"name": "hostname",
"type": "varchar(255)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "string"
}
},

View File

@@ -0,0 +1,17 @@
import { Migration } from '@mikro-orm/migrations';
export class Migration20231111160045 extends Migration {
async up(): Promise<void> {
this.addSql('alter table "provider_metrics" add column "hostname" varchar(255) not null;');
this.addSql('alter table "provider_metrics" alter column "error_message" type text using ("error_message"::text);');
this.addSql('alter table "provider_metrics" alter column "full_error" type text using ("full_error"::text);');
}
async down(): Promise<void> {
this.addSql('alter table "provider_metrics" alter column "error_message" type varchar(255) using ("error_message"::varchar(255));');
this.addSql('alter table "provider_metrics" alter column "full_error" type varchar(255) using ("full_error"::varchar(255));');
this.addSql('alter table "provider_metrics" drop column "hostname";');
}
}

View File

@@ -40,9 +40,12 @@ export class ProviderMetric {
@Property({ name: 'embed_id', nullable: true })
embedId?: string;
@Property({ name: 'error_message', nullable: true })
@Property({ name: 'error_message', nullable: true, type: 'text' })
errorMessage?: string;
@Property({ name: 'full_error', nullable: true })
@Property({ name: 'full_error', nullable: true, type: 'text' })
fullError?: string;
@Property({ name: 'hostname' })
hostname!: string;
}

View File

@@ -18,6 +18,7 @@ export type Metrics = {
| 'type'
| 'provider_id'
| 'embed_id'
| 'hostname'
>;
};
@@ -57,6 +58,7 @@ export async function setupMetrics(app: FastifyInstance) {
'tmdb_id',
'type',
'embed_id',
'hostname',
],
}),
};

View File

@@ -37,19 +37,25 @@ export const metricsRouter = makeRouter((app) => {
window: '30m',
});
const hostname = req.headers.origin?.slice(0, 255) ?? 'unknown origin';
const entities = body.items.map((v) => {
const errorMessage = v.errorMessage?.slice(0, 200);
const truncatedFullError = v.fullError?.slice(0, 2000);
const metric = new ProviderMetric();
em.assign(metric, {
providerId: v.providerId,
embedId: v.embedId,
fullError: v.fullError,
errorMessage: v.errorMessage,
fullError: truncatedFullError,
errorMessage: errorMessage,
episodeId: v.episodeId,
seasonId: v.seasonId,
status: v.status,
title: v.title,
tmdbId: v.tmdbId,
type: v.type,
hostname,
});
return metric;
});
@@ -63,6 +69,7 @@ export const metricsRouter = makeRouter((app) => {
title: entity.title,
tmdb_id: entity.tmdbId,
type: entity.type,
hostname,
});
});