.map(data => _.get(data, 'earnings'))
export const getView = (state: AppState, id: string): View => { return get(state, `views.views.${id}.view`) }
addFunctionParameter(func, value) { if (func.params.length >= func.def.params.length && !_.get(_.last(func.def.params), 'multiple', false)) { throw { message: 'too many parameters for function ' + func.def.name }; } func.params.push(value); }
return (doc: SavedObjectDoc) => _.set(doc, path, _.isFunction(value) ? value(_.get(doc, path)) : value) as SavedObjectDoc;
objPaths.forEach(path => { const id = get(this, path); if (id) { ids.push(id._id || id); } });
circular.forEach(c => { const ref = _.get(json, c.circuralTargetPath) _.set(json, c.pathToObj, ref) })
const addFilter = (state: LogsState, action: AddFilterAction): LogsState => { const {filter} = action.payload return {...state, filters: [filter, ..._.get(state, 'filters', [])]} }
/** * Fetches data used to populate monitor charts * @param request Kibana request * @param monitorId ID value for the selected monitor * @param dateRangeStart timestamp bounds * @param dateRangeEnd timestamp bounds */ public async getMonitorChartsData( request: any, monitorId: string, dateRangeStart: string, dateRangeEnd: string ): Promise<MonitorChart> { const params = { index: INDEX_NAMES.HEARTBEAT, body: { query: { bool: { filter: [ { range: { '@timestamp': { gte: dateRangeStart, lte: dateRangeEnd } } }, { term: { 'monitor.id': monitorId } }, ], }, }, size: 0, aggs: { timeseries: { auto_date_histogram: { field: '@timestamp', buckets: 25, }, aggs: { status: { terms: { field: 'monitor.status', size: 2, shard_size: 2 } }, duration: { stats: { field: 'monitor.duration.us' } }, }, }, }, }, }; const result = await this.database.search(request, params); const buckets = dropLatestBucket(get(result, 'aggregations.timeseries.buckets', [])); /** * The code below is responsible for formatting the aggregation data we fetched above in a way * that the chart components used by the client understands. * There are five required values. Two are lists of points that conform to a simple (x,y) structure. * * The third list is for an area chart expressing a range, and it requires an (x,y,y0) structure, * where y0 is the min value for the point and y is the max. * * Additionally, we supply the maximum value for duration and status, so the corresponding charts know * what the domain size should be. */ const monitorChartsData: MonitorChart = { durationArea: [], durationLine: [], status: [], durationMaxValue: 0, statusMaxCount: 0, }; buckets.forEach(bucket => { const x = get(bucket, 'key'); const docCount = get(bucket, 'doc_count', 0); // update the maximum value for each point monitorChartsData.statusMaxCount = Math.max(docCount, monitorChartsData.statusMaxCount); monitorChartsData.durationMaxValue = Math.max( monitorChartsData.durationMaxValue, get(bucket, 'duration.max', 0) ); // these points express a range that will be displayed as an area chart monitorChartsData.durationArea.push({ x, yMin: get(bucket, 'duration.min', null), yMax: get(bucket, 'duration.max', null), }); monitorChartsData.durationLine.push({ x, y: get(bucket, 'duration.avg', null) }); monitorChartsData.status.push( formatStatusBuckets(x, get(bucket, 'status.buckets', []), docCount) ); }); return monitorChartsData; }
$("[style]").each((idx, elem) => { const root = parse(_.get(elem.attribs, "style")); const styles = pickDeclToStyleObject(root.nodes as Declaration[]); appendStyleProps(elem, styles); });
/** * Fetch options for the filter bar. * @param request Kibana request object * @param dateRangeStart timestamp bounds * @param dateRangeEnd timestamp bounds */ public async getFilterBar( request: any, dateRangeStart: string, dateRangeEnd: string ): Promise<FilterBar> { const params = { index: INDEX_NAMES.HEARTBEAT, body: { _source: ['monitor.id', 'monitor.type', 'url.full', 'url.port', 'monitor.name'], size: 1000, query: { range: { '@timestamp': { gte: dateRangeStart, lte: dateRangeEnd, }, }, }, collapse: { field: 'monitor.id', }, sort: { '@timestamp': 'desc', }, }, }; const result = await this.database.search(request, params); const ids: MonitorKey[] = []; const ports = new Set<number>(); const types = new Set<string>(); const names = new Set<string>(); const hits = get(result, 'hits.hits', []); hits.forEach((hit: any) => { const key: string = get(hit, '_source.monitor.id'); const url: string | null = get(hit, '_source.url.full', null); const port: number | undefined = get(hit, '_source.url.port', undefined); const type: string | undefined = get(hit, '_source.monitor.type', undefined); const name: string | null = get(hit, '_source.monitor.name', null); if (key) { ids.push({ key, url }); } if (port) { ports.add(port); } if (type) { types.add(type); } if (name) { names.add(name); } }); return { ids, ports: Array.from(ports), schemes: Array.from(types), names: Array.from(names), statuses: ['up', 'down'], }; }