|  | 
| 5 | 5 |  */ | 
| 6 | 6 | 
 | 
| 7 | 7 | import { i18n } from '@kbn/i18n'; | 
|  | 8 | +import { LicenseType } from '../../licensing/common/types'; | 
| 8 | 9 | import { AlertType } from '../common/alert_types'; | 
|  | 10 | +import { | 
|  | 11 | +  LicensingPluginSetup, | 
|  | 12 | +  LicensingRequestHandlerContext, | 
|  | 13 | +} from '../../licensing/server'; | 
| 9 | 14 | 
 | 
| 10 | 15 | export const APM_FEATURE = { | 
| 11 | 16 |   id: 'apm', | 
| @@ -58,11 +63,43 @@ export const APM_FEATURE = { | 
| 58 | 63 |   }, | 
| 59 | 64 | }; | 
| 60 | 65 | 
 | 
| 61 |  | -export const APM_SERVICE_MAPS_FEATURE_NAME = 'APM service maps'; | 
| 62 |  | -export const APM_SERVICE_MAPS_LICENSE_TYPE = 'platinum'; | 
|  | 66 | +interface Feature { | 
|  | 67 | +  name: string; | 
|  | 68 | +  license: LicenseType; | 
|  | 69 | +} | 
|  | 70 | +type FeatureName = 'serviceMaps' | 'ml' | 'customLinks'; | 
|  | 71 | +export const features: Record<FeatureName, Feature> = { | 
|  | 72 | +  serviceMaps: { | 
|  | 73 | +    name: 'APM service maps', | 
|  | 74 | +    license: 'platinum', | 
|  | 75 | +  }, | 
|  | 76 | +  ml: { | 
|  | 77 | +    name: 'APM machine learning', | 
|  | 78 | +    license: 'platinum', | 
|  | 79 | +  }, | 
|  | 80 | +  customLinks: { | 
|  | 81 | +    name: 'APM custom links', | 
|  | 82 | +    license: 'gold', | 
|  | 83 | +  }, | 
|  | 84 | +}; | 
| 63 | 85 | 
 | 
| 64 |  | -export const APM_ML_FEATURE_NAME = 'APM machine learning'; | 
| 65 |  | -export const APM_ML_LICENSE_TYPE = 'platinum'; | 
|  | 86 | +export function registerFeaturesUsage({ | 
|  | 87 | +  licensingPlugin, | 
|  | 88 | +}: { | 
|  | 89 | +  licensingPlugin: LicensingPluginSetup; | 
|  | 90 | +}) { | 
|  | 91 | +  Object.values(features).forEach(({ name, license }) => { | 
|  | 92 | +    licensingPlugin.featureUsage.register(name, license); | 
|  | 93 | +  }); | 
|  | 94 | +} | 
| 66 | 95 | 
 | 
| 67 |  | -export const APM_CUSTOM_LINKS_FEATURE_NAME = 'APM custom links'; | 
| 68 |  | -export const APM_CUSTOM_LINKS_LICENSE_TYPE = 'gold'; | 
|  | 96 | +export function notifyFeatureUsage({ | 
|  | 97 | +  licensingPlugin, | 
|  | 98 | +  featureName, | 
|  | 99 | +}: { | 
|  | 100 | +  licensingPlugin: LicensingRequestHandlerContext; | 
|  | 101 | +  featureName: FeatureName; | 
|  | 102 | +}) { | 
|  | 103 | +  const feature = features[featureName]; | 
|  | 104 | +  licensingPlugin.featureUsage.notifyUsage(feature.name); | 
|  | 105 | +} | 
0 commit comments