From 5bc2c176734a272a9ed023a856c2ca562b236d7c Mon Sep 17 00:00:00 2001 From: Vamsi Manohar Date: Thu, 3 Nov 2022 14:56:40 -0700 Subject: [PATCH] Prometheus Mappings Fix Signed-off-by: Vamsi Manohar --- dashboards-observability/public/plugin.ts | 2 +- .../public/services/timestamp/timestamp.ts | 50 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/dashboards-observability/public/plugin.ts b/dashboards-observability/public/plugin.ts index a14131546..1e3189e57 100644 --- a/dashboards-observability/public/plugin.ts +++ b/dashboards-observability/public/plugin.ts @@ -47,7 +47,7 @@ export class ObservabilityPlugin implements Plugin isEqual(type, dateTimeType)); @@ -60,6 +61,53 @@ export default class TimestampUtils { } async getIndexMappings(index: string) { + const myArray = index.split('.'); + if (myArray.length > 1) { + if (await this.isPrometheusCatalog(myArray[0])) { + const mappings = await this.pplService.fetch({ + query: 'describe ' + index + ' | fields COLUMN_NAME, DATA_TYPE', + format: 'jdbc', + }); + return this.convertToMappings(index, mappings); + } + } return await this.dslService.fetchFields(index); } + + async isPrometheusCatalog(catalog: string) { + const catalogs = await this.pplService.fetch({ + query: "show catalogs | where CONNECTOR_TYPE='PROMETHEUS' | fields CATALOG_NAME", + format: 'viz', + }); + if ( + catalogs.data && + catalogs.data.CATALOG_NAME && + catalogs.data.CATALOG_NAME.includes(catalog) + ) { + return true; + } else { + return false; + } + } + + private convertToMappings(index: string, {datarows}: object) { + const result = {}; + result[index] = {}; + result[index]["mappings"]={}; + result[index]["mappings"]["properties"] = {}; + if(datarows) { + for (const s of datarows) { + const key = s[0]; + let datatype = s[1]; + if(datatype === 'timestamp') { + datatype = 'date'; + } + result[index]["mappings"]["properties"][key] = { + type : datatype + }; + } + } + console.log(result); + return result; + } }