UNPKG

@hpcc-js/comms

Version:
226 lines 13.2 kB
import { __awaiter, __extends, __generator, __spreadArray } from "tslib"; import { scopedLogger } from "@hpcc-js/util"; import { LogaccessServiceBase, WsLogaccess } from "./wsdl/ws_logaccess/v1.05/ws_logaccess"; var logger = scopedLogger("@hpcc-js/comms/services/wsLogaccess.ts"); export { WsLogaccess }; var LogaccessService = /** @class */ (function (_super) { __extends(LogaccessService, _super); function LogaccessService() { return _super !== null && _super.apply(this, arguments) || this; } LogaccessService.prototype.GetLogAccessInfo = function (request) { if (request === void 0) { request = {}; } if (!this._logAccessInfo) { this._logAccessInfo = _super.prototype.GetLogAccessInfo.call(this, request); } return this._logAccessInfo; }; LogaccessService.prototype.GetLogs = function (request) { return _super.prototype.GetLogs.call(this, request); }; LogaccessService.prototype.GetLogsEx = function (request) { return __awaiter(this, void 0, void 0, function () { var logInfo, columnMap, convertLogLine, getLogsRequest, filters, _loop_1, key, binaryLogFilter_1; var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; return __generator(this, function (_l) { switch (_l.label) { case 0: return [4 /*yield*/, this.GetLogAccessInfo()]; case 1: logInfo = _l.sent(); columnMap = {}; logInfo.Columns.Column.forEach(function (column) { return columnMap[column.LogType] = column.Name; }); convertLogLine = function (line) { var _a; var retVal = {}; for (var key in columnMap) { if (line === null || line === void 0 ? void 0 : line.fields) { retVal[key] = (_a = Object.assign.apply(Object, __spreadArray([{}], line.fields, false))[columnMap[key]]) !== null && _a !== void 0 ? _a : ""; } else { retVal[key] = ""; } } return retVal; }; getLogsRequest = { Filter: { leftBinaryFilter: { BinaryLogFilter: [{ leftFilter: { LogCategory: WsLogaccess.LogAccessType.All, }, }] } }, Range: { StartDate: new Date(0).toISOString(), }, LogLineStartFrom: (_a = request.LogLineStartFrom) !== null && _a !== void 0 ? _a : 0, LogLineLimit: (_b = request.LogLineLimit) !== null && _b !== void 0 ? _b : 100, SelectColumnMode: WsLogaccess.LogSelectColumnMode.DEFAULT, Format: "JSON", SortBy: { SortCondition: [{ BySortType: WsLogaccess.SortColumType.ByDate, ColumnName: "", Direction: 0 }] } }; filters = []; _loop_1 = function (key) { var searchField; if (key in columnMap) { if (Object.values(WsLogaccess.LogColumnType).includes(key)) { searchField = key; } else { searchField = columnMap[key]; } } var logCategory; if (searchField) { switch (searchField) { case WsLogaccess.LogColumnType.workunits: case "hpcc.log.jobid": logCategory = WsLogaccess.LogAccessType.ByJobID; break; case WsLogaccess.LogColumnType.audience: case "hpcc.log.audience": logCategory = WsLogaccess.LogAccessType.ByTargetAudience; break; case WsLogaccess.LogColumnType.class: case "hpcc.log.class": logCategory = WsLogaccess.LogAccessType.ByLogType; break; case WsLogaccess.LogColumnType.components: case "kubernetes.container.name": logCategory = WsLogaccess.LogAccessType.ByComponent; break; default: logCategory = WsLogaccess.LogAccessType.ByFieldName; searchField = columnMap[key]; } if (Array.isArray(request[key])) { request[key].forEach(function (value) { if (logCategory === WsLogaccess.LogAccessType.ByComponent) { value += "*"; } filters.push({ LogCategory: logCategory, SearchField: searchField, SearchByValue: value }); }); } else { var value = request[key]; if (logCategory === WsLogaccess.LogAccessType.ByComponent) { // append wildcard to end of search value to include ephemeral // containers that aren't listed in ECL Watch's filters value += "*"; } filters.push({ LogCategory: logCategory, SearchField: searchField, SearchByValue: value }); } } }; for (key in request) { _loop_1(key); } if (filters.length > 2) { binaryLogFilter_1 = getLogsRequest.Filter.leftBinaryFilter.BinaryLogFilter[0]; filters.forEach(function (filter, i) { var operator = WsLogaccess.LogAccessFilterOperator.AND; if (i > 0) { if (filters[i - 1].SearchField === filter.SearchField) { operator = WsLogaccess.LogAccessFilterOperator.OR; } if (i === filters.length - 1) { binaryLogFilter_1.Operator = operator; binaryLogFilter_1.rightFilter = filter; } else { binaryLogFilter_1.Operator = operator; binaryLogFilter_1.rightBinaryFilter = { BinaryLogFilter: [{ leftFilter: filter }] }; binaryLogFilter_1 = binaryLogFilter_1.rightBinaryFilter.BinaryLogFilter[0]; } } else { binaryLogFilter_1.leftFilter = filter; } }); } else { delete getLogsRequest.Filter.leftBinaryFilter; getLogsRequest.Filter.leftFilter = { LogCategory: WsLogaccess.LogAccessType.All }; if ((_c = filters[0]) === null || _c === void 0 ? void 0 : _c.SearchField) { getLogsRequest.Filter.leftFilter = { LogCategory: (_d = filters[0]) === null || _d === void 0 ? void 0 : _d.LogCategory, SearchField: (_e = filters[0]) === null || _e === void 0 ? void 0 : _e.SearchField, SearchByValue: (_f = filters[0]) === null || _f === void 0 ? void 0 : _f.SearchByValue }; } if ((_g = filters[1]) === null || _g === void 0 ? void 0 : _g.SearchField) { getLogsRequest.Filter.Operator = WsLogaccess.LogAccessFilterOperator.AND; if (filters[0].SearchField === filters[1].SearchField) { getLogsRequest.Filter.Operator = WsLogaccess.LogAccessFilterOperator.OR; } getLogsRequest.Filter.rightFilter = { LogCategory: (_h = filters[1]) === null || _h === void 0 ? void 0 : _h.LogCategory, SearchField: (_j = filters[1]) === null || _j === void 0 ? void 0 : _j.SearchField, SearchByValue: (_k = filters[1]) === null || _k === void 0 ? void 0 : _k.SearchByValue }; } } if (request.StartDate) { getLogsRequest.Range.StartDate = request.StartDate.toISOString(); } if (request.EndDate) { getLogsRequest.Range.EndDate = request.EndDate.toISOString(); } return [2 /*return*/, this.GetLogs(getLogsRequest).then(function (response) { var _a, _b, _c; try { var logLines = JSON.parse(response.LogLines); var lines = []; switch (logInfo.RemoteLogManagerType) { case "azureloganalyticscurl": case "elasticstack": case "grafanacurl": lines = (_b = (_a = logLines.lines) === null || _a === void 0 ? void 0 : _a.map(convertLogLine)) !== null && _b !== void 0 ? _b : []; break; default: logger.warning("Unknown RemoteLogManagerType: ".concat(logInfo.RemoteLogManagerType)); lines = []; } return { lines: lines, total: (_c = response.TotalLogLinesAvailable) !== null && _c !== void 0 ? _c : 10000 }; } catch (e) { logger.error(e); } return { lines: [], total: 0 }; })]; } }); }); }; return LogaccessService; }(LogaccessServiceBase)); export { LogaccessService }; //# sourceMappingURL=wsLogaccess.js.map