Skip to content
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
1 change: 1 addition & 0 deletions changelog.d/5-internal/pr-3036
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make stern fail on startup if supported backend api version needs bumping
4 changes: 4 additions & 0 deletions libs/wire-api/src/Wire/API/Routes/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Control.Lens ((?~))
import Data.Aeson (FromJSON, ToJSON (..))
import qualified Data.Aeson as Aeson
import Data.Bifunctor
import Data.ByteString.Conversion (ToByteString (builder))
import qualified Data.ByteString.Lazy as LBS
import Data.Domain
import Data.Schema
Expand Down Expand Up @@ -83,6 +84,9 @@ instance ToHttpApiData Version where
toHeader = LBS.toStrict . Aeson.encode
toUrlPiece = Text.decodeUtf8 . toHeader

instance ToByteString Version where
builder = toEncodedUrlPiece

supportedVersions :: [Version]
supportedVersions = [minBound .. maxBound]

Expand Down
1 change: 1 addition & 0 deletions tools/stern/src/Stern/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ default (ByteString)
start :: Opts -> IO ()
start o = do
e <- newEnv o
runAppT e $ Intra.assertBackendApiVersion
s <- Server.newSettings (server e)
Server.runSettingsWithShutdown s (servantApp e) Nothing
where
Expand Down
32 changes: 29 additions & 3 deletions tools/stern/src/Stern/Intra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Stern.Intra
( putUser,
( assertBackendApiVersion,
putUser,
putUserStatus,
getContacts,
getUserConnections,
Expand Down Expand Up @@ -61,10 +62,12 @@ module Stern.Intra
)
where

import Bilge hiding (head, options, requestId)
import Bilge hiding (head, options, path, paths, requestId)
import qualified Bilge
import Bilge.RPC
import Brig.Types.Intra
import Control.Error
import Control.Exception (ErrorCall (ErrorCall))
import Control.Lens (view, (^.))
import Control.Monad.Reader
import Data.Aeson hiding (Error)
Expand Down Expand Up @@ -94,6 +97,7 @@ import Stern.Types
import System.Logger.Class hiding (Error, name, (.=))
import qualified System.Logger.Class as Log
import UnliftIO.Exception hiding (Handler)
import UnliftIO.Retry (constantDelay, limitRetries, recoverAll)
import Wire.API.Connection
import Wire.API.Conversation
import Wire.API.Internal.Notification
Expand All @@ -114,6 +118,28 @@ import Wire.API.User.Search

-------------------------------------------------------------------------------

backendApiVersion :: Version
backendApiVersion = V2

-- | Make sure the backend supports `backendApiVersion`. Crash if it doesn't. (This is called
-- in `Stern.API` so problems make `./services/integration.sh` crash.)
assertBackendApiVersion :: App ()
assertBackendApiVersion = recoverAll (constantDelay 1000000 <> limitRetries 5) $ \_retryStatus -> do
b <- view brig
vinfo :: VersionInfo <-
responseJsonError
=<< rpc' "brig" b (method GET . Bilge.path "/api-version" . contentJson . expect2xx)
unless (maximum (vinfoSupported vinfo) == backendApiVersion) $ do
throwIO . ErrorCall $ "newest supported backend api version must be " <> show backendApiVersion

path :: ByteString -> Request -> Request
path = Bilge.path . ((toByteString' backendApiVersion <> "/") <>)

paths :: [ByteString] -> Request -> Request
paths = Bilge.paths . (toByteString' backendApiVersion :)

-------------------------------------------------------------------------------

putUser :: UserId -> UserUpdate -> Handler ()
putUser uid upd = do
info $ userMsg uid . msg "Changing user state"
Expand Down Expand Up @@ -746,7 +772,7 @@ getUserConversations uid = do
b
( method GET
. header "Z-User" (toByteString' uid)
. path "/v2/conversations"
. path "conversations"
. queryItem "size" (toByteString' batchSize)
. maybe id (queryItem "start" . toByteString') start
. expect2xx
Expand Down
1 change: 1 addition & 0 deletions tools/stern/stern.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ library
, lens >=4.4
, metrics-wai >=0.3
, mtl >=2.1
, retry
, schema-profunctor
, servant
, servant-server
Expand Down