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

Disable de-federation (to avoid running into a scalability issue). #3582

Merged
merged 43 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5cd9b51
Disable de-federation (to avoid running into a scalability issue).
fisx Sep 13, 2023
3f2c608
Fixup
fisx Sep 13, 2023
3b4f917
Fix changelog entries.
fisx Sep 13, 2023
c18179f
Fixup
fisx Sep 13, 2023
1be1316
...
fisx Sep 14, 2023
1b4199f
Revert "WPB-3916: Filtering out duplicate members when sending defede…
fisx Sep 14, 2023
890695f
Revert "WPB-3611: Notifying remote domains about defederation. (#3487)"
fisx Sep 14, 2023
3714ce7
sanitize-pr
fisx Sep 14, 2023
0cd2e76
hi ci
fisx Sep 14, 2023
27d2809
hi ci
fisx Sep 14, 2023
225da42
Merge remote-tracking branch 'origin/develop' into WPB-4668-disable-d…
fisx Sep 14, 2023
1c54bae
m|=| :')
fisx Sep 15, 2023
1e79578
Remove outdated FUTUREWORK.
fisx Sep 15, 2023
d1f5a26
rm one more integration test.
fisx Sep 15, 2023
1ea24f1
rm one more trace of the defederation worker.
fisx Sep 15, 2023
4d2b605
Fix tests.
fisx Sep 15, 2023
58a0468
rm another obsolete test.
fisx Sep 15, 2023
2a9662b
Work around record syntax limitations.
fisx Sep 15, 2023
aa27851
Fixup
fisx Sep 15, 2023
566f675
Merge remote-tracking branch 'origin/develop' into WPB-4668-disable-d…
fisx Sep 15, 2023
d882e9b
Cleanup brig_test.federation_remotes for legacy integration tests.
fisx Sep 15, 2023
f3d8899
Fixup
fisx Sep 15, 2023
b36945e
Fixup
fisx Sep 15, 2023
b6ae5e1
Fixup
fisx Sep 15, 2023
446430c
...
fisx Sep 15, 2023
790fa39
...
fisx Sep 15, 2023
5d1ef83
...
fisx Sep 15, 2023
f7c3879
...
fisx Sep 15, 2023
6510c76
...
fisx Sep 18, 2023
d0d8bec
[stash]
fisx Sep 18, 2023
410675f
Truncate federation_remotes for dynamic backends on acquire
akshaymankar Sep 18, 2023
aa06800
ThreadDelay FTW
akshaymankar Sep 18, 2023
6dd7a4d
Delete unnecesary ci-cleanup-fed-remotes make target
akshaymankar Sep 18, 2023
f6ed7e0
Allow searching before searching
akshaymankar Sep 18, 2023
d7e5c9c
Remove TODOs
akshaymankar Sep 18, 2023
cc85728
Don't assume domains
akshaymankar Sep 18, 2023
2b076fe
Remove unnecessary comment
akshaymankar Sep 18, 2023
ba30535
Cleanup
fisx Sep 18, 2023
620b2e9
Cleanup
fisx Sep 18, 2023
b9f24ad
Remove redundant constraints
akshaymankar Sep 18, 2023
8d2c59d
Remove unnecessary createFedConn
akshaymankar Sep 18, 2023
1594279
Undo changes made to federator tests
akshaymankar Sep 19, 2023
0f3875a
federator-integration: Use diffferent endpoint for testing federator
akshaymankar Sep 19, 2023
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
5 changes: 0 additions & 5 deletions changelog.d/1-api-changes/WPB-3611

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/1-api-changes/WPB-4668-disable-defederation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove de-federation (to avoid a scalability issue).
akshaymankar marked this conversation as resolved.
Show resolved Hide resolved
1 change: 0 additions & 1 deletion changelog.d/3-bug-fixes/duplicate-member-notifications

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/6-federation/WPB-3611

This file was deleted.

9 changes: 2 additions & 7 deletions docs/src/understand/configure-federation.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,8 @@ the sysadmin:

* [`PUT`](https://staging-nginz-https.zinfra.io/api-internal/swagger-ui/brig/#/brig/put_i_federation_remotes__domain_)

* [`DELETE`](https://staging-nginz-https.zinfra.io/api-internal/swagger-ui/brig/#/brig/delete_i_federation_remotes__domain_)
- **WARNING:** If you delete a connection, all users from that
remote will be removed from local conversations, and all
conversations hosted by that remote will be removed from the local
backend. Connections between local and remote users that are
removed will be archived, and can be re-established should you
decide to add the same backend later.
* **NOTE:** De-federating (`DELETE`) has been removed from the API to
avoid a scalability issue. Watch out for a fix in the changelog!

The `remotes` list looks like this:

Expand Down
1 change: 0 additions & 1 deletion integration/integration.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ library
Test.Brig
Test.Client
Test.Conversation
Test.Defederation
Test.Demo
Test.Federation
Test.Federator
Expand Down
9 changes: 0 additions & 9 deletions integration/test/API/GalleyInternal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,3 @@ getFederationStatus user domains =
submit
"GET"
$ req & addJSONObject ["domains" .= domainList]

deleteFederationDomain ::
( HasCallStack
) =>
String ->
App Response
deleteFederationDomain domain = do
req <- rawBaseRequest OwnDomain Galley Unversioned $ joinHttpPath ["i", "federation", domain]
submit "DELETE" req
12 changes: 1 addition & 11 deletions integration/test/Test/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,7 @@ testDefederationGroupConversation = do
r.status `shouldMatchInt` 404

-- assert federation.delete event is sent twice
void $
awaitNMatches
2
3
( \n -> do
correctType <- nPayload n %. "type" `isEqual` "federation.delete"
if correctType
then nPayload n %. "domain" `isEqual` domainB
else pure False
)
ws
void $ awaitNMatches 2 3 (\n -> nPayload n %. "type" `isEqual` "federation.delete") ws

-- assert no conversation.delete event is sent to uA
eventPayloads <-
Expand Down
85 changes: 0 additions & 85 deletions integration/test/Test/Defederation.hs

This file was deleted.

19 changes: 0 additions & 19 deletions libs/schema-profunctor/src/Data/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ module Data.Schema
fieldOverF,
fieldWithDocModifierF,
array,
pair,
set,
nonEmptyArray,
map_,
Expand Down Expand Up @@ -464,24 +463,6 @@ array sch = SchemaP (SchemaDoc s) (SchemaIn r) (SchemaOut w)
s = mkArray (schemaDoc sch)
w x = A.Array . V.fromList <$> mapM (schemaOut sch) x

-- | A schema for a JSON pair.
-- This is serialised as JSON array of exactly 2 elements
-- of the same type. Any more or less is an error.
pair ::
(HasArray ndoc doc, HasName ndoc) =>
ValueSchema ndoc a ->
ValueSchema doc (a, a)
pair sch = SchemaP (SchemaDoc s) (SchemaIn r) (SchemaOut w)
where
name = maybe "pair" ("pair of " <>) (getName (schemaDoc sch))
r = A.withArray (T.unpack name) $ \arr -> do
l <- mapM (schemaIn sch) $ V.toList arr
case l of
[a, b] -> pure (a, b)
_ -> fail $ "Expected exactly 2 elements, but got " <> show (length l)
s = mkArray (schemaDoc sch)
w (a, b) = A.Array . V.fromList <$> mapM (schemaOut sch) [a, b]

set ::
(HasArray ndoc doc, HasName ndoc, Ord a) =>
ValueSchema ndoc a ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ type GalleyApi =
TypingDataUpdateRequest
TypingDataUpdateResponse
:<|> FedEndpoint "on-typing-indicator-updated" TypingDataUpdated EmptyResponse
:<|> FedEndpoint "on-connection-removed" Domain EmptyResponse

data TypingDataUpdateRequest = TypingDataUpdateRequest
{ typingStatus :: TypingStatus,
Expand Down
69 changes: 18 additions & 51 deletions libs/wire-api/src/Wire/API/Event/Federation.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{-# LANGUAGE TemplateHaskell #-}

module Wire.API.Event.Federation
( Event (..),
EventType (..),
)
where

import Control.Arrow ((&&&))
import Control.Lens (makePrisms)
import Data.Aeson (FromJSON, ToJSON)
import Data.Aeson qualified as A
import Data.Aeson.KeyMap qualified as KeyMap
Expand All @@ -15,71 +12,41 @@ import Data.Json.Util (ToJSONObject (toJSONObject))
import Data.Schema
import Data.Swagger qualified as S
import Imports
import Test.QuickCheck.Gen
import Wire.Arbitrary

data Event
= FederationDelete Domain
| FederationConnectionRemoved (Domain, Domain)
deriving stock (Eq, Show, Generic)

$(makePrisms ''Event)
data Event = Event
{ _eventType :: EventType,
_eventDomain :: Domain
}
deriving (Eq, Show, Ord, Generic)

instance Arbitrary Event where
arbitrary =
oneof
[ FederationDelete <$> arbitrary,
FederationConnectionRemoved <$> arbitrary
]
Event
<$> arbitrary
<*> arbitrary

data EventType
= FederationTypeDelete
| FederationTypeConnectionRemoved
deriving (Eq, Show, Ord, Enum, Bounded, Generic)
= FederationDelete
deriving (Eq, Show, Ord, Generic)
deriving (Arbitrary) via (GenericUniform EventType)
deriving (A.FromJSON, A.ToJSON, S.ToSchema) via Schema EventType

instance ToSchema EventType where
schema =
enum @Text "FederationEventType" $
enum @Text "EventType" $
mconcat
[ element "federation.delete" FederationTypeDelete,
element "federation.connectionRemoved" FederationTypeConnectionRemoved
[ element "federation.delete" FederationDelete
]

eventType :: Event -> EventType
eventType (FederationDelete _) = FederationTypeDelete
eventType (FederationConnectionRemoved _) = FederationTypeConnectionRemoved

taggedEventDataSchema :: ObjectSchema SwaggerDoc (EventType, Event)
taggedEventDataSchema =
bind
(fst .= field "type" schema)
-- The fields we need to look at change based on the event
-- type, so we need to dispatch here to get monadic-ish behaviour.
--
-- federation.delete is expecting a "domain" field that contains a bare domain string.
-- federation.connectionRemoved is expecting a "domains" field that contains exactly a pair of domains in a list
( snd .= dispatch dataSchema
)
where
dataSchema :: EventType -> ObjectSchema SwaggerDoc Event
dataSchema FederationTypeDelete = tag _FederationDelete deleteSchema
dataSchema FederationTypeConnectionRemoved = tag _FederationConnectionRemoved connectionRemovedSchema

-- These schemas have different fields they are targeting.
deleteSchema :: ObjectSchema SwaggerDoc Domain
deleteSchema = field "domain" schema

connectionRemovedSchema :: ObjectSchema SwaggerDoc (Domain, Domain)
connectionRemovedSchema = field "domains" (pair schema)

-- Schemas for the events, as they have different structures.
eventObjectSchema :: ObjectSchema SwaggerDoc Event
eventObjectSchema = snd <$> (eventType &&& id) .= taggedEventDataSchema
eventObjectSchema =
Event
<$> _eventType .= field "type" schema
<*> _eventDomain .= field "domain" schema

instance ToSchema Event where
schema = object "FederationEvent" eventObjectSchema
schema = object "Event" eventObjectSchema

instance ToJSONObject Event where
toJSONObject =
Expand Down
11 changes: 1 addition & 10 deletions libs/wire-api/src/Wire/API/FederationUpdate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ module Wire.API.FederationUpdate
( syncFedDomainConfigs,
SyncFedDomainConfigsCallback (..),
emptySyncFedDomainConfigsCallback,
deleteFederationRemoteGalley,
fetch,
)
where

import Control.Concurrent.Async
import Control.Exception
import Control.Retry qualified as R
import Data.Domain
import Data.Set qualified as Set
import Data.Text
import Data.Typeable (cast)
import Imports
import Network.HTTP.Client (defaultManagerSettings, newManager)
import Servant.Client (BaseUrl (BaseUrl), ClientEnv (ClientEnv), ClientError, ClientM, Scheme (Http), runClientM)
import Servant.Client (BaseUrl (BaseUrl), ClientEnv (ClientEnv), ClientError, Scheme (Http), runClientM)
import Servant.Client.Internal.HttpClient (defaultMakeClientRequest)
import System.Logger qualified as L
import Util.Options
Expand All @@ -34,9 +31,6 @@ syncFedDomainConfigs (Endpoint h p) log' cb = do
updateDomainsThread <- async $ loop log' clientEnv cb ioref
pure (ioref, updateDomainsThread)

deleteFedRemoteGalley :: Domain -> ClientM ()
deleteFedRemoteGalley dom = namedClient @IAPI.API @"delete-federation-remote-from-galley" dom

-- | Initial function for getting the set of domains from brig, and an update interval
initialize :: L.Logger -> ClientEnv -> IO FederationDomainConfigs
initialize logger clientEnv =
Expand All @@ -56,9 +50,6 @@ initialize logger clientEnv =
Just c -> pure c
Nothing -> throwIO $ ErrorCall "*** Failed to reach brig for federation setup, giving up!"

deleteFederationRemoteGalley :: Domain -> ClientEnv -> IO (Either ClientError ())
deleteFederationRemoteGalley dom = runClientM $ deleteFedRemoteGalley dom

loop :: L.Logger -> ClientEnv -> SyncFedDomainConfigsCallback -> IORef FederationDomainConfigs -> IO ()
loop logger clientEnv (SyncFedDomainConfigsCallback callback) env = forever $
catch go $ \(e :: SomeException) -> do
Expand Down
30 changes: 0 additions & 30 deletions libs/wire-api/src/Wire/API/Routes/Internal/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -764,40 +764,10 @@ type FederationRemotesAPI =
:> ReqBody '[JSON] FederationDomainConfig
:> Put '[JSON] ()
)
:<|> Named
"delete-federation-remotes"
( Description FederationRemotesAPIDescription
:> Description FederationRemotesAPIDeleteDescription
:> "federation"
:> "remotes"
:> Capture "domain" Domain
:> Delete '[JSON] ()
)
-- This is nominally similar to delete-federation-remotes,
-- but is called from Galley to delete the one-on-one coversations.
-- This is needed as Galley doesn't have access to the tables
-- that hold these values. We don't want these deletes to happen
-- in delete-federation-remotes as brig might fall over and leave
-- some records hanging around. Galley uses a Rabbit queue to track
-- what is has done and can recover from a service falling over.
:<|> Named
"delete-federation-remote-from-galley"
( Description FederationRemotesAPIDescription
:> Description FederationRemotesAPIDeleteDescription
:> "federation"
:> "remote"
:> Capture "domain" Domain
:> "galley"
:> Delete '[JSON] ()
)

type FederationRemotesAPIDescription =
"See https://docs.wire.com/understand/federation/backend-communication.html#configuring-remote-connections for background. "

type FederationRemotesAPIDeleteDescription =
"**WARNING!** If you remove a remote connection, all users from that remote will be removed from local conversations, and all \
\group conversations hosted by that remote will be removed from the local backend. This cannot be reverted! "

swaggerDoc :: Swagger
swaggerDoc =
toSwagger (Proxy @API)
Expand Down
Loading
Loading