Skip to content

Commit

Permalink
WIP continues
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrhodes committed Oct 23, 2019
1 parent c5eb8cc commit b9413b2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
8 changes: 4 additions & 4 deletions x-pack/legacy/plugins/infra/server/routes/ip_to_hostname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ export const initIpToHostName = ({ framework }: InfraBackendLibs) => {
body: ipToHostSchema,
},
},
async (context, req, response) => {
async (context, request, response) => {
try {
const params = {
index: req.body.index_pattern,
index: request.body.index_pattern,
body: {
size: 1,
query: {
match: { 'host.ip': req.body.ip },
match: { 'host.ip': request.body.ip },
},
_source: ['host.name'],
},
};
const { hits } = await callWithRequest<HostDoc>(req, 'search', params);
const { hits } = await callWithRequest<HostDoc>(request, 'search', params);
if (hits.total.value === 0) {
return response.notFound({
body: { message: 'Host with matching IP address not found.' },
Expand Down
58 changes: 31 additions & 27 deletions x-pack/legacy/plugins/infra/server/routes/metrics_explorer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,45 @@
*/

import { boomify } from 'boom';
import { schema } from '@kbn/config-schema';
import { InfraBackendLibs } from '../../lib/infra_types';
import { getGroupings } from './lib/get_groupings';
import { populateSeriesWithTSVBData } from './lib/populate_series_with_tsvb_data';
import { metricsExplorerSchema } from './schema';
import { MetricsExplorerResponse, MetricsExplorerWrappedRequest } from './types';
import { MetricsExplorerResponse, MetricsExplorerRequestBody } from './types';

// NP_TODO: need to replace all of this with real types
const escapeHatch = schema.object({}, { allowUnknowns: true });
type EscapeHatch = typeof escapeHatch;

export const initMetricExplorerRoute = (libs: InfraBackendLibs) => {
const { framework } = libs;
const { callWithRequest } = framework;

// framework.registerRoute<MetricsExplorerWrappedRequest, Promise<MetricsExplorerResponse>>({
// method: 'post',
// path: '/api/infra/metrics_explorer',
// options: {
// validate: {
// payload: metricsExplorerSchema,
// },
// },
// handler: async req => {
// try {
// const search = <Aggregation>(searchOptions: object) =>
// callWithRequest<{}, Aggregation>(req, 'search', searchOptions);
// const options = req.payload;
// // First we get the groupings from a composite aggregation
// const response = await getGroupings(search, options);
framework.router.post<EscapeHatch, EscapeHatch, EscapeHatch>(
{
path: '/api/infra/metrics_explorer',
validate: {
body: escapeHatch,
},
},
async (context, request, response) => {
try {
const search = <Aggregation>(searchOptions: object) =>
callWithRequest<{}, Aggregation>(request, 'search', searchOptions);
const options = request.payload;
// First we get the groupings from a composite aggregation
const groupings = await getGroupings(search, options);

// // Then we take the results and fill in the data from TSVB with the
// // user's custom metrics
// const seriesWithMetrics = await Promise.all(
// response.series.map(populateSeriesWithTSVBData(req, options, framework))
// );
// return { ...response, series: seriesWithMetrics };
// } catch (error) {
// throw boomify(error);
// }
// },
// });
// Then we take the results and fill in the data from TSVB with the
// user's custom metrics
const seriesWithMetrics = await Promise.all(
groupings.series.map(populateSeriesWithTSVBData(request, options, framework))
);
response.ok({ body: { ...response, series: seriesWithMetrics } });
} catch (error) {
throw boomify(error);
}
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface MetricsExplorerMetric {
field?: string | undefined;
}

export interface MetricsExplorerRequest {
export interface MetricsExplorerRequestBody {
timerange: InfraTimerange;
indexPattern: string;
metrics: MetricsExplorerMetric[];
Expand All @@ -37,8 +37,6 @@ export interface MetricsExplorerRequest {
filterQuery?: string;
}

export type MetricsExplorerWrappedRequest = InfraWrappableRequest<MetricsExplorerRequest>;

export interface MetricsExplorerPageInfo {
total: number;
afterKey?: string | null;
Expand Down

0 comments on commit b9413b2

Please sign in to comment.