forked from Sunbird-Obsrv/obsrv-api-service
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into metrics-fix
- Loading branch information
Showing
26 changed files
with
947 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
api-service/src/controllers/DataAnalyzePII/DataAnalyzePIIController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Request, Response } from "express"; | ||
import { ResponseHandler } from "../../helpers/ResponseHandler"; | ||
import httpStatus from "http-status"; | ||
import * as _ from "lodash"; | ||
import logger from "../../logger"; | ||
import { detectPII } from "../../connections/commandServiceConnection"; | ||
|
||
const code = "FAILED_TO_DETECT_PII"; | ||
export const dataAnalyzePII = async (req: Request, res: Response) => { | ||
const apiId = _.get(req, 'id') | ||
try { | ||
const userToken = req.get('authorization') as string; | ||
const piiSuggestionsResponse = await detectPII(_.get(req, ['body', 'data']), userToken); | ||
logger.info({apiId , message: `Detected PII successfully` }) | ||
ResponseHandler.successResponse(req, res, { status: httpStatus.OK, data: piiSuggestionsResponse?.data}) | ||
} catch (error: any) { | ||
const errMessage = _.get(error, "response.data.detail") | ||
logger.error(error, apiId, code); | ||
let errorMessage = error; | ||
const statusCode = _.get(error, "status") | ||
if (!statusCode || statusCode == 500) { | ||
errorMessage = { code, message: errMessage || "Failed to detect pii" } | ||
} | ||
ResponseHandler.errorResponse(errorMessage, req, res); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
api-service/src/controllers/DataMetrics/DataMetricsController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Request, Response } from "express"; | ||
import _ from "lodash"; | ||
import { executeNativeQuery } from "../../connections/druidConnection"; | ||
import { ResponseHandler } from "../../helpers/ResponseHandler"; | ||
import vaidationSchema from "./DataMetricsValidationSchema.json" | ||
import { schemaValidation } from "../../services/ValidationService"; | ||
import logger from "../../logger"; | ||
import { obsrvError } from "../../types/ObsrvError"; | ||
import axios from "axios"; | ||
import { config } from "../../configs/Config"; | ||
|
||
const getBaseUrl = (url: string) => { | ||
if (_.startsWith(url, "/prom")) return config.query_api.prometheus.url + _.replace(url, "/prom", "") | ||
} | ||
|
||
const dataMetrics = async (req: Request, res: Response) => { | ||
const isValidSchema = schemaValidation(req.body, vaidationSchema); | ||
if (!isValidSchema?.isValid) { | ||
logger.error({ message: isValidSchema?.message, code: "INVALID_QUERY" }) | ||
throw obsrvError("", "INVALID_QUERY", isValidSchema.message, "BAD_REQUEST", 400) | ||
} | ||
const { query } = req.body || {}; | ||
const endpoint = query.url; | ||
if (_.startsWith(endpoint, "/prom")) { | ||
query.url = getBaseUrl(endpoint) | ||
const { url, method, headers = {}, body = {}, params = {}, ...rest } = query; | ||
const apiResponse = await axios.request({ url, method, headers, params, data: body, ...rest }) | ||
const data = _.get(apiResponse, "data"); | ||
return res.json(data); | ||
} | ||
else { | ||
const query = _.get(req, ["body", "query", "body", "query"]); | ||
const response = await executeNativeQuery(query); | ||
ResponseHandler.successResponse(req, res, { status: 200, data: _.get(response, "data") }); | ||
} | ||
} | ||
|
||
export default dataMetrics; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
api-service/src/controllers/DatasetMetrics/DatasetMetrics.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string", | ||
"enum": [ | ||
"api.dataset.metrics" | ||
] | ||
}, | ||
"ver": { | ||
"type": "string" | ||
}, | ||
"ts": { | ||
"type": "string" | ||
}, | ||
"params": { | ||
"type": "object", | ||
"properties": { | ||
"msgid": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"msgid" | ||
], | ||
"additionalProperties": false | ||
}, | ||
"request": { | ||
"type": "object", | ||
"properties": { | ||
"dataset_id": { | ||
"type": "string" | ||
}, | ||
"category": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"enum": [ | ||
"data_freshness", | ||
"data_observability", | ||
"data_volume", | ||
"data_lineage", | ||
"connectors", | ||
"data_quality" | ||
] | ||
}, | ||
"minItems": 1 | ||
}, | ||
"query_time_period":{ | ||
"type": "integer", | ||
"minimum": 1 | ||
} | ||
}, | ||
"required": [ | ||
"category", | ||
"dataset_id" | ||
] | ||
} | ||
}, | ||
"required": ["id", "ver", "ts", "params", "request"] | ||
} |
Oops, something went wrong.