-
Notifications
You must be signed in to change notification settings - Fork 14
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
Feature flag admin endpoints #1474
Conversation
We also need FILTER_MODE (includeAll, excludeAll) in featureFlags for Segments logic too, as it is also present in Experiments. if we don't want to use FILTER_MODE then we need to discuss how the Segments would work for it. |
@RidhamShah I've created a pr that adds FILTER_MODE to the db. When that's merged we can continue with this one. |
|
||
// saving variations | ||
let variationDocs: FlagVariation[]; | ||
const setSegmentInEx = (inEx: FeatureFlagSegmentExclusion | FeatureFlagSegmentInclusion) => { |
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.
what does inEx
mean? inclusion / exclusion?
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.
Yeah, I'd meant to eventually give that a better name. Good catch
* sortAs: | ||
* type: string | ||
* enum: [ASC, DESC] | ||
* tags: | ||
* - Feature flags | ||
* - Feature Flags |
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.
Line 240 says Experiments instead of Feature Flags
: inEx; | ||
}; | ||
|
||
let includeSegmentExists = true; |
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 asked copilot to pull this out 159-221 into own function without the repetition for the segment include and segment exclude. It needs some help with types but I thought something like this looked pretty reasonable, what do you think?
async function handleSegment(segmentInclusionExclusion: any, flagDoc: any, flag: any, type: string, logger: any) {
let segmentExists = true;
let segmentDoc: Segment;
let segmentDocToSave: Partial<FeatureFlagSegmentInclusion | FeatureFlagSegmentExclusion> = {};
if (segmentInclusionExclusion) {
const segment: any = setSegmentInEx(segmentInclusionExclusion);
const segmentData: SegmentInputValidator = {
...segment,
id: segment.id || uuid(),
name: flagDoc.id + ' ' + type + ' Segment',
description: flagDoc.id + ' ' + type + ' Segment',
context: flagDoc.context[0],
type: SEGMENT_TYPE.PRIVATE,
};
try {
segmentDoc = await this.segmentService.upsertSegment(segmentData, logger);
} catch (err) {
const error = err as ErrorWithType;
error.details = 'Error in adding segment in DB';
error.type = SERVER_ERROR.QUERY_FAILED;
logger.error(error);
throw error;
}
// creating segment doc
const tempDoc = type === 'Inclusion' ? new FeatureFlagSegmentInclusion() : new FeatureFlagSegmentExclusion();
tempDoc.segment = segmentDoc;
tempDoc.featureFlag = flag;
segmentDocToSave = this.getSegmentDoc(tempDoc);
} else {
segmentExists = false;
}
return { segmentExists, segmentDoc, segmentDocToSave };
}
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 think it makes sense to reduce duplication. I'll see what I can do about wrangling the types.
looks good to me, other than whatever's in the merge conflicts |
backend/packages/Upgrade/src/api/controllers/validators/FeatureFlagValidator.ts
Outdated
Show resolved
Hide resolved
backend/packages/Upgrade/src/api/services/FeatureFlagService.ts
Outdated
Show resolved
Hide resolved
hey it works. @VivekFitkariwala let us know if this can be merged, this will be helpful for getting the UI moving. I see some outstanding comments but I think Ben has responded. |
* WIP: Feature flag admin endpoints * update feature flag service tests * review changes * merge dev into feature/feature-flag-admin-api * review changes --------- Co-authored-by: danoswaltCL <[email protected]>
Adds (or updates) the following endpoints:
GET /flags
POST /flags
GET /flags/{id}
DELETE /flags/{id}
PUT /flags/{id}
POST /flags/paginated
POST /flags/status
The request (for POST and PUT) and response bodies for these endpoints can be viewed by looking at the swagger page.