index.tsx 6.3 KB

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