projectDataForwarding.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import {Fragment} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import Feature from 'sentry/components/acl/feature';
  4. import FeatureDisabled from 'sentry/components/acl/featureDisabled';
  5. import {Alert} from 'sentry/components/alert';
  6. import AsyncComponent from 'sentry/components/asyncComponent';
  7. import MiniBarChart from 'sentry/components/charts/miniBarChart';
  8. import EmptyMessage from 'sentry/components/emptyMessage';
  9. import ExternalLink from 'sentry/components/links/externalLink';
  10. import {Panel, PanelBody, PanelHeader} from 'sentry/components/panels';
  11. import PluginList from 'sentry/components/pluginList';
  12. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  13. import {t, tct} from 'sentry/locale';
  14. import {Organization, Plugin, Project, TimeseriesValue} from 'sentry/types';
  15. import {Series} from 'sentry/types/echarts';
  16. import withOrganization from 'sentry/utils/withOrganization';
  17. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  18. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  19. import PermissionAlert from 'sentry/views/settings/project/permissionAlert';
  20. type StatProps = {
  21. params: {
  22. orgId: string;
  23. projectId: string;
  24. };
  25. };
  26. type StatState = AsyncComponent['state'] & {
  27. stats: TimeseriesValue[];
  28. };
  29. class DataForwardingStats extends AsyncComponent<StatProps, StatState> {
  30. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  31. const {orgId, projectId} = this.props.params;
  32. const until = Math.floor(new Date().getTime() / 1000);
  33. const since = until - 3600 * 24 * 30;
  34. const options = {
  35. query: {
  36. since,
  37. until,
  38. resolution: '1d',
  39. stat: 'forwarded',
  40. },
  41. };
  42. return [['stats', `/projects/${orgId}/${projectId}/stats/`, options]];
  43. }
  44. renderBody() {
  45. const {projectId} = this.props.params;
  46. const {stats} = this.state;
  47. const series: Series = {
  48. seriesName: t('Forwarded'),
  49. data: stats.map(([timestamp, value]) => ({name: timestamp * 1000, value})),
  50. };
  51. const forwardedAny = series.data.some(({value}) => value > 0);
  52. return (
  53. <Panel>
  54. <SentryDocumentTitle title={t('Data Forwarding')} projectSlug={projectId} />
  55. <PanelHeader>{t('Forwarded events in the last 30 days (by day)')}</PanelHeader>
  56. <PanelBody withPadding>
  57. {forwardedAny ? (
  58. <MiniBarChart
  59. isGroupedByDate
  60. showTimeInTooltip
  61. labelYAxisExtents
  62. series={[series]}
  63. height={150}
  64. />
  65. ) : (
  66. <EmptyMessage
  67. title={t('Nothing forwarded in the last 30 days.')}
  68. description={t('Total events forwarded to third party integrations.')}
  69. />
  70. )}
  71. </PanelBody>
  72. </Panel>
  73. );
  74. }
  75. }
  76. type Props = RouteComponentProps<{projectId: string}, {}> & {
  77. organization: Organization;
  78. project: Project;
  79. };
  80. type State = AsyncComponent['state'] & {
  81. plugins: Plugin[];
  82. };
  83. class ProjectDataForwarding extends AsyncComponent<Props, State> {
  84. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  85. const {organization} = this.props;
  86. const {projectId} = this.props.params;
  87. return [['plugins', `/projects/${organization.slug}/${projectId}/plugins/`]];
  88. }
  89. get forwardingPlugins() {
  90. return this.state.plugins.filter(
  91. p => p.type === 'data-forwarding' && p.hasConfiguration
  92. );
  93. }
  94. updatePlugin(plugin: Plugin, enabled: boolean) {
  95. const plugins = this.state.plugins.map(p => ({
  96. ...p,
  97. enabled: p.id === plugin.id ? enabled : p.enabled,
  98. }));
  99. this.setState({plugins});
  100. }
  101. onEnablePlugin = (plugin: Plugin) => this.updatePlugin(plugin, true);
  102. onDisablePlugin = (plugin: Plugin) => this.updatePlugin(plugin, false);
  103. renderBody() {
  104. const {organization, project} = this.props;
  105. const plugins = this.forwardingPlugins;
  106. const hasAccess = organization.access.includes('project:write');
  107. const params = {...this.props.params, orgId: organization.slug};
  108. const pluginsPanel =
  109. plugins.length > 0 ? (
  110. <PluginList
  111. organization={organization}
  112. project={project}
  113. pluginList={plugins}
  114. onEnablePlugin={this.onEnablePlugin}
  115. onDisablePlugin={this.onDisablePlugin}
  116. />
  117. ) : (
  118. <Panel>
  119. <EmptyMessage
  120. title={t('There are no integrations available for data forwarding')}
  121. />
  122. </Panel>
  123. );
  124. return (
  125. <div data-test-id="data-forwarding-settings">
  126. <Feature
  127. features={['projects:data-forwarding']}
  128. hookName="feature-disabled:data-forwarding"
  129. >
  130. {({hasFeature, features}) => (
  131. <Fragment>
  132. <SettingsPageHeader title={t('Data Forwarding')} />
  133. <TextBlock>
  134. {tct(
  135. `Data Forwarding allows processed events to be sent to your
  136. favorite business intelligence tools. The exact payload and
  137. types of data depend on the integration you're using. Learn
  138. more about this functionality in our [link:documentation].`,
  139. {
  140. link: (
  141. <ExternalLink href="https://docs.sentry.io/product/data-management-settings/data-forwarding/" />
  142. ),
  143. }
  144. )}
  145. </TextBlock>
  146. <PermissionAlert />
  147. <Alert showIcon>
  148. {tct(
  149. `Sentry forwards [em:all applicable error events] to the provider, in
  150. some cases this may be a significant volume of data.`,
  151. {
  152. em: <strong />,
  153. }
  154. )}
  155. </Alert>
  156. {!hasFeature && (
  157. <FeatureDisabled
  158. alert
  159. featureName={t('Data Forwarding')}
  160. features={features}
  161. />
  162. )}
  163. <DataForwardingStats params={params} />
  164. {hasAccess && hasFeature && pluginsPanel}
  165. </Fragment>
  166. )}
  167. </Feature>
  168. </div>
  169. );
  170. }
  171. }
  172. export default withOrganization(ProjectDataForwarding);