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

Remove feature flag #231

Merged
merged 21 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 1 addition & 10 deletions ProcessMessage/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
(({
Expand Down Expand Up @@ -365,7 +363,6 @@ describe("getprocessMessageHandler", () => {

const processMessageHandler = getProcessMessageHandler({
TTL_FOR_USER_NOT_FOUND,
isUserEligibleForNewFeature,
lActivation,
lProfileModel,
lMessageModel,
Expand Down Expand Up @@ -464,7 +461,6 @@ describe("getprocessMessageHandler", () => {

const processMessageHandler = getProcessMessageHandler({
TTL_FOR_USER_NOT_FOUND,
isUserEligibleForNewFeature,
lActivation,
lProfileModel,
lMessageModel,
Expand Down Expand Up @@ -560,7 +556,6 @@ describe("getprocessMessageHandler", () => {
);
const processMessageHandler = getProcessMessageHandler({
TTL_FOR_USER_NOT_FOUND,
isUserEligibleForNewFeature: _ => false,
lActivation,
lProfileModel,
lMessageModel,
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

rejection_reason:
failureReason === "PROFILE_NOT_FOUND"
? RejectionReasonEnum.USER_NOT_FOUND
Expand Down Expand Up @@ -664,7 +660,6 @@ describe("getprocessMessageHandler", () => {
);
const processMessageHandler = getProcessMessageHandler({
TTL_FOR_USER_NOT_FOUND,
isUserEligibleForNewFeature,
lActivation,
lProfileModel,
lMessageModel,
Expand Down Expand Up @@ -750,7 +745,6 @@ describe("getprocessMessageHandler", () => {
);
const processMessageHandler = getProcessMessageHandler({
TTL_FOR_USER_NOT_FOUND,
isUserEligibleForNewFeature,
lActivation,
lProfileModel,
lMessageModel,
Expand Down Expand Up @@ -799,7 +793,6 @@ describe("getprocessMessageHandler", () => {
);
const processMessageHandler = getProcessMessageHandler({
TTL_FOR_USER_NOT_FOUND,
isUserEligibleForNewFeature,
lActivation,
lProfileModel,
lMessageModel,
Expand Down Expand Up @@ -864,7 +857,6 @@ describe("getprocessMessageHandler", () => {
patchMessageMock.mockReturnValueOnce(TE.left({} as CosmosErrors));
const processMessageHandler = getProcessMessageHandler({
TTL_FOR_USER_NOT_FOUND,
isUserEligibleForNewFeature,
lActivation,
lProfileModel,
lMessageModel,
Expand Down Expand Up @@ -897,7 +889,6 @@ describe("getprocessMessageHandler", () => {
);
const processMessageHandler = getProcessMessageHandler({
TTL_FOR_USER_NOT_FOUND,
isUserEligibleForNewFeature,
lActivation,
lProfileModel,
lMessageModel,
Expand Down
201 changes: 85 additions & 116 deletions ProcessMessage/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -374,7 +373,6 @@ type Handler = (c: Context, i: unknown) => Promise<void>;
*/
export const getProcessMessageHandler = ({
TTL_FOR_USER_NOT_FOUND,
isUserEligibleForNewFeature,
lActivation,
lProfileModel,
lMessageModel,
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions ProcessMessage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion __integrations__/environments/env.io-functions-services
Original file line number Diff line number Diff line change
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion utils/__tests__/featureFlag.test.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
2 changes: 1 addition & 1 deletion utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof BetaUsers>;
Expand Down
File renamed without changes.