File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -230,6 +230,10 @@ library stubs
230230 tasty,
231231 tasty-hunit
232232
233+ if !flag(fbthrift)
234+ other-modules: Facebook.Service.HttpFb303
235+ build-depends: wai, http-types
236+
233237library logger
234238 import: fb-haskell, fb-cpp, deps
235239 visibility: private
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ import Thrift.Processor
3232import Thrift.Server.CppServer
3333#else
3434import Thrift.Server.HTTP
35+ import Facebook.Service.HttpFb303
3536#endif
3637
3738-- | Runs a facebook service on a CPPServer
@@ -166,7 +167,12 @@ withBackgroundFacebookService_
166167 -> IO a
167168withBackgroundFacebookService_ fb303 handler postProcess opts waitAction = do
168169 bracketFb303 fb303 Fb303_status_STARTING Fb303_status_STOPPED $ do
169- withBackgroundServer' handler postProcess opts waitAction
170+ #if FBTHRIFT
171+ let opts' = opts
172+ #else
173+ let opts' = opts { middleware = middleware opts . fb303Middleware fb303 }
174+ #endif
175+ withBackgroundServer' handler postProcess opts' waitAction
170176
171177nilPostProcess :: a -> b -> [c ]
172178nilPostProcess _ _ = []
Original file line number Diff line number Diff line change 1+ {-
2+ Copyright (c) Meta Platforms, Inc. and affiliates.
3+ All rights reserved.
4+
5+ This source code is licensed under the BSD-style license found in the
6+ LICENSE file in the root directory of this source tree.
7+ -}
8+
9+ module Facebook.Service.HttpFb303 where
10+
11+ import qualified Data.ByteString.Lazy as LBS
12+ import Data.IORef (readIORef )
13+ import Network.HTTP.Types
14+ import Network.Wai
15+
16+ import Facebook.Fb303
17+ import Fb303Core.Types
18+
19+ -- | Middleware exposing Fb303 as a more standard health check endpoint at @/health@.
20+ fb303Middleware :: Fb303State -> Middleware
21+ fb303Middleware fb303 app req respond = do
22+ case pathInfo req of
23+ [" health" ] -> do
24+ status <- readIORef (fb303_status fb303)
25+ let replyStatus = case status of
26+ Fb303_status_ALIVE -> ok200
27+ Fb303_status_WARNING -> mkStatus 290 " warning"
28+ Fb303_status_STARTING -> mkStatus 291 " starting"
29+ Fb303_status_STOPPING -> mkStatus 292 " stopping"
30+ Fb303_status_STOPPED -> mkStatus 293 " stopped"
31+ Fb303_status_DEAD -> mkStatus 294 " dead"
32+ Fb303_status__UNKNOWN _ -> mkStatus 299 " unknown status"
33+ respond $ responseLBS replyStatus [(hContentType, " text/plain" )] (LBS. fromStrict $ statusMessage replyStatus)
34+ _ -> app req respond
You can’t perform that action at this time.
0 commit comments