util.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import partition from 'lodash/partition';
  2. import {PlatformKey, profiling} from 'sentry/data/platformCategories';
  3. import {Project} from 'sentry/types/project';
  4. export const supportedProfilingPlatforms = [
  5. 'android',
  6. 'apple-ios',
  7. 'node',
  8. 'python',
  9. ] as const;
  10. export type SupportedProfilingPlatform = Extract<
  11. typeof profiling[number],
  12. typeof supportedProfilingPlatforms[number]
  13. >;
  14. const platformToDocsPlatform: Record<
  15. typeof profiling[number],
  16. typeof supportedProfilingPlatforms[number]
  17. > = {
  18. android: 'android',
  19. 'apple-ios': 'apple-ios',
  20. node: 'node',
  21. 'node-express': 'node',
  22. 'node-koa': 'node',
  23. 'node-connect': 'node',
  24. python: 'python',
  25. 'python-django': 'python',
  26. 'python-flask': 'python',
  27. 'python-sanic': 'python',
  28. 'python-bottle': 'python',
  29. 'python-pylons': 'python',
  30. 'python-pyramid': 'python',
  31. 'python-tornado': 'python',
  32. };
  33. export function isProfilingSupportedOrProjectHasProfiles(project: Project): boolean {
  34. return !!(
  35. (project.platform && platformToDocsPlatform[project.platform]) ||
  36. // If this project somehow managed to send profiles, then profiling is supported for this project.
  37. // Sometimes and for whatever reason, platform can also not be set on a project so the above check alone would fail
  38. project.hasProfiles
  39. );
  40. }
  41. export const profilingOnboardingDocKeys = [
  42. '0-alert',
  43. '1-install',
  44. '2-configure-performance',
  45. '3-configure-profiling',
  46. '4-upload',
  47. ] as const;
  48. type ProfilingOnboardingDocKeys = typeof profilingOnboardingDocKeys[number];
  49. export const supportedPlatformExpectedDocKeys: Record<
  50. SupportedProfilingPlatform,
  51. ProfilingOnboardingDocKeys[]
  52. > = {
  53. android: ['1-install', '2-configure-performance', '3-configure-profiling', '4-upload'],
  54. 'apple-ios': [
  55. '1-install',
  56. '2-configure-performance',
  57. '3-configure-profiling',
  58. '4-upload',
  59. ],
  60. node: ['0-alert', '1-install', '2-configure-performance', '3-configure-profiling'],
  61. python: ['0-alert', '1-install', '2-configure-performance', '3-configure-profiling'],
  62. };
  63. function makeDocKey(platformId: PlatformKey, key: string) {
  64. return `${platformId}-profiling-onboarding-${key}`;
  65. }
  66. type DocKeyMap = Record<typeof profilingOnboardingDocKeys[number], string>;
  67. export function makeDocKeyMap(platformId: PlatformKey | undefined) {
  68. if (!platformId || !platformToDocsPlatform[platformId]) {
  69. return null;
  70. }
  71. const docsPlatform = platformToDocsPlatform[platformId];
  72. const expectedDocKeys: ProfilingOnboardingDocKeys[] =
  73. supportedPlatformExpectedDocKeys[docsPlatform];
  74. return expectedDocKeys.reduce((acc: DocKeyMap, key) => {
  75. acc[key] = makeDocKey(docsPlatform, key);
  76. return acc;
  77. }, {} as DocKeyMap);
  78. }
  79. export function splitProjectsByProfilingSupport(projects: Project[]): {
  80. supported: Project[];
  81. unsupported: Project[];
  82. } {
  83. const [supported, unsupported] = partition(
  84. projects,
  85. project => project.platform && platformToDocsPlatform[project.platform]
  86. );
  87. return {supported, unsupported};
  88. }