Skip to content

Commit

Permalink
Add "Analyze in ML" buttons (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry350 committed Oct 15, 2019
1 parent ab225d0 commit 8d72d24
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { EuiButton, ButtonColor } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

export const AnalyzeInMlButton: React.FunctionComponent<{
color?: ButtonColor;
fill?: boolean;
href: string;
}> = ({ color = 'primary', fill = true, href }) => {
return (
<EuiButton color={color} fill={fill} href={href}>
<FormattedMessage
id="xpack.infra.logs.analysis.analyzeInMlButtonLabel"
defaultMessage="Analyze in ML"
/>
</EuiButton>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { encode } from 'rison-node';

export type GetMlLink = (partitionId?: string | undefined) => string;

export const getMlLinkFormatter = ({
basePath,
startTime,
endTime,
jobId,
}: {
basePath: string;
startTime: number;
endTime: number;
jobId: string;
}) => (partitionId?: string) => {
const startTimeParam = new Date(startTime).toISOString();
const endTimeParam = new Date(endTime).toISOString();

const _g = encode({
ml: {
jobIds: [jobId],
},
time: {
from: startTimeParam,
to: endTimeParam,
mode: 'absolute',
},
});

const baseLink = `${basePath}/app/ml#/timeseriesexplorer?_g=${_g}`;

if (partitionId) {
const _a = encode({
mlTimeSeriesExplorer: {
entities: { 'event.dataset': partitionId },
},
});
return `${baseLink}&_a=${encodeURIComponent(_a)}`;
} else {
return baseLink;
}
};

0 comments on commit 8d72d24

Please sign in to comment.