Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [ML] Combines ui/time_buckets into MlTimeBuckets (#46227) #46606

Merged
merged 1 commit into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { useKibanaContext, SavedSearchQuery } from '../../contexts/kibana';
import { kbnTypeToMLJobType } from '../../util/field_types_utils';
// @ts-ignore
import { timeBasedIndexCheck } from '../../util/index_utils';
import { MlTimeBuckets } from '../../util/ml_time_buckets';
import { TimeBuckets } from '../../util/time_buckets';
import { FieldRequestConfig, FieldVisConfig } from './common';
import { ActionsPanel } from './components/actions_panel';
import { FieldsPanel } from './components/fields_panel';
Expand Down Expand Up @@ -269,7 +269,7 @@ export const Page: FC = () => {

// Obtain the interval to use for date histogram aggregations
// (such as the document count chart). Aim for 75 bars.
const buckets = new MlTimeBuckets();
const buckets = new TimeBuckets();

const tf = timefilter as any;
let earliest: number | undefined;
Expand Down
14 changes: 7 additions & 7 deletions x-pack/legacy/plugins/ml/public/explorer/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
import { ExplorerSwimlane } from './explorer_swimlane';
import { KqlFilterBar } from '../components/kql_filter_bar';
import { formatHumanReadableDateTime } from '../util/date_utils';
import { getBoundsRoundedToInterval } from 'plugins/ml/util/ml_time_buckets';
import { getBoundsRoundedToInterval } from '../util/time_buckets';
import { getSelectedJobIds } from '../components/job_selector/job_select_service_utils';
import { InfluencersList } from '../components/influencers_list';
import { ALLOW_CELL_RANGE_SELECTION, dragSelect$, explorer$ } from './explorer_dashboard_service';
Expand Down Expand Up @@ -159,7 +159,7 @@ export const Explorer = injectI18n(injectObservablesAsProps(
dateFormatTz: PropTypes.string.isRequired,
globalState: PropTypes.object.isRequired,
jobSelectService: PropTypes.object.isRequired,
MlTimeBuckets: PropTypes.func.isRequired,
TimeBuckets: PropTypes.func.isRequired,
};

state = getExplorerDefaultState();
Expand Down Expand Up @@ -365,13 +365,13 @@ export const Explorer = injectI18n(injectObservablesAsProps(
}

getSwimlaneBucketInterval(selectedJobs) {
const { MlTimeBuckets } = this.props;
const { TimeBuckets } = this.props;

const swimlaneWidth = getSwimlaneContainerWidth(this.state.noInfluencersConfigured);
// Bucketing interval should be the maximum of the chart related interval (i.e. time range related)
// and the max bucket span for the jobs shown in the chart.
const bounds = timefilter.getActiveBounds();
const buckets = new MlTimeBuckets();
const buckets = new TimeBuckets();
buckets.setInterval('auto');
buckets.setBounds(bounds);

Expand Down Expand Up @@ -1074,7 +1074,7 @@ export const Explorer = injectI18n(injectObservablesAsProps(
globalState,
intl,
jobSelectService,
MlTimeBuckets,
TimeBuckets,
} = this.props;

const {
Expand Down Expand Up @@ -1206,7 +1206,7 @@ export const Explorer = injectI18n(injectObservablesAsProps(
chartWidth={swimlaneWidth}
filterActive={filterActive}
maskAll={maskAll}
MlTimeBuckets={MlTimeBuckets}
TimeBuckets={TimeBuckets}
swimlaneCellClick={this.swimlaneCellClick}
swimlaneData={overallSwimlaneData}
swimlaneType={SWIMLANE_TYPE.OVERALL}
Expand Down Expand Up @@ -1282,7 +1282,7 @@ export const Explorer = injectI18n(injectObservablesAsProps(
chartWidth={swimlaneWidth}
filterActive={filterActive}
maskAll={maskAll}
MlTimeBuckets={MlTimeBuckets}
TimeBuckets={TimeBuckets}
swimlaneCellClick={this.swimlaneCellClick}
swimlaneData={viewBySwimlaneData}
swimlaneType={SWIMLANE_TYPE.VIEW_BY}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import {
numTicksForDateFormat,
removeLabelOverlap
} from '../../util/chart_utils';
import { TimeBuckets } from 'ui/time_buckets';
import { LoadingIndicator } from '../../components/loading_indicator/loading_indicator';
import { TimeBuckets } from '../../util/time_buckets';
import { mlEscape } from '../../util/string_utils';
import { mlFieldFormatService } from '../../services/field_format_service';
import { mlChartTooltipService } from '../../components/chart_tooltip/chart_tooltip_service';
Expand Down Expand Up @@ -255,7 +255,7 @@ export const ExplorerChartDistribution = injectI18n(class ExplorerChartDistribut
const xAxisTickFormat = timeBuckets.getScaledDateFormat();

const tickValuesStart = Math.max(config.selectedEarliest, config.plotEarliest);
// +1 ms to account for the ms that was substracted for query aggregations.
// +1 ms to account for the ms that was subtracted for query aggregations.
const interval = config.selectedLatest - config.selectedEarliest + 1;
const tickValues = getTickValues(tickValuesStart, interval, config.plotEarliest, config.plotLatest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import seriesConfig from './__mocks__/mock_series_config_rare.json';

// Mock TimeBuckets and mlFieldFormatService, they don't play well
// with the jest based test setup yet.
jest.mock('ui/time_buckets', () => ({
jest.mock('../../util/time_buckets', () => ({
TimeBuckets: function () {
this.setBounds = jest.fn();
this.setInterval = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import {
showMultiBucketAnomalyMarker,
showMultiBucketAnomalyTooltip,
} from '../../util/chart_utils';
import { TimeBuckets } from 'ui/time_buckets';
import { LoadingIndicator } from '../../components/loading_indicator/loading_indicator';
import { TimeBuckets } from '../../util/time_buckets';
import { mlEscape } from '../../util/string_utils';
import { mlFieldFormatService } from '../../services/field_format_service';
import { mlChartTooltipService } from '../../components/chart_tooltip/chart_tooltip_service';
Expand Down Expand Up @@ -194,7 +194,7 @@ export const ExplorerChartSingleMetric = injectI18n(class ExplorerChartSingleMet
const xAxisTickFormat = timeBuckets.getScaledDateFormat();

const tickValuesStart = Math.max(config.selectedEarliest, config.plotEarliest);
// +1 ms to account for the ms that was substracted for query aggregations.
// +1 ms to account for the ms that was subtracted for query aggregations.
const interval = config.selectedLatest - config.selectedEarliest + 1;
const tickValues = getTickValues(tickValuesStart, interval, config.plotEarliest, config.plotLatest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import seriesConfig from './__mocks__/mock_series_config_filebeat.json';

// Mock TimeBuckets and mlFieldFormatService, they don't play well
// with the jest based test setup yet.
jest.mock('ui/time_buckets', () => ({
jest.mock('../../util/time_buckets', () => ({
TimeBuckets: function () {
this.setBounds = jest.fn();
this.setInterval = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import seriesConfigRare from './__mocks__/mock_series_config_rare.json';

// Mock TimeBuckets and mlFieldFormatService, they don't play well
// with the jest based test setup yet.
jest.mock('ui/time_buckets', () => ({
jest.mock('../../util/time_buckets', () => ({
TimeBuckets: function () {
this.setBounds = jest.fn();
this.setInterval = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getAnomalyExplorerBreadcrumbs } from './breadcrumbs';
import { checkFullLicense } from '../license/check_license';
import { checkGetJobsPrivilege } from '../privilege/check_privilege';
import { getIndexPatterns, loadIndexPatterns } from '../util/index_utils';
import { MlTimeBuckets } from 'plugins/ml/util/ml_time_buckets';
import { TimeBuckets } from 'plugins/ml/util/time_buckets';
import { explorer$ } from './explorer_dashboard_service';
import { mlTimefilterRefresh$ } from '../services/timefilter_refresh_service';
import { mlFieldFormatService } from 'plugins/ml/services/field_format_service';
Expand Down Expand Up @@ -74,7 +74,7 @@ module.controller('MlExplorerController', function (
timefilter.enableTimeRangeSelector();
timefilter.enableAutoRefreshSelector();

$scope.MlTimeBuckets = MlTimeBuckets;
$scope.TimeBuckets = TimeBuckets;

let resizeTimeout = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.directive('mlExplorerReactWrapper', function (config, globalState) {
dateFormatTz,
globalState,
jobSelectService,
MlTimeBuckets: scope.MlTimeBuckets,
TimeBuckets: scope.TimeBuckets,
}}
/>
</I18nContext>,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/ml/public/explorer/explorer_swimlane.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const ExplorerSwimlane = injectI18n(class ExplorerSwimlane extends React.
chartWidth: PropTypes.number.isRequired,
filterActive: PropTypes.bool,
maskAll: PropTypes.bool,
MlTimeBuckets: PropTypes.func.isRequired,
TimeBuckets: PropTypes.func.isRequired,
swimlaneCellClick: PropTypes.func.isRequired,
swimlaneData: PropTypes.shape({
laneLabels: PropTypes.array.isRequired
Expand Down Expand Up @@ -248,7 +248,7 @@ export const ExplorerSwimlane = injectI18n(class ExplorerSwimlane extends React.
chartWidth,
filterActive,
maskAll,
MlTimeBuckets,
TimeBuckets,
swimlaneCellClick,
swimlaneData,
swimlaneType,
Expand Down Expand Up @@ -285,7 +285,7 @@ export const ExplorerSwimlane = injectI18n(class ExplorerSwimlane extends React.
.range([0, xAxisWidth]);

// Get the scaled date format to use for x axis tick labels.
const timeBuckets = new MlTimeBuckets();
const timeBuckets = new TimeBuckets();
timeBuckets.setInterval(`${stepSecs}s`);
const xAxisTickFormat = timeBuckets.getScaledDateFormat();

Expand Down
20 changes: 10 additions & 10 deletions x-pack/legacy/plugins/ml/public/explorer/explorer_swimlane.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ jest.mock('./explorer_dashboard_service', () => ({
}));

function getExplorerSwimlaneMocks() {
const MlTimeBucketsMethods = {
const TimeBucketsMethods = {
setInterval: jest.fn(),
getScaledDateFormat: jest.fn()
};
const MlTimeBuckets = jest.fn(() => MlTimeBucketsMethods);
MlTimeBuckets.mockMethods = MlTimeBucketsMethods;
const TimeBuckets = jest.fn(() => TimeBucketsMethods);
TimeBuckets.mockMethods = TimeBucketsMethods;

const swimlaneData = { laneLabels: [] };

return {
MlTimeBuckets,
TimeBuckets,
swimlaneData
};
}
Expand All @@ -65,7 +65,7 @@ describe('ExplorerSwimlane', () => {

const wrapper = mountWithIntl(<ExplorerSwimlane.WrappedComponent
chartWidth={mockChartWidth}
MlTimeBuckets={mocks.MlTimeBuckets}
TimeBuckets={mocks.TimeBuckets}
swimlaneCellClick={jest.fn()}
swimlaneData={mocks.swimlaneData}
swimlaneType="overall"
Expand All @@ -80,8 +80,8 @@ describe('ExplorerSwimlane', () => {
// test calls to mock functions
expect(dragSelect$.subscribe.mock.calls.length).toBeGreaterThanOrEqual(1);
expect(wrapper.instance().dragSelectSubscriber.unsubscribe.mock.calls).toHaveLength(0);
expect(mocks.MlTimeBuckets.mockMethods.setInterval.mock.calls.length).toBeGreaterThanOrEqual(1);
expect(mocks.MlTimeBuckets.mockMethods.getScaledDateFormat.mock.calls.length).toBeGreaterThanOrEqual(1);
expect(mocks.TimeBuckets.mockMethods.setInterval.mock.calls.length).toBeGreaterThanOrEqual(1);
expect(mocks.TimeBuckets.mockMethods.getScaledDateFormat.mock.calls.length).toBeGreaterThanOrEqual(1);
expect(swimlaneRenderDoneListener.mock.calls.length).toBeGreaterThanOrEqual(1);
});

Expand All @@ -91,7 +91,7 @@ describe('ExplorerSwimlane', () => {

const wrapper = mountWithIntl(<ExplorerSwimlane.WrappedComponent
chartWidth={mockChartWidth}
MlTimeBuckets={mocks.MlTimeBuckets}
TimeBuckets={mocks.TimeBuckets}
swimlaneCellClick={jest.fn()}
swimlaneData={mockOverallSwimlaneData}
swimlaneType="overall"
Expand All @@ -103,8 +103,8 @@ describe('ExplorerSwimlane', () => {
// test calls to mock functions
expect(dragSelect$.subscribe.mock.calls.length).toBeGreaterThanOrEqual(1);
expect(wrapper.instance().dragSelectSubscriber.unsubscribe.mock.calls).toHaveLength(0);
expect(mocks.MlTimeBuckets.mockMethods.setInterval.mock.calls.length).toBeGreaterThanOrEqual(1);
expect(mocks.MlTimeBuckets.mockMethods.getScaledDateFormat.mock.calls.length).toBeGreaterThanOrEqual(1);
expect(mocks.TimeBuckets.mockMethods.setInterval.mock.calls.length).toBeGreaterThanOrEqual(1);
expect(mocks.TimeBuckets.mockMethods.getScaledDateFormat.mock.calls.length).toBeGreaterThanOrEqual(1);
expect(swimlaneRenderDoneListener.mock.calls.length).toBeGreaterThanOrEqual(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import d3 from 'd3';
import angular from 'angular';
import moment from 'moment';

import { TimeBuckets } from 'ui/time_buckets';
import { TimeBuckets } from '../../../../../util/time_buckets';
import { numTicksForDateFormat } from 'plugins/ml/util/chart_utils';

import { uiModules } from 'ui/modules';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// various util functions for populating the chartData object used by the job wizards

import _ from 'lodash';
import { MlTimeBuckets } from 'plugins/ml/util/ml_time_buckets';
import { TimeBuckets } from 'plugins/ml/util/time_buckets';
import { calculateTextWidth } from 'plugins/ml/util/string_utils';
import { mlResultsService } from 'plugins/ml/services/results_service';
import { mlSimpleJobSearchService } from 'plugins/ml/jobs/new_job/simple/components/utils/search_service';
Expand All @@ -24,7 +24,7 @@ export function ChartDataUtilsProvider() {
const MAX_BARS = BAR_TARGET + (BAR_TARGET / 100) * 100; // 100% larger that bar target
const query = formConfig.combinedQuery;
const bounds = timefilter.getActiveBounds();
const buckets = new MlTimeBuckets();
const buckets = new TimeBuckets();
buckets.setBarTarget(BAR_TARGET);
buckets.setMaxBars(MAX_BARS);
buckets.setInterval('auto');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import d3 from 'd3';
import angular from 'angular';
import moment from 'moment';

import { TimeBuckets } from 'ui/time_buckets';
import { TimeBuckets } from '../../../../../util/time_buckets';
import { drawLineChartDots, numTicksForDateFormat } from 'plugins/ml/util/chart_utils';

import { uiModules } from 'ui/modules';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import uiRoutes from 'ui/routes';
import { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
import { checkLicenseExpired } from 'plugins/ml/license/check_license';
import { checkCreateJobsPrivilege } from 'plugins/ml/privilege/check_privilege';
import { MlTimeBuckets } from 'plugins/ml/util/ml_time_buckets';
import { TimeBuckets } from 'plugins/ml/util/time_buckets';
import { getCreateMultiMetricJobBreadcrumbs } from 'plugins/ml/jobs/breadcrumbs';
import { filterAggTypes } from 'plugins/ml/jobs/new_job/simple/components/utils/filter_agg_types';
import { validateJob } from 'plugins/ml/jobs/new_job/simple/components/utils/validate_job';
Expand Down Expand Up @@ -292,7 +292,7 @@ module
}

const bounds = timefilter.getActiveBounds();
$scope.formConfig.chartInterval = new MlTimeBuckets();
$scope.formConfig.chartInterval = new TimeBuckets();
$scope.formConfig.chartInterval.setBarTarget(BAR_TARGET);
$scope.formConfig.chartInterval.setMaxBars(MAX_BARS);
$scope.formConfig.chartInterval.setInterval('auto');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import angular from 'angular';
import moment from 'moment';

import { formatHumanReadableDateTime } from '../../../../../util/date_utils';
import { TimeBuckets } from 'ui/time_buckets';
import { TimeBuckets } from '../../../../../util/time_buckets';
import { numTicksForDateFormat } from '../../../../../util/chart_utils';
import { mlEscape } from '../../../../../util/string_utils';
import { mlChartTooltipService } from '../../../../../components/chart_tooltip/chart_tooltip_service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import angular from 'angular';
import uiRoutes from 'ui/routes';
import { checkLicenseExpired } from 'plugins/ml/license/check_license';
import { checkCreateJobsPrivilege } from 'plugins/ml/privilege/check_privilege';
import { MlTimeBuckets } from 'plugins/ml/util/ml_time_buckets';
import { TimeBuckets } from 'plugins/ml/util/time_buckets';
import { getCreatePopulationJobBreadcrumbs } from 'plugins/ml/jobs/breadcrumbs';
import { filterAggTypes } from 'plugins/ml/jobs/new_job/simple/components/utils/filter_agg_types';
import { validateJob } from 'plugins/ml/jobs/new_job/simple/components/utils/validate_job';
Expand Down Expand Up @@ -302,7 +302,7 @@ module
}

const bounds = timefilter.getActiveBounds();
$scope.formConfig.chartInterval = new MlTimeBuckets();
$scope.formConfig.chartInterval = new TimeBuckets();
$scope.formConfig.chartInterval.setBarTarget(BAR_TARGET);
$scope.formConfig.chartInterval.setMaxBars(MAX_BARS);
$scope.formConfig.chartInterval.setInterval('auto');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import _ from 'lodash';

import { EVENT_RATE_COUNT_FIELD, WIZARD_TYPE } from 'plugins/ml/jobs/new_job/simple/components/constants/general';
import { ML_MEDIAN_PERCENTS } from 'plugins/ml/../common/util/job_utils';
import { MlTimeBuckets } from 'plugins/ml/util/ml_time_buckets';
import { TimeBuckets } from 'plugins/ml/util/time_buckets';
import { mlFieldFormatService } from 'plugins/ml/services/field_format_service';
import { mlJobService } from 'plugins/ml/services/job_service';
import { createJobForSaving } from 'plugins/ml/jobs/new_job/utils/new_job_utils';
Expand Down Expand Up @@ -76,7 +76,7 @@ export function PopulationJobServiceProvider() {
};
});

const searchJson = getSearchJsonFromConfig(formConfig, timefilter, MlTimeBuckets);
const searchJson = getSearchJsonFromConfig(formConfig, timefilter, TimeBuckets);

ml.esSearch(searchJson)
.then((resp) => {
Expand Down Expand Up @@ -313,7 +313,7 @@ export function PopulationJobServiceProvider() {

function getSearchJsonFromConfig(formConfig) {
const bounds = timefilter.getActiveBounds();
const buckets = new MlTimeBuckets();
const buckets = new TimeBuckets();
buckets.setInterval('auto');
buckets.setBounds(bounds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import d3 from 'd3';
import angular from 'angular';
import moment from 'moment';

import { TimeBuckets } from 'ui/time_buckets';
import { TimeBuckets } from '../../../../../util/time_buckets';
import { drawLineChartDots, numTicksForDateFormat } from 'plugins/ml/util/chart_utils';

import { uiModules } from 'ui/modules';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
import { getSafeAggregationName } from 'plugins/ml/../common/util/job_utils';
import { checkLicenseExpired } from 'plugins/ml/license/check_license';
import { checkCreateJobsPrivilege } from 'plugins/ml/privilege/check_privilege';
import { MlTimeBuckets } from 'plugins/ml/util/ml_time_buckets';
import { TimeBuckets } from 'plugins/ml/util/time_buckets';
import { getCreateSingleMetricJobBreadcrumbs } from 'plugins/ml/jobs/breadcrumbs';
import { filterAggTypes } from 'plugins/ml/jobs/new_job/simple/components/utils/filter_agg_types';
import { validateJob } from 'plugins/ml/jobs/new_job/simple/components/utils/validate_job';
Expand Down Expand Up @@ -288,7 +288,7 @@ module
}

const bounds = timefilter.getActiveBounds();
$scope.formConfig.chartInterval = new MlTimeBuckets();
$scope.formConfig.chartInterval = new TimeBuckets();
$scope.formConfig.chartInterval.setBarTarget(BAR_TARGET);
$scope.formConfig.chartInterval.setMaxBars(MAX_BARS);
$scope.formConfig.chartInterval.setInterval('auto');
Expand Down
Loading