Skip to content

Commit b28b8a7

Browse files
committed
Use warn level when logging federation denied errors
1 parent 5fe9c12 commit b28b8a7

File tree

8 files changed

+27
-16
lines changed

8 files changed

+27
-16
lines changed

services/brig/brig.integration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ optSettings:
209209
defaultForNull:
210210
status: disabled
211211
setFederationDomainConfigsUpdateFreq: 1
212-
setFederationStrategy: allowAll
212+
setFederationStrategy: allowNone
213213
setFederationDomainConfigs:
214214
- domain: example.com
215215
search_policy: full_search

services/federator/src/Federator/Discovery.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import System.Logger.Class qualified as Log
3636
import Wire.Network.DNS.Effect (DNSLookup)
3737
import Wire.Network.DNS.Effect qualified as Lookup
3838
import Wire.Network.DNS.SRV (SrvEntry (srvTarget), SrvResponse (..), SrvTarget)
39+
import Wire.Sem.Logger.Level qualified as SemLog
3940

4041
data DiscoveryFailure
4142
= DiscoveryFailureSrvNotAvailable ByteString
@@ -45,6 +46,7 @@ data DiscoveryFailure
4546
instance Exception DiscoveryFailure
4647

4748
instance AsWai DiscoveryFailure where
49+
errorLogLevel _ = SemLog.Error
4850
toWai e = Wai.mkError status label (LText.fromStrict (discoveryErrorDescription e))
4951
where
5052
(status, label) = case e of

services/federator/src/Federator/Error.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ module Federator.Error
2121
where
2222

2323
import Network.Wai.Utilities.Error qualified as Wai
24+
import Wire.Sem.Logger.Level as Log
2425

2526
class AsWai e where
27+
errorLogLevel :: e -> Log.Level
2628
toWai :: e -> Wai.Error

services/federator/src/Federator/Error/ServerError.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Imports
2323
import Network.HTTP.Types qualified as HTTP
2424
import Network.Wai.Utilities.Error qualified as Wai
2525
import Wire.API.Federation.Domain
26+
import Wire.Sem.Logger.Level qualified as Log
2627

2728
data ServerError
2829
= InvalidRoute
@@ -33,6 +34,7 @@ data ServerError
3334
instance Exception ServerError
3435

3536
instance AsWai ServerError where
37+
errorLogLevel _ = Log.Error
3638
toWai e@InvalidRoute =
3739
Wai.mkError HTTP.status403 "invalid-endpoint" (LText.fromStrict (serverErrorDescription e))
3840
toWai e@(UnknownComponent _) =

services/federator/src/Federator/Interpreter.hs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Federator.Remote
2323
import Federator.Service
2424
import Federator.Validation
2525
import HTTP2.Client.Manager (Http2Manager)
26-
import Imports
26+
import Imports hiding (log)
2727
import Network.HTTP.Types qualified as HTTP
2828
import Network.Wai qualified as Wai
2929
import Network.Wai.Handler.Warp qualified as Warp
@@ -46,6 +46,7 @@ import Wire.API.Component (Component (Brig))
4646
import Wire.API.FederationUpdate qualified as FedUp (getFederationDomainConfigs)
4747
import Wire.API.Routes.FederationDomainConfig qualified as FedUp (FederationDomainConfigs)
4848
import Wire.Network.DNS.Effect
49+
import Wire.Sem.Logger
4950
import Wire.Sem.Logger.TinyLog
5051

5152
class ErrorEffects (ee :: [Type]) r where
@@ -84,22 +85,19 @@ runWaiErrorEither ::
8485
(AsWai e, Member TinyLog r) =>
8586
Sem (Error e ': r) (Either Wai.Error a) ->
8687
Sem r (Either Wai.Error a)
87-
runWaiErrorEither =
88-
fmap join
89-
. runError
90-
. flip catch logError
91-
. mapError toWai
92-
. raiseUnder
88+
runWaiErrorEither = fmap join . logError
9389
where
9490
logError ::
95-
( Member (Error Wai.Error) r,
96-
Member TinyLog r
97-
) =>
98-
Wai.Error ->
99-
Sem r a
100-
logError e = do
101-
err $ Wai.logErrorMsg e
102-
throw e
91+
(Member TinyLog r, AsWai e) =>
92+
Sem (Error e ': r) a ->
93+
Sem r (Either Wai.Error a)
94+
logError m =
95+
runError m >>= \case
96+
Left e -> do
97+
let we = toWai e
98+
log (errorLogLevel e) $ Wai.logErrorMsg we
99+
pure (Left we)
100+
Right x -> pure (Right x)
103101

104102
serveServant ::
105103
forall (api :: Type).

services/federator/src/Federator/MockServer.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import Wire.API.Federation.API (Component)
7474
import Wire.API.Federation.API.Common
7575
import Wire.API.Federation.Domain
7676
import Wire.API.Federation.Version
77+
import Wire.Sem.Logger.Level qualified as Log
7778
import Wire.Sem.Logger.TinyLog
7879

7980
-- | This can be thrown by actions passed to mock federator to simulate
@@ -84,6 +85,7 @@ data MockException
8485
deriving (Eq, Show, Typeable)
8586

8687
instance AsWai MockException where
88+
errorLogLevel _ = Log.Error
8789
toWai (MockErrorResponse status message) = Wai.mkError status "mock-error" message
8890
toWai (MockUnreachableBackendErrorResponse d) =
8991
Wai.mkError HTTP.status503 "mock-error" (unreachableMsg d)

services/federator/src/Federator/Remote.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import Wire.API.Federation.Client
4949
import Wire.API.Federation.Component
5050
import Wire.API.Federation.Error
5151
import Wire.Network.DNS.SRV
52+
import Wire.Sem.Logger.Level qualified as Log
5253

5354
-- | An error that can occur as a result of making a request to a remote
5455
-- federator.
@@ -63,6 +64,7 @@ data RemoteError
6364
deriving (Show)
6465

6566
instance AsWai RemoteError where
67+
errorLogLevel _ = Log.Error
6668
toWai (RemoteError target msg err) =
6769
federationRemoteHTTP2Error target msg err
6870
toWai (RemoteErrorResponse target msg status body) =

services/federator/src/Federator/Validation.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import Polysemy.Error
4646
import Polysemy.Input
4747
import Wire.API.Routes.FederationDomainConfig
4848
import Wire.Network.DNS.SRV (SrvTarget (..))
49+
import Wire.Sem.Logger.Level qualified as Log
4950

5051
data ValidationError
5152
= NoClientCertificate
@@ -58,6 +59,8 @@ data ValidationError
5859
instance Exception ValidationError
5960

6061
instance AsWai ValidationError where
62+
errorLogLevel (FederationDenied _) = Log.Warn
63+
errorLogLevel _ = Log.Error
6164
toWai err =
6265
Wai.mkError (validationErrorStatus err) (validationErrorLabel err)
6366
. LText.fromStrict

0 commit comments

Comments
 (0)