Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { logger, provide, inject, init } from 'midway-web';
import { FindAndCountAllResult, ModelQueryOptions } from '../../interface/models/common';
import { FindOptions, QueryTypes, Op, WhereOptions } from 'sequelize';
import {
Trace,
TraceQuery,
TraceSummaryQuery,
TraceSummary,
TraceSummaryTrend,
TraceSummaryTrendQuery,
TraceDetailQuery,
} from '../../interface/models/trace';
import { isEmpty, round } from 'lodash';
import {sqlPartTimestampConvertToTs} from '../util/util';
@provide('traceManager')
export class TraceManager {
@logger()
protected logger;
@inject()
protected dw;
@inject()
protected traceModel;
protected instance;
@init()
initialize() {
this.instance = this.dw.instance;
}
import { logger, provide, inject, init } from 'midway-web';
import { FindOptions, QueryTypes, Op } from 'sequelize';
import { SpanTargetList, TraceNode, TraceNodeQuery, TraceNodeSummary, TraceNodeSummaryQuery, SummaryTrend,
TraceNodeSummaryTrendQuery, SpanTargetSummaryTrendQuery, SpanTargetQuery, SpanSummaryTrendQuery,
SpansSummaryTrendResult } from '../../interface/models/traceNode';
import { FindAndCountAllResult, ModelQueryOptions } from '../../interface/models/common';
import { isEmpty, groupBy, each, round } from 'lodash';
import { sqlPartTimestampConvertToTs } from '../util/util';
@provide('traceNodeManager')
export class TraceNodeManager {
@inject()
protected dw;
@logger()
protected logger;
@inject()
protected traceNodeModel;
protected instance;
@init()
initialize() {
this.instance = this.dw.instance;
import { provide, async, config, logger, scope, ScopeEnum } from 'midway-web';
import { BaseDataSource } from './base';
@scope(ScopeEnum.Singleton)
@async()
@provide('dw')
export class DWDataSource extends BaseDataSource {
@config('dw')
config;
@logger('dwLogger')
logger;
name: string = 'dw';
}
import { provide, inject, IApplicationContext, providerWrapper, scope, ScopeEnum } from 'midway-web';
import {IPlatformManagerAdapter} from '../../interface/adapter/IPlatformManagerAdapter';
import {IPlatformAdapter} from '../../interface/adapter/IPlatformAdapter';
@scope(ScopeEnum.Singleton)
@provide('platformManagerAdapter')
export class PlatformManagerAdapter implements IPlatformManagerAdapter {
@inject()
protected platformAdapterDispatcher;
async get(name: string): Promise {
return this.platformAdapterDispatcher(name);
}
}
export function platformAdapterDispatcher(context: IApplicationContext) {
return async (adapterName: string) => {
try {
return await context.getAsync(adapterName + 'PlatformAdapter');
} catch (err) {
import { logger, provide, inject, async } from 'midway-web';
import * as _ from 'lodash';
import * as Interface from '../../interface/services/IErrorService';
import * as Sequelize from 'sequelize';
interface SearchCondition {
[key: string]: any;
}
@async()
@provide('errorManager')
export class ErrorManager {
@logger()
protected logger;
@inject()
protected errorModel;
public async findErrors(options: Interface.QueryErrorOptions) {
const conditions = this.buildSearchConditions(options);
return this.errorModel.findAndCountAll({
where: { [Sequelize.Op.and]: conditions },
order: [[ 'timestamp', 'desc' ]],
offset: (options.page - 1) * options.pageSize,
limit: options.pageSize,
import { provide, inject } from 'midway-web';
import * as _ from 'lodash';
import {AppSelector, IndicatorResult, MetricNameJSON, TimeWindowOptions} from '../../interface/services/common';
import {TSDB} from '../dataSource/tsdb';
import {ISadMetricsAdapter} from '../../interface/adapter/ISadMetricsAdapter';
@provide('metricsManager')
export class MetricsManager {
@inject('tsdb')
protected tsdb: TSDB;
@inject('sadMetricsAdapter')
protected sadMetricsAdapter: ISadMetricsAdapter;
static pickLatestDp (dps) {
if (_.isEmpty(dps)) {
return null;
}
let times = [];
for (const key of Object.keys(dps)) {
times.push(parseInt(key, 10));
}
import { logger, provide, inject } from 'midway-web';
import { FindOptions } from 'sequelize';
import * as md5 from 'md5';
import { SandboxGroup } from '../../interface/models/group';
import { FindAndCountAllResult, ModelQueryOptions, ScopeInfo } from '../../interface/models/common';
@provide('groupManager')
export class GroupManager {
@logger()
protected logger;
@inject()
protected groupModel;
public async list(condition: FindOptions): Promise> {
return this.groupModel.findAndCount(condition);
}
public async listByApplication(app: ScopeInfo, options?: ModelQueryOptions): Promise> {
this.logger.info(`list groups by application [${app.scopeName}@${app.scope}].`);
const condition: FindOptions = {
attributes: {
import { provide, logger, inject, async } from 'midway-web';
import * as assert from 'assert';
import { ModelQueryOptions, ScopeInfo } from '../../interface/models/common';
import { SandboxApplication } from '../../interface/models/application';
import {IPlatformGroup, IPlatformHost, IPlatformHostResult} from '../../interface/adapter/IPlatformAdapter';
import {AppSelector, ListResult} from '../../interface/services/common';
import { SandboxGroup } from '../../interface/models/group';
import { IApplicationService } from '../../interface/services/IApplicationService';
import { optionsCheck } from '../util/util';
import {ApplicationManager} from '../manager/applicationManager';
import {PlatformManagerAdapter} from '../adapter/platformManagerAdapter';
import {GroupManager} from '../manager/groupManager';
@async()
@provide('applicationService')
export class ApplicationService implements IApplicationService {
@logger()
protected logger;
@inject()
protected applicationManager: ApplicationManager;
@inject()
protected groupManager: GroupManager;
@inject()
protected platformManagerAdapter: PlatformManagerAdapter;
async listByUser(uid: string, options?: ModelQueryOptions): Promise> {
assert(uid, 'uid can\'t be null');
import { logger, provide, inject } from 'midway-web';
import { FindAndCountAllResult, ModelQueryOptions } from '../../interface/models/common';
import { FindOptions } from 'sequelize';
import { KeyTrace } from '../../interface/models/keyTrace';
import * as md5 from 'md5';
@provide('keyTraceManager')
export class KeyTraceManager {
@logger()
logger;
@inject()
dw;
@inject()
protected keyTraceModel;
public async list(condition: FindOptions): Promise> {
return this.keyTraceModel.findAndCount(condition);
}
public async listKeyTraces(query: Partial, options?: ModelQueryOptions): Promise> {
import { provide, inject } from 'midway-web';
import { ComplexSelector, MetricsNamesSelector, IndicatorResult, TimeWindowOptions,
AppSelector } from '../../interface/services/common';
import {TSDB} from '../dataSource/tsdb';
import * as _ from 'lodash';
import {MetricsManager} from '../manager/metricsManager';
import {ApplicationService} from './applicationService';
import {IMetricsService} from '../../interface/services/IMetricsService';
const BUILT_IN_PREFIXS = ['system.', 'node.', 'error.', 'middleware.'];
const BUILD_IN_REG = new RegExp(`^(${BUILT_IN_PREFIXS.join('|')})`);
@provide('metricsService')
export class MetricsService implements IMetricsService {
@inject('tsdb')
protected tsdb: TSDB;
@inject('metricsManager')
protected metricsManager: MetricsManager;
@inject('applicationService')
protected applicationService: ApplicationService;
async getMetricsNames(options: ComplexSelector & AppSelector & TimeWindowOptions): Promise {
return this.metricsManager.getMetricsNames(options);
}
async getCustomMetricsNames(options: ComplexSelector & AppSelector & TimeWindowOptions): Promise {