@tekkare/romulus 0.1.303 → 0.1.304
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createError, defineEventHandler, getQuery, readBody } from "h3";
|
|
2
2
|
import { requireOipSession } from "../../utils/oipAuth";
|
|
3
3
|
import { findOipEsIndex, resolveOipEsIndex } from "../../utils/oipEsIndices";
|
|
4
|
+
import { oipReportIndexUsage } from "../../utils/oipIndexUsage";
|
|
4
5
|
import { oipResourceIndexes, type OipEsCluster } from "../../../app/utils/oipResources";
|
|
5
6
|
import { ES_INDEX } from "../../../app/oip-drugs/esIndices";
|
|
6
7
|
import { OIP_PATIENT_INDEXES } from "../../../app/oip-patients/indexes";
|
|
@@ -145,7 +146,9 @@ export default defineEventHandler(async (event) => {
|
|
|
145
146
|
throw createError({ status: 503, message: `Elasticsearch cluster not configured: ${cluster}` });
|
|
146
147
|
}
|
|
147
148
|
|
|
148
|
-
const
|
|
149
|
+
const physicalNames = await Promise.all(refs.map(physicalOf));
|
|
150
|
+
oipReportIndexUsage(event, physicalNames);
|
|
151
|
+
const physical = physicalNames.join(",");
|
|
149
152
|
const domain = target.domain.replace(/^https?:\/\//, "").replace(/\/+$/, "");
|
|
150
153
|
return await $fetch(`https://${domain}/${physical}/_search`, {
|
|
151
154
|
method: "POST",
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
import { getOipAccessToken } from "./oipAuth";
|
|
3
|
+
import { oipAppUrls } from "./oipGuards";
|
|
4
|
+
|
|
5
|
+
// Releve « cette app lit cet index » pour la sonde hebdo de la Virtual Lab API
|
|
6
|
+
// (POST /index-health/usage). La sonde compare chaque lundi le mapping et les
|
|
7
|
+
// valeurs des champs keyword des index lus, et nomme dans son mail les apps
|
|
8
|
+
// touchees : un champ passe en nested vide les filtres sans aucune erreur.
|
|
9
|
+
// A appeler depuis tout proxy ES d'app, avec les noms physiques interroges.
|
|
10
|
+
|
|
11
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
12
|
+
|
|
13
|
+
/** Derniere declaration par index : une par jour et par instance suffit. */
|
|
14
|
+
const reported = new Map<string, number>();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Declare les index lus, sans attendre ni jamais faire echouer la requete :
|
|
18
|
+
* une sonde muette vaut mieux qu'un filtre qui ne charge plus. Sans URL d'app
|
|
19
|
+
* (NUXT_OIP_APP_URL) ni jeton, rien ne part.
|
|
20
|
+
*/
|
|
21
|
+
export function oipReportIndexUsage(event: H3Event, physicalIndexes: string[]) {
|
|
22
|
+
const apiUrl = (useRuntimeConfig().oipVirtualLabApiUrl as string) || process.env.VIRTUAL_LAB_API_URL;
|
|
23
|
+
let app = "";
|
|
24
|
+
try {
|
|
25
|
+
const url = oipAppUrls()[0]!;
|
|
26
|
+
app = new URL(/^https?:\/\//.test(url) ? url : `https://${url}`).host;
|
|
27
|
+
} catch {
|
|
28
|
+
// App sans URL declaree : rien a signaler.
|
|
29
|
+
}
|
|
30
|
+
if (!apiUrl || !app) return;
|
|
31
|
+
|
|
32
|
+
const now = Date.now();
|
|
33
|
+
const due = physicalIndexes.filter((index) => now - (reported.get(index) ?? 0) > DAY_MS);
|
|
34
|
+
if (!due.length) return;
|
|
35
|
+
for (const index of due) reported.set(index, now);
|
|
36
|
+
|
|
37
|
+
void (async () => {
|
|
38
|
+
const token = await getOipAccessToken(event);
|
|
39
|
+
if (!token) throw new Error("no session");
|
|
40
|
+
await $fetch(`${apiUrl}/index-health/usage`, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
43
|
+
body: { app, indexes: due },
|
|
44
|
+
});
|
|
45
|
+
})().catch((err: any) => {
|
|
46
|
+
// Reessaie a la prochaine requete plutot que dans un jour.
|
|
47
|
+
for (const index of due) reported.delete(index);
|
|
48
|
+
console.warn(`[oip/index-usage] report failed: ${err?.message ?? err}`);
|
|
49
|
+
});
|
|
50
|
+
}
|