index.tsx 6.4 KB

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