Skip to content
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

[Gitar] Cleaning up stale flag: integrationEvents with value true #7940

Merged
merged 6 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import { IntegrationDelete } from './IntegrationDelete/IntegrationDelete';
import { IntegrationStateSwitch } from './IntegrationStateSwitch/IntegrationStateSwitch';
import { capitalizeFirst } from 'utils/capitalizeFirst';
import { IntegrationHowToSection } from '../IntegrationHowToSection/IntegrationHowToSection';
import { useUiFlag } from 'hooks/useUiFlag';
import { IntegrationEventsModal } from '../IntegrationEvents/IntegrationEventsModal';
import AccessContext from 'contexts/AccessContext';

Expand Down Expand Up @@ -116,7 +115,6 @@ export const IntegrationForm: VFC<IntegrationFormProps> = ({
});
const [eventsModalOpen, setEventsModalOpen] = useState(false);
const { isAdmin } = useContext(AccessContext);
const integrationEventsEnabled = useUiFlag('integrationEvents');

const submitText = editMode ? 'Update' : 'Create';
const url = `${uiConfig.unleashUrl}/api/admin/addons${
Expand Down Expand Up @@ -318,7 +316,7 @@ export const IntegrationForm: VFC<IntegrationFormProps> = ({
integration
</StyledHeaderTitle>
<ConditionallyRender
condition={editMode && isAdmin && integrationEventsEnabled}
condition={editMode && isAdmin}
show={
<Link onClick={() => setEventsModalOpen(true)}>
View events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import useAddons from 'hooks/api/getters/useAddons/useAddons';
import useToast from 'hooks/useToast';
import { formatUnknownError } from 'utils/formatUnknownError';
import { Dialogue } from 'component/common/Dialogue/Dialogue';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { useUiFlag } from 'hooks/useUiFlag';
import Visibility from '@mui/icons-material/Visibility';
import { PermissionHOC } from 'component/common/PermissionHOC/PermissionHOC';
import { IntegrationEventsModal } from 'component/integrations/IntegrationEvents/IntegrationEventsModal';
Expand Down Expand Up @@ -55,7 +53,6 @@ export const IntegrationCardMenu: VFC<IIntegrationCardMenuProps> = ({
const { refetchAddons } = useAddons();
const { setToastData, setToastApiError } = useToast();
const [eventsModalOpen, setEventsModalOpen] = useState(false);
const integrationEventsEnabled = useUiFlag('integrationEvents');

const closeMenu = () => {
setIsMenuOpen(false);
Expand Down Expand Up @@ -131,24 +128,19 @@ export const IntegrationCardMenu: VFC<IIntegrationCardMenuProps> = ({
}}
onClose={handleMenuClick}
>
<ConditionallyRender
condition={integrationEventsEnabled}
show={
<PermissionHOC permission={ADMIN}>
{({ hasAccess }) => (
<MenuItem
onClick={() => setEventsModalOpen(true)}
disabled={!hasAccess}
>
<ListItemIcon>
<Visibility />
</ListItemIcon>
<ListItemText>View events</ListItemText>
</MenuItem>
)}
</PermissionHOC>
}
/>
<PermissionHOC permission={ADMIN}>
{({ hasAccess }) => (
<MenuItem
onClick={() => setEventsModalOpen(true)}
disabled={!hasAccess}
>
<ListItemIcon>
<Visibility />
</ListItemIcon>
<ListItemText>View events</ListItemText>
</MenuItem>
)}
</PermissionHOC>
<MenuItem
onClick={() => {
setIsToggleOpen(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import useSWRInfinite, {
} from 'swr/infinite';
import { formatApiPath } from 'utils/formatPath';
import type { IntegrationEvents } from 'interfaces/integrationEvent';
import { useUiFlag } from 'hooks/useUiFlag';
import AccessContext from 'contexts/AccessContext';
import handleErrorResponses from '../httpErrorResponseHandler';

Expand All @@ -21,15 +20,13 @@ export const useIntegrationEvents = (
options: SWRInfiniteConfiguration = {},
) => {
const { isAdmin } = useContext(AccessContext);
const integrationEventsEnabled = useUiFlag('integrationEvents');

const getKey: SWRInfiniteKeyLoader = (
pageIndex: number,
previousPageData: IntegrationEvents,
) => {
// Does not meet conditions
if (!integrationId || !isAdmin || !integrationEventsEnabled)
return null;
if (!integrationId || !isAdmin) return null;

// Reached the end
if (previousPageData && !previousPageData.integrationEvents.length)
Expand Down
1 change: 0 additions & 1 deletion frontend/src/interfaces/uiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export type UiFlags = {
flagCreator?: boolean;
resourceLimits?: boolean;
insightsV2?: boolean;
integrationEvents?: boolean;
newEventSearch?: boolean;
archiveProjects?: boolean;
projectListImprovements?: boolean;
Expand Down
1 change: 0 additions & 1 deletion src/lib/__snapshots__/create-config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ exports[`should create default config 1`] = `
"filterInvalidClientMetrics": false,
"googleAuthEnabled": false,
"insightsV2": false,
"integrationEvents": false,
"killInsightsUI": false,
"killScheduledChangeRequestCache": false,
"maintenanceMode": false,
Expand Down
4 changes: 1 addition & 3 deletions src/lib/addons/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ export default abstract class Addon {
async registerEvent(
integrationEvent: IntegrationEventWriteModel,
): Promise<void> {
if (this.flagResolver.isEnabled('integrationEvents')) {
await this.integrationEventsService.registerEvent(integrationEvent);
}
await this.integrationEventsService.registerEvent(integrationEvent);
}

destroy?(): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export class IntegrationEventsService {
}

async cleanUpEvents(): Promise<void> {
if (!this.flagResolver.isEnabled('integrationEvents')) return;

await this.integrationEventsStore.cleanUpEvents();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ beforeAll(async () => {
db.stores,
{
experimental: {
flags: {
integrationEvents: true,
},
flags: {},
},
},
db.rawDatabase,
Expand Down
10 changes: 1 addition & 9 deletions src/lib/openapi/spec/integration-events-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@ export const integrationEventsSchema = {
type: 'object',
additionalProperties: false,
required: ['integrationEvents'],
properties: {
integrationEvents: {
type: 'array',
description: 'A list of integration events.',
items: {
$ref: integrationEventSchema.$id,
},
},
},
properties: {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm this doesn't seem right if we're keeping the feature and just removing the feature flag

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is because the did a grep for integrationEvents without considering whether something is a string or a "name".

Copy link

@rajbarik rajbarik Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not do "grep" to transform the code. There are scenarios where it is OK to delete this entry, e.g.,

flags: {
            integrationEvents: true,
        },

We need to discuss and agree on when it is safe to delete and when it is not. @sjaanus

components: {
schemas: {
integrationEventSchema,
Expand Down
21 changes: 2 additions & 19 deletions src/lib/routes/admin-api/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
type IntegrationEventsSchema,
integrationEventsSchema,
} from '../../openapi/spec/integration-events-schema';
import { BadDataError, NotFoundError } from '../../error';
import { BadDataError } from '../../error';
import type { IntegrationEventsService } from '../../services';

type AddonServices = Pick<
Expand Down Expand Up @@ -276,10 +276,6 @@ Note: passing \`null\` as a value for the description property will set it to an
>,
res: Response<IntegrationEventsSchema>,
): Promise<void> {
if (!this.flagResolver.isEnabled('integrationEvents')) {
throw new NotFoundError('This feature is not enabled');
}

const { id } = req.params;

if (Number.isNaN(Number(id))) {
Expand All @@ -288,24 +284,11 @@ Note: passing \`null\` as a value for the description property will set it to an

const { limit = '50', offset = '0' } = req.query;

const normalizedLimit =
Number(limit) > 0 && Number(limit) <= 100 ? Number(limit) : 50;
const normalizedOffset = Number(offset) > 0 ? Number(offset) : 0;

const integrationEvents =
await this.integrationEventsService.getPaginatedEvents(
id,
normalizedLimit,
normalizedOffset,
);

this.openApiService.respondWithValidation(
200,
res,
integrationEventsSchema.$id,
{
integrationEvents: serializeDates(integrationEvents),
},
{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a little weird, we're keeping the feature

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as the other one, I guess. It just looks for integrationEvents, thinks "oh, I can delete that" and then also cleans up where it's used. We should see if we can fix that somehow.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment above!

);
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/lib/types/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export type IFlagKey =
| 'extendedMetrics'
| 'removeUnsafeInlineStyleSrc'
| 'insightsV2'
| 'integrationEvents'
| 'originMiddleware'
| 'newEventSearch'
| 'archiveProjects'
Expand Down Expand Up @@ -296,10 +295,6 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_INSIGHTS_V2,
false,
),
integrationEvents: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_INTEGRATION_EVENTS,
false,
),
originMiddleware: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_ORIGIN_MIDDLEWARE,
false,
Expand Down
1 change: 0 additions & 1 deletion src/server-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ process.nextTick(async () => {
resourceLimits: true,
extendedMetrics: true,
insightsV2: true,
integrationEvents: true,
originMiddleware: true,
newEventSearch: true,
projectListImprovements: true,
Expand Down
Loading