|
@@ -3,11 +3,12 @@ import isEqual from 'lodash/isEqual';
|
|
|
import omitBy from 'lodash/omitBy';
|
|
|
|
|
|
import {addErrorMessage} from 'sentry/actionCreators/indicator';
|
|
|
+import {doMetricsRequest, DoMetricsRequestOptions} from 'sentry/actionCreators/metrics';
|
|
|
import {Client, ResponseMeta} from 'sentry/api';
|
|
|
-import {getInterval, shouldFetchPreviousPeriod} from 'sentry/components/charts/utils';
|
|
|
+import {shouldFetchPreviousPeriod} from 'sentry/components/charts/utils';
|
|
|
import {DEFAULT_STATS_PERIOD} from 'sentry/constants';
|
|
|
import {t} from 'sentry/locale';
|
|
|
-import {DateString, MetricsApiResponse, Organization} from 'sentry/types';
|
|
|
+import {MetricsApiResponse} from 'sentry/types';
|
|
|
import {getPeriod} from 'sentry/utils/getPeriod';
|
|
|
|
|
|
import {TableData} from '../discover/discoverQuery';
|
|
@@ -35,31 +36,25 @@ type DefaultProps = {
|
|
|
* Include data for previous period
|
|
|
*/
|
|
|
includePrevious: boolean;
|
|
|
-};
|
|
|
-
|
|
|
-type Props = DefaultProps & {
|
|
|
- api: Client;
|
|
|
- field: string[];
|
|
|
- orgSlug: Organization['slug'];
|
|
|
- children?: (renderProps: MetricsRequestRenderProps) => React.ReactNode;
|
|
|
- cursor?: string;
|
|
|
- end?: DateString;
|
|
|
- environment?: Readonly<string[]>;
|
|
|
- groupBy?: string[];
|
|
|
/**
|
|
|
* Transform the response data to be something ingestible by GridEditable tables
|
|
|
*/
|
|
|
includeTabularData?: boolean;
|
|
|
- interval?: string;
|
|
|
+ /**
|
|
|
+ * If true, no request will be made
|
|
|
+ */
|
|
|
isDisabled?: boolean;
|
|
|
- limit?: number;
|
|
|
- orderBy?: string;
|
|
|
- project?: Readonly<number[]>;
|
|
|
- query?: string;
|
|
|
- start?: DateString;
|
|
|
- statsPeriod?: string | null;
|
|
|
};
|
|
|
|
|
|
+type Props = DefaultProps &
|
|
|
+ Omit<
|
|
|
+ DoMetricsRequestOptions,
|
|
|
+ 'includeAllArgs' | 'statsPeriodStart' | 'statsPeriodEnd'
|
|
|
+ > & {
|
|
|
+ api: Client;
|
|
|
+ children?: (renderProps: MetricsRequestRenderProps) => React.ReactNode;
|
|
|
+ };
|
|
|
+
|
|
|
type State = {
|
|
|
error: string | null;
|
|
|
errored: boolean;
|
|
@@ -72,6 +67,8 @@ type State = {
|
|
|
class MetricsRequest extends React.Component<Props, State> {
|
|
|
static defaultProps: DefaultProps = {
|
|
|
includePrevious: false,
|
|
|
+ includeTabularData: false,
|
|
|
+ isDisabled: false,
|
|
|
};
|
|
|
|
|
|
state: State = {
|
|
@@ -101,13 +98,7 @@ class MetricsRequest extends React.Component<Props, State> {
|
|
|
|
|
|
private unmounting: boolean = false;
|
|
|
|
|
|
- get path() {
|
|
|
- const {orgSlug} = this.props;
|
|
|
-
|
|
|
- return `/organizations/${orgSlug}/metrics/data/`;
|
|
|
- }
|
|
|
-
|
|
|
- baseQueryParams({previousPeriod = false} = {}) {
|
|
|
+ getQueryParams({previousPeriod = false} = {}) {
|
|
|
const {
|
|
|
project,
|
|
|
environment,
|
|
@@ -118,24 +109,23 @@ class MetricsRequest extends React.Component<Props, State> {
|
|
|
limit,
|
|
|
interval,
|
|
|
cursor,
|
|
|
+ statsPeriod,
|
|
|
+ start,
|
|
|
+ end,
|
|
|
+ orgSlug,
|
|
|
} = this.props;
|
|
|
|
|
|
- const {start, end, statsPeriod} = getPeriod({
|
|
|
- period: this.props.statsPeriod,
|
|
|
- start: this.props.start,
|
|
|
- end: this.props.end,
|
|
|
- });
|
|
|
-
|
|
|
const commonQuery = {
|
|
|
- project,
|
|
|
- environment,
|
|
|
field,
|
|
|
- query: query || undefined,
|
|
|
+ cursor,
|
|
|
+ environment,
|
|
|
groupBy,
|
|
|
+ interval,
|
|
|
+ query,
|
|
|
+ limit,
|
|
|
+ project,
|
|
|
orderBy,
|
|
|
- per_page: limit,
|
|
|
- cursor,
|
|
|
- interval: interval ? interval : getInterval({start, end, period: statsPeriod}),
|
|
|
+ orgSlug,
|
|
|
};
|
|
|
|
|
|
if (!previousPeriod) {
|
|
@@ -174,18 +164,12 @@ class MetricsRequest extends React.Component<Props, State> {
|
|
|
}));
|
|
|
|
|
|
const promises = [
|
|
|
- api.requestPromise(this.path, {
|
|
|
- includeAllArgs: true,
|
|
|
- query: this.baseQueryParams(),
|
|
|
- }),
|
|
|
+ doMetricsRequest(api, {includeAllArgs: true, ...this.getQueryParams()}),
|
|
|
];
|
|
|
|
|
|
+ // TODO(metrics): this could be merged into one request by doubling the statsPeriod and then splitting the response in half
|
|
|
if (shouldFetchPreviousPeriod({start, end, period: statsPeriod, includePrevious})) {
|
|
|
- promises.push(
|
|
|
- api.requestPromise(this.path, {
|
|
|
- query: this.baseQueryParams({previousPeriod: true}),
|
|
|
- })
|
|
|
- );
|
|
|
+ promises.push(doMetricsRequest(api, this.getQueryParams({previousPeriod: true})));
|
|
|
}
|
|
|
|
|
|
try {
|