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

[DO NOT MERGE] WPB-10517 check if user level feature flag setting is used at all in production #4219

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ packages:
, tools/db/migrate-sso-feature-flag/
, tools/db/move-team/
, tools/db/phone-users/
, tools/db/conference-feature/
, tools/db/repair-handles/
, tools/db/repair-brig-clients-table/
, tools/db/service-backfill/
Expand Down
1 change: 1 addition & 0 deletions nix/local-haskell-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
spar = hself.callPackage ../services/spar/default.nix { inherit gitignoreSource; };
assets = hself.callPackage ../tools/db/assets/default.nix { inherit gitignoreSource; };
auto-whitelist = hself.callPackage ../tools/db/auto-whitelist/default.nix { inherit gitignoreSource; };
conference-feature = hself.callPackage ../tools/db/conference-feature/default.nix { inherit gitignoreSource; };
find-undead = hself.callPackage ../tools/db/find-undead/default.nix { inherit gitignoreSource; };
inconsistencies = hself.callPackage ../tools/db/inconsistencies/default.nix { inherit gitignoreSource; };
migrate-sso-feature-flag = hself.callPackage ../tools/db/migrate-sso-feature-flag/default.nix { inherit gitignoreSource; };
Expand Down
1 change: 1 addition & 0 deletions nix/wire-server.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ let
integration = [ "integration" ];
rabbitmq-consumer = [ "rabbitmq-consumer" ];
test-stats = [ "test-stats" ];
conference-feature = [ "conference-feature" ];
};

inherit (lib) attrsets;
Expand Down
1 change: 1 addition & 0 deletions tools/db/conference-feature/.ormolu
23 changes: 23 additions & 0 deletions tools/db/conference-feature/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2024 Wire Swiss GmbH <[email protected]>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Main where

import qualified ConferenceFeature.Lib as Lib

main :: IO ()
main = Lib.main
98 changes: 98 additions & 0 deletions tools/db/conference-feature/conference-feature.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
cabal-version: 3.0
name: conference-feature
version: 1.0.0
synopsis: check the user's conference feature
category: Network
author: Wire Swiss GmbH
maintainer: Wire Swiss GmbH <[email protected]>
copyright: (c) 2024 Wire Swiss GmbH
license: AGPL-3.0-only
build-type: Simple

library
hs-source-dirs: src
exposed-modules:
ConferenceFeature.Lib
ConferenceFeature.Types

ghc-options:
-O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates
-Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path
-funbox-strict-fields -threaded -with-rtsopts=-N
-Wredundant-constraints -Wunused-packages

build-depends:
, aeson
, aeson-pretty
, base
, bytestring
, cassandra-util
, conduit
, containers
, cql
, exceptions
, imports
, lens
, optparse-applicative
, tinylog
, types-common
, wire-api

default-extensions:
AllowAmbiguousTypes
BangPatterns
ConstraintKinds
DataKinds
DefaultSignatures
DeriveFunctor
DeriveGeneric
DeriveLift
DeriveTraversable
DerivingStrategies
DerivingVia
DuplicateRecordFields
EmptyCase
FlexibleContexts
FlexibleInstances
FunctionalDependencies
GADTs
GeneralizedNewtypeDeriving
InstanceSigs
KindSignatures
LambdaCase
MultiParamTypeClasses
MultiWayIf
NamedFieldPuns
NoImplicitPrelude
OverloadedLabels
OverloadedRecordDot
OverloadedStrings
PackageImports
PatternSynonyms
PolyKinds
QuasiQuotes
RankNTypes
RecordWildCards
ScopedTypeVariables
StandaloneDeriving
TupleSections
TypeApplications
TypeFamilies
TypeFamilyDependencies
TypeOperators
UndecidableInstances
ViewPatterns

executable conference-feature
main-is: Main.hs
build-depends:
, base
, conference-feature

hs-source-dirs: app
default-language: Haskell2010
ghc-options:
-O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates
-Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path
-funbox-strict-fields -threaded -with-rtsopts=-N
-Wredundant-constraints -Wunused-packages
53 changes: 53 additions & 0 deletions tools/db/conference-feature/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# WARNING: GENERATED FILE, DO NOT EDIT.
# This file is generated by running hack/bin/generate-local-nix-packages.sh and
# must be regenerated whenever local packages are added or removed, or
# dependencies are added or removed.
{ mkDerivation
, aeson
, aeson-pretty
, base
, bytestring
, cassandra-util
, conduit
, containers
, cql
, exceptions
, gitignoreSource
, imports
, lens
, lib
, optparse-applicative
, time
, tinylog
, types-common
, wire-api
}:
mkDerivation {
pname = "conference-feature";
version = "1.0.0";
src = gitignoreSource ./.;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [
aeson
aeson-pretty
base
bytestring
cassandra-util
conduit
containers
cql
exceptions
imports
lens
optparse-applicative
time
tinylog
types-common
wire-api
];
executableHaskellDepends = [ base ];
description = "check the user's conference feature";
license = lib.licenses.agpl3Only;
mainProgram = "conference-feature";
}
95 changes: 95 additions & 0 deletions tools/db/conference-feature/src/ConferenceFeature/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{-# LANGUAGE OverloadedStrings #-}

-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2024 Wire Swiss GmbH <[email protected]>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module ConferenceFeature.Lib where

import Cassandra as C
import ConferenceFeature.Types
import Data.Conduit
import qualified Data.Conduit.Combinators as Conduit
import qualified Data.Set as Set
import qualified Database.CQL.Protocol as CQL
import Imports
import Options.Applicative
import System.Logger.Class (MonadLogger)
import qualified System.Logger.Class as Log
import System.Logger.Message ((.=))
import Wire.API.Team.Feature
import Wire.API.User (AccountStatus (Active))

pageSize :: Int32
pageSize = 1000

readUsers :: forall m. (MonadClient m, MonadLogger m) => ConduitM () [UserRow] m ()
readUsers =
paginateC cql (paramsP One () pageSize) x5
.| Conduit.map (fmap CQL.asRecord)
where
cql :: C.PrepQuery C.R () (CQL.TupleType UserRow)
cql =
"SELECT id, activated, status, team, feature_conference_calling FROM user"

scanUsers :: forall m. (MonadClient m, MonadLogger m) => ConduitT () Result m ()
scanUsers = do
readUsers
.| Conduit.concat
.| Conduit.map userToResult
.| Conduit.scanl (<>) mempty
.| Conduit.iterM (logEvery 100000)
where
logEvery :: Int -> Result -> m ()
logEvery i r =
when ((getSum (usersTotal r)) `mod` i == 0) $ Log.info $ "intermediate" .= show r

userToResult :: UserRow -> Result
userToResult user = case user.conferenceCallingFeatureStatus of
Just FeatureStatusEnabled ->
if user.activated && user.status == Just Active
then case user.team of
Just tid ->
mempty
{ usersTotal = Sum 1,
activeTeamUsersWithConferenceCalling = Sum 1,
affectedTeams = Set.singleton tid
}
Nothing ->
mempty
{ usersTotal = Sum 1,
activeFreeUsersWithConferenceCalling = Sum 1
}
else
mempty
{ usersTotal = Sum 1,
inactiveUsersWithConferenceCalling = Sum 1
}
Just FeatureStatusDisabled -> mempty {usersTotal = Sum 1}
Nothing -> mempty {usersTotal = Sum 1}

run :: forall m. (MonadClient m, MonadLogger m) => m ()
run = do
result <- runConduit $ scanUsers .| Conduit.lastDef mempty
Log.info $ "result" .= show result

main :: IO ()
main = do
opts <- execParser (info (helper <*> optsParser) desc)
env <- mkEnv opts
runReaderT (unAppT run) env
where
desc = header "conference-feature" <> progDesc "find users with conference feature" <> fullDesc
Loading
Loading