How to use midway-web - 10 common examples

To help you get started, we’ve selected a few midway-web examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github midwayjs / sandbox / packages / sandbox-core / src / app / controller / metricsCtrl.ts View on Github external
@get('/getMetricsNames')
  async getMetricsNames(ctx) {

    const query = ctx.query;
    const {scope, scopeName, env} = query;
    const data = await this.metricsService.getMetricsNames({
      scope, scopeName, env,
    });
    ctx.body = {
      success: true,
      data,
    };

  }

  @get('/getCustomMetricsNames')
  async getCustomMetricsNames(ctx) {

    const query = ctx.query;
    const {scope, scopeName, env} = query;
    const data = await this.metricsService.getCustomMetricsNames({
      scope, scopeName, env,
    });
    ctx.body = {
      success: true,
      data,
    };

  }

  @get('/queryMetricsLatest')
  async queryMetricsLatest(ctx) {
github midwayjs / sandbox / packages / sandbox-core / src / core / manager / traceManager.ts View on Github external
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;
  }
github midwayjs / sandbox / packages / sandbox-core / src / core / manager / traceNodeManager.ts View on Github external
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;
github midwayjs / sandbox / packages / sandbox-core / src / core / service / metricsService.ts View on Github external
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 {
    const allMetricsName = await this.metricsManager.getMetricsNames(options);
    return allMetricsName.filter((name) => !BUILD_IN_REG.test(name));
  }

  async queryMetricsLatest(options: ComplexSelector & MetricsNamesSelector & AppSelector): Promise {
github midwayjs / sandbox / packages / sandbox-core / src / core / service / metricsService.ts View on Github external
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 {
    const allMetricsName = await this.metricsManager.getMetricsNames(options);
    return allMetricsName.filter((name) => !BUILD_IN_REG.test(name));
  }
github midwayjs / sandbox / packages / sandbox-core / src / core / dataSource / base.ts View on Github external
import { init } from 'midway-web';
import { Sequelize } from 'sequelize';
import { Options as SequelizeOptions, Sequelize as SequelizeInstance } from 'sequelize';

export class BaseDataSource {
  protected instance: SequelizeInstance;

  protected config;
  protected logger;
  protected name: string;

  @init()
  async connection() {
    const password = await this.getPassword();
    const options: SequelizeOptions = this.getOptions();
    const database: string = this.config.database;
    const username: string = this.config.username;

    this.instance = new Sequelize(database, username, password, options);

    try {
      await this.instance.authenticate();
      await this.prepare();
    } catch (error) {
      error.message = `[DataSource-${this.name}] connection error:${error.message}`;
      throw error;
    }
  }
github midwayjs / sandbox / packages / sandbox-core / src / core / manager / traceNodeManager.ts View on Github external
@provide('traceNodeManager')
export class TraceNodeManager {

  @inject()
  protected dw;

  @logger()
  protected logger;

  @inject()
  protected traceNodeModel;

  protected instance;

  @init()
  initialize() {
    this.instance = this.dw.instance;
  }

  escape(query: object, fields: string[]): void {
    fields.forEach((field) => {
      if (query[field] !== undefined) {
        query[field] = this.instance.escape(query[field]);
      }
    });
  }

  public async list(condition: FindOptions): Promise> {
    return this.traceNodeModel.findAndCount(condition);
  }
github midwayjs / sandbox / packages / sandbox-core / src / core / dataSource / tsdb.ts View on Github external
@logger()
  public logger;
  defaultQueryOpts = {
    ms: 'true',
  };
  defaultPOSTOpts = {
    msResolution: true,
    showQuery: false,
  };

  protected host: string;
  protected port: string;
  protected prefix: string;

  @init()
  init() {
    this.host = this.config.host;
    this.port = this.config.port;
    this.prefix = 'http://' + this.host + ':' + this.port;
  }

  async suggest(suggestOptions: SuggestOptions) {
    const resp = await this.request('/api/suggest', suggestOptions, {
      method: 'GET',
    });
    return resp.data;
  }

  async query(queryOptions: QueryOptions): Promise {
    const resp = await this.requestPost('/api/query', {
      data: {
github midwayjs / sandbox / packages / sandbox-core / src / core / manager / traceManager.ts View on Github external
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;
  }

  escape(query: object, fields: string[]): void {
    fields.forEach((field) => {
      if (query[field] !== undefined) {
        query[field] = this.instance.escape(query[field]);
      }
    });
  }

  async list(condition: FindOptions): Promise> {
    return this.traceModel.findAndCount(condition);
  }
github midwayjs / sandbox / packages / sandbox-core / src / app / controller / tracingCtrl.ts View on Github external
@get('/traceNodeSummary')
  async traceNodeSummary(ctx) {
    const query = ctx.query;
    const result = await this.traceService.traceNodeSummary(query);
    ctx.body = wrapJson(result);
  }

  @get('/spanTargetList')
  async spanTargetList(ctx) {
    const query = ctx.query;
    const result = await this.traceService.spanTargetList(query);
    ctx.body = wrapJson(result);
  }

  @get('/listNodesByTarget')
  async listNodesByTarget(ctx) {
    const query = ctx.query;
    const result = await this.traceService.listNodesByTarget(query);
    ctx.body = wrapJson(result);
  }

  @get('/spansSummaryTrend')
  async spansSummaryTrend(ctx) {
    const query = ctx.query;
    const result = await this.traceService.spansSummaryTrend(query);
    ctx.body = wrapJson(result);
  }

  @get('/traceFlowHistogram')
  async traceFlowHistogram(ctx) {
    const query = ctx.query;