From 73bff681b8259c3066e28e3f43945d62640626b3 Mon Sep 17 00:00:00 2001 From: Garma <64153597+Garma00@users.noreply.github.com> Date: Wed, 30 Nov 2022 15:34:10 +0100 Subject: [PATCH] Remove feature flag (#231) --- ProcessMessage/__tests__/handler.test.ts | 11 +- ProcessMessage/handler.ts | 201 ++++++++---------- ProcessMessage/index.ts | 9 - .../environments/env.io-functions-services | 1 - utils/__tests__/featureFlag.test.ts | 2 +- utils/config.ts | 2 +- utils/{featureFlags.ts => featureFlag.ts} | 0 7 files changed, 88 insertions(+), 138 deletions(-) rename utils/{featureFlags.ts => featureFlag.ts} (100%) diff --git a/ProcessMessage/__tests__/handler.test.ts b/ProcessMessage/__tests__/handler.test.ts index b8e3e826..180d0205 100644 --- a/ProcessMessage/__tests__/handler.test.ts +++ b/ProcessMessage/__tests__/handler.test.ts @@ -64,10 +64,8 @@ import { ServiceId } from "@pagopa/io-functions-commons/dist/generated/definitio import { RejectedMessageStatusValueEnum } from "@pagopa/io-functions-commons/dist/generated/definitions/RejectedMessageStatusValue"; import { RejectionReasonEnum } from "@pagopa/io-functions-commons/dist/generated/definitions/RejectionReason"; import { CosmosErrors } from "@pagopa/io-functions-commons/dist/src/utils/cosmosdb_model"; -import { Ttl } from "@pagopa/io-functions-commons/dist/src/utils/cosmosdb_model_ttl"; const TTL_FOR_USER_NOT_FOUND = 94670856 as NonNegativeInteger; -const isUserEligibleForNewFeature = (_: FiscalCode) => true; const createContext = (functionName: string = "funcname"): Context => (({ @@ -365,7 +363,6 @@ describe("getprocessMessageHandler", () => { const processMessageHandler = getProcessMessageHandler({ TTL_FOR_USER_NOT_FOUND, - isUserEligibleForNewFeature, lActivation, lProfileModel, lMessageModel, @@ -464,7 +461,6 @@ describe("getprocessMessageHandler", () => { const processMessageHandler = getProcessMessageHandler({ TTL_FOR_USER_NOT_FOUND, - isUserEligibleForNewFeature, lActivation, lProfileModel, lMessageModel, @@ -560,7 +556,6 @@ describe("getprocessMessageHandler", () => { ); const processMessageHandler = getProcessMessageHandler({ TTL_FOR_USER_NOT_FOUND, - isUserEligibleForNewFeature: _ => false, lActivation, lProfileModel, lMessageModel, @@ -591,6 +586,7 @@ describe("getprocessMessageHandler", () => { expect(messageStatusUpdaterParam).toEqual({ status: RejectedMessageStatusValueEnum.REJECTED, + ttl: O.isNone(profileResult) ? 94670856 : undefined, // we want ttl setted only in case the user does not exist rejection_reason: failureReason === "PROFILE_NOT_FOUND" ? RejectionReasonEnum.USER_NOT_FOUND @@ -664,7 +660,6 @@ describe("getprocessMessageHandler", () => { ); const processMessageHandler = getProcessMessageHandler({ TTL_FOR_USER_NOT_FOUND, - isUserEligibleForNewFeature, lActivation, lProfileModel, lMessageModel, @@ -750,7 +745,6 @@ describe("getprocessMessageHandler", () => { ); const processMessageHandler = getProcessMessageHandler({ TTL_FOR_USER_NOT_FOUND, - isUserEligibleForNewFeature, lActivation, lProfileModel, lMessageModel, @@ -799,7 +793,6 @@ describe("getprocessMessageHandler", () => { ); const processMessageHandler = getProcessMessageHandler({ TTL_FOR_USER_NOT_FOUND, - isUserEligibleForNewFeature, lActivation, lProfileModel, lMessageModel, @@ -864,7 +857,6 @@ describe("getprocessMessageHandler", () => { patchMessageMock.mockReturnValueOnce(TE.left({} as CosmosErrors)); const processMessageHandler = getProcessMessageHandler({ TTL_FOR_USER_NOT_FOUND, - isUserEligibleForNewFeature, lActivation, lProfileModel, lMessageModel, @@ -897,7 +889,6 @@ describe("getprocessMessageHandler", () => { ); const processMessageHandler = getProcessMessageHandler({ TTL_FOR_USER_NOT_FOUND, - isUserEligibleForNewFeature, lActivation, lProfileModel, lMessageModel, diff --git a/ProcessMessage/handler.ts b/ProcessMessage/handler.ts index c89d1b09..bc124aa9 100644 --- a/ProcessMessage/handler.ts +++ b/ProcessMessage/handler.ts @@ -353,7 +353,6 @@ const createMessageOrThrow = async ( export interface IProcessMessageHandlerInput { readonly TTL_FOR_USER_NOT_FOUND: Ttl; - readonly isUserEligibleForNewFeature: (fc: FiscalCode) => boolean; readonly lActivation: ActivationModel; readonly lProfileModel: ProfileModel; readonly lMessageModel: MessageModel; @@ -374,7 +373,6 @@ type Handler = (c: Context, i: unknown) => Promise; */ export const getProcessMessageHandler = ({ TTL_FOR_USER_NOT_FOUND, - isUserEligibleForNewFeature, lActivation, lProfileModel, lMessageModel, @@ -425,121 +423,92 @@ export const getProcessMessageHandler = ({ if (O.isNone(maybeProfile)) { // the recipient doesn't have any profile yet - - // if the user is enabled for feature flag we want to execute the new code - if ( - isUserEligibleForNewFeature(newMessageWithoutContent.fiscalCode) - ) { - await pipe( - messageStatusUpdater({ - rejection_reason: RejectionReasonEnum.USER_NOT_FOUND, - status: RejectedMessageStatusValueEnum.REJECTED, - ttl: TTL_FOR_USER_NOT_FOUND - }), - TE.mapLeft((err: CosmosErrors) => { - telemetryClient.trackEvent({ - name: "api.messages.create.create-status-fail", - properties: { - errorAsJson: JSON.stringify(err), - errorKind: "messageStatusUpdater failed", - fiscalCode: toHash(newMessageWithoutContent.fiscalCode), - messageId: newMessageWithoutContent.id, - senderId: newMessageWithoutContent.senderServiceId - }, - tagOverrides: { samplingEnabled: "false" } - }); - context.log.error( - `${logPrefix}|PROFILE_NOT_FOUND|UPSERT_STATUS=REJECTED|ERROR=${JSON.stringify( - err - )}` - ); - throw new Error( - "Error while updating message status to REJECTED|PROFILE_NOT_FOUND" - ); - }), - TE.chain( - flow( - () => - lMessageStatusModel.updateTTLForAllVersions( - [newMessageWithoutContent.id], - TTL_FOR_USER_NOT_FOUND - ), - TE.mapLeft((error: CosmosErrors) => { - telemetryClient.trackEvent({ - name: "api.messages.create.fail-status-ttl-set", - properties: { - errorAsJson: JSON.stringify(error), - errorKind: error.kind, - fiscalCode: toHash( - newMessageWithoutContent.fiscalCode - ), - messageId: newMessageWithoutContent.id, - senderId: newMessageWithoutContent.senderServiceId - }, - tagOverrides: { samplingEnabled: "false" } - }); - return error; - }) - ) - ), - TE.chain(() => - pipe( - lMessageModel.patch( - [ - newMessageWithoutContent.id, - newMessageWithoutContent.fiscalCode - ], - // this cast is needed cause patch does not accept ttl - { ttl: TTL_FOR_USER_NOT_FOUND } as Partial< - MessageWithoutContent - > + await pipe( + messageStatusUpdater({ + rejection_reason: RejectionReasonEnum.USER_NOT_FOUND, + status: RejectedMessageStatusValueEnum.REJECTED, + ttl: TTL_FOR_USER_NOT_FOUND + }), + TE.mapLeft((err: CosmosErrors) => { + telemetryClient.trackEvent({ + name: "api.messages.create.create-status-fail", + properties: { + errorAsJson: JSON.stringify(err), + errorKind: "messageStatusUpdater failed", + fiscalCode: toHash(newMessageWithoutContent.fiscalCode), + messageId: newMessageWithoutContent.id, + senderId: newMessageWithoutContent.senderServiceId + }, + tagOverrides: { samplingEnabled: "false" } + }); + context.log.error( + `${logPrefix}|PROFILE_NOT_FOUND|UPSERT_STATUS=REJECTED|ERROR=${JSON.stringify( + err + )}` + ); + throw new Error( + "Error while updating message status to REJECTED|PROFILE_NOT_FOUND" + ); + }), + TE.chain( + flow( + () => + lMessageStatusModel.updateTTLForAllVersions( + [newMessageWithoutContent.id], + TTL_FOR_USER_NOT_FOUND ), - TE.mapLeft((error: CosmosErrors) => { - telemetryClient.trackEvent({ - name: "api.messages.create.fail-message-ttl-set", - properties: { - errorKind: error.kind, - fiscalCode: toHash( - newMessageWithoutContent.fiscalCode - ), - messageId: newMessageWithoutContent.id, - senderId: newMessageWithoutContent.senderServiceId - }, - tagOverrides: { samplingEnabled: "false" } - }); - return error; - }) - ) - ), - TE.getOrElse(e => { - context.log.error( - `${logPrefix}|PROFILE_NOT_FOUND|UPSERT_STATUS=REJECTED|ERROR=${JSON.stringify( - e - )}` - ); - throw new Error("Error while setting the ttl"); - }) - )(); - // if the user is not enabled for feature flag we just execute the messageStatusUpdater without the ttl - } else { - await pipe( - messageStatusUpdater({ - rejection_reason: RejectionReasonEnum.USER_NOT_FOUND, - status: RejectedMessageStatusValueEnum.REJECTED - }), - // eslint-disable-next-line - TE.getOrElse(e => { - context.log.error( - `${logPrefix}|PROFILE_NOT_FOUND|UPSERT_STATUS=REJECTED|ERROR=${JSON.stringify( - e - )}` - ); - throw new Error( - "Error while updating message status to REJECTED|PROFILE_NOT_FOUND" - ); - }) - )(); - } + TE.mapLeft((error: CosmosErrors) => { + telemetryClient.trackEvent({ + name: "api.messages.create.fail-status-ttl-set", + properties: { + errorAsJson: JSON.stringify(error), + errorKind: error.kind, + fiscalCode: toHash(newMessageWithoutContent.fiscalCode), + messageId: newMessageWithoutContent.id, + senderId: newMessageWithoutContent.senderServiceId + }, + tagOverrides: { samplingEnabled: "false" } + }); + return error; + }) + ) + ), + TE.chain(() => + pipe( + lMessageModel.patch( + [ + newMessageWithoutContent.id, + newMessageWithoutContent.fiscalCode + ], + // this cast is needed cause patch does not accept ttl + { ttl: TTL_FOR_USER_NOT_FOUND } as Partial< + MessageWithoutContent + > + ), + TE.mapLeft((error: CosmosErrors) => { + telemetryClient.trackEvent({ + name: "api.messages.create.fail-message-ttl-set", + properties: { + errorKind: error.kind, + fiscalCode: toHash(newMessageWithoutContent.fiscalCode), + messageId: newMessageWithoutContent.id, + senderId: newMessageWithoutContent.senderServiceId + }, + tagOverrides: { samplingEnabled: "false" } + }); + return error; + }) + ) + ), + TE.getOrElse(e => { + context.log.error( + `${logPrefix}|PROFILE_NOT_FOUND|UPSERT_STATUS=REJECTED|ERROR=${JSON.stringify( + e + )}` + ); + throw new Error("Error while setting the ttl"); + }) + )(); context.log.warn(`${logPrefix}|RESULT=PROFILE_NOT_FOUND`); return; diff --git a/ProcessMessage/index.ts b/ProcessMessage/index.ts index e147d11f..8412c0dd 100644 --- a/ProcessMessage/index.ts +++ b/ProcessMessage/index.ts @@ -22,13 +22,11 @@ import { ACTIVATION_COLLECTION_NAME } from "@pagopa/io-functions-commons/dist/src/models/activation"; import { Second } from "@pagopa/ts-commons/lib/units"; -import { FiscalCode } from "@pagopa/ts-commons/lib/strings"; import { cosmosdbInstance } from "../utils/cosmosdb"; import { getConfigOrThrow } from "../utils/config"; import { initTelemetryClient } from "../utils/appinsights"; import { CommonMessageData } from "../utils/events/message"; import { makeRetrieveExpandedDataFromBlob } from "../utils/with-expanded-input"; -import { getIsUserEligibleForNewFeature } from "../utils/featureFlags"; import { getProcessMessageHandler } from "./handler"; const config = getConfigOrThrow(); @@ -73,16 +71,9 @@ const retrieveProcessingMessageData = makeRetrieveExpandedDataFromBlob( config.PROCESSING_MESSAGE_CONTAINER_NAME ); -const isUserEligibleForNewFeature = getIsUserEligibleForNewFeature( - (fc: FiscalCode) => config.BETA_USERS.includes(fc), - (_: FiscalCode) => false, - config.FEATURE_FLAG -); - const activityFunctionHandler: AzureFunction = getProcessMessageHandler({ TTL_FOR_USER_NOT_FOUND: config.TTL_FOR_USER_NOT_FOUND, isOptInEmailEnabled: config.FF_OPT_IN_EMAIL_ENABLED, - isUserEligibleForNewFeature, lActivation: activationModel, lBlobService: blobServiceForMessageContent, lMessageModel: messageModel, diff --git a/__integrations__/environments/env.io-functions-services b/__integrations__/environments/env.io-functions-services index 3b3e62b5..a323dffc 100644 --- a/__integrations__/environments/env.io-functions-services +++ b/__integrations__/environments/env.io-functions-services @@ -54,7 +54,6 @@ APIM_SUBSCRIPTION_KEY="NonEmptyString" # ---------- TTL_FOR_USER_NOT_FOUND=94670856 -FEATURE_FLAG=ALL MIN_APP_VERSION_WITH_READ_AUTH=${MIN_APP_VERSION_WITH_READ_AUTH} FF_PAYMENT_STATUS_ENABLED=${FF_PAYMENT_STATUS_ENABLED} diff --git a/utils/__tests__/featureFlag.test.ts b/utils/__tests__/featureFlag.test.ts index cc5852bc..f8d4ae12 100644 --- a/utils/__tests__/featureFlag.test.ts +++ b/utils/__tests__/featureFlag.test.ts @@ -1,7 +1,7 @@ import { FeatureFlagEnum, getIsUserEligibleForNewFeature -} from "../featureFlags"; +} from "../featureFlag"; import { FiscalCode } from "@pagopa/ts-commons/lib/strings"; import { aFiscalCode, anotherFiscalCode } from "../../__mocks__/mocks"; diff --git a/utils/config.ts b/utils/config.ts index 42788e7c..9bb6d013 100644 --- a/utils/config.ts +++ b/utils/config.ts @@ -25,7 +25,7 @@ import { } from "@pagopa/ts-commons/lib/numbers"; import { flow, pipe } from "fp-ts/lib/function"; import { CommaSeparatedListOf } from "./comma-separated-list"; -import { FeatureFlag, FeatureFlagEnum } from "./featureFlags"; +import { FeatureFlag, FeatureFlagEnum } from "./featureFlag"; export const BetaUsers = t.readonlyArray(FiscalCode); export type BetaUsers = t.TypeOf; diff --git a/utils/featureFlags.ts b/utils/featureFlag.ts similarity index 100% rename from utils/featureFlags.ts rename to utils/featureFlag.ts