-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Licensing: allow multiple registration of the same feature #76272
Conversation
const registered = this.lastUsages.get(featureName); | ||
if (registered) { | ||
if (registered.licenseType !== licenseType) { | ||
throw new Error( | ||
`Feature '${featureName}' has already been registered with another license type. (current: ${registered.licenseType}, new: ${licenseType})` | ||
); | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@restrry This is the easiest fix for the problem, and answer the need.
Another option would be to instead adapt the client-side service to fetch the list of already registered features from the server-side during setup
and to not perform calls to the server when trying to register an already existing feature. This is just a little trickier if we want to keep the client-side service synchronous
export class FeatureUsageService { | |
public setup({ http }: SetupDeps): FeatureUsageServiceSetup { | |
return { | |
register: async (featureName, licenseType) => { | |
await http.post('/internal/licensing/feature_usage/register', { | |
body: JSON.stringify({ | |
featureName, | |
licenseType, | |
}), | |
}); | |
}, | |
}; | |
} |
as it would mean creating the fetch promise during setup
and await for its result in every call to register. But nothing that can't be done. Do you think this would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the solution you have in PR. It's simpler and less likely to break IMO.
Other option could be to allow multiple |
Yea, that would be another possibility |
💚 Build SucceededBuild metrics
To update your PR or re-run it, just comment with: |
Pinging @elastic/kibana-platform (Team:Platform) |
const registered = this.lastUsages.get(featureName); | ||
if (registered) { | ||
if (registered.licenseType !== licenseType) { | ||
throw new Error( | ||
`Feature '${featureName}' has already been registered with another license type. (current: ${registered.licenseType}, new: ${licenseType})` | ||
); | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the solution you have in PR. It's simpler and less likely to break IMO.
Summary
Adapt the
FeatureUsage
service to accept multiple registrations of the same feature, as long as thelicenseType
is the same.This is driven by the fact that features can now be registered from the client-side, so every refresh or new client can call this API, resulting in multiple calls.
Checklist