Skip to content

Commit

Permalink
refactor: merge hstream-kafka-server into hstream-server (#1694)
Browse files Browse the repository at this point in the history
To start hserver, run:

$ hstream-server --config-path ...

To start hserver-kafka, run:

$ hstream-server kafka --config-path ...
  • Loading branch information
4eUeP authored Nov 24, 2023
1 parent 3073f50 commit 04df96e
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 62 deletions.
2 changes: 0 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ COPY --from=ld_image /logdevice/common/test/ssl_certs/ /logdevice/common/test/ss

COPY --from=builder /root/.cabal/bin/hstream-server \
/root/.cabal/bin/hstream-server-old \
/root/.cabal/bin/hstream-kafka-server \
/root/.cabal/bin/hstream-kafka-server-old \
/root/.cabal/bin/hstream-kafka-cli \
/root/.cabal/bin/hstream \
/root/.cabal/bin/hadmin \
Expand Down
7 changes: 7 additions & 0 deletions hstream-kafka/HStream/Kafka/Server/Config.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module HStream.Kafka.Server.Config
( ServerOpts (..)
, CliOptions (..)
, cliOptionsParser

, runServerConfig
, runServerFromCliOpts

, MetaStoreAddr (..)
, AdvertisedListeners
Expand Down Expand Up @@ -31,6 +35,9 @@ runServerConfig args f = do
ShowVersion -> showVersion
Cli cliOpts -> getConfig cliOpts >>= f

runServerFromCliOpts :: CliOptions -> (ServerOpts -> IO ()) -> IO ()
runServerFromCliOpts cliOpts f = getConfig cliOpts >>= f

getConfig :: CliOptions -> IO ServerOpts
getConfig opts@CliOptions{..} = do
path <- makeAbsolute cliConfigPath
Expand Down
2 changes: 2 additions & 0 deletions hstream-kafka/HStream/Kafka/Server/Config/FromCli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
module HStream.Kafka.Server.Config.FromCli
( serverCliParser
, runServerCli

, CliOptions (..)
, cliOptionsParser

-- * Helpers
Expand Down
10 changes: 8 additions & 2 deletions hstream/app/kafka-server.hs → hstream/app/lib/KafkaServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

-- FIXME: How about merging this module into hstream/app/server.hs?
module KafkaServer
( app
, runApp
) where

import Control.Concurrent (forkIO)
import qualified Control.Concurrent.Async as Async
import Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar,
Expand Down Expand Up @@ -67,8 +73,8 @@ import Text.RawString.QQ (r)

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

main :: IO ()
main = do
runApp :: IO ()
runApp = do
args <- getArgs
runServerConfig args app

Expand Down
15 changes: 11 additions & 4 deletions hstream/app/server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import HStream.Gossip (GossipContext (..),
startGossip, waitGossipBoot)
import HStream.Gossip.Types (Epoch, InitType (Gossip))
import HStream.Gossip.Utils (getMemberListWithEpochSTM)
import qualified HStream.Kafka.Server.Config as Ka
import qualified HStream.Logger as Log
import HStream.MetaStore.Types as M (MetaHandle (..),
MetaStore (..),
Expand Down Expand Up @@ -78,6 +79,7 @@ import HStream.Server.Types (ServerContext (..))
import qualified HStream.Store.Logger as Log
import qualified HStream.ThirdParty.Protobuf as Proto
import HStream.Utils (getProtoTimestamp)
import qualified KafkaServer as Ka

#ifdef HStreamUseGrpcHaskell
import HStream.Server.Handler (handlers)
Expand All @@ -98,8 +100,12 @@ main = do
args <- getArgs
serverCli <- runServerCli args
case serverCli of
ShowVersion -> showVersion
Cli cliOpts -> getConfig cliOpts >>= app
ShowVersion -> showVersion
Cli cliOpts -> getConfig cliOpts >>= app
KafkaCli cliOpts -> Ka.runServerFromCliOpts cliOpts Ka.app

-------------------------------------------------------------------------------
-- HStream Server

app :: ServerOpts -> IO ()
app config@ServerOpts{..} = do
Expand Down Expand Up @@ -291,8 +297,6 @@ serveListeners sc grpcOpts
else HsGrpc.runServer grpcOpts' (HsGrpcHandler.handlers sc')
#endif

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

-- default grpc options
#ifdef HStreamUseGrpcHaskell
defGrpcOpts
Expand Down Expand Up @@ -328,6 +332,9 @@ defGrpcOpts host port tlsConfig chanArgs = do
}
#endif

-------------------------------------------------------------------------------
-- Misc

showVersion :: IO ()
showVersion = do
API.HStreamVersion{..} <- getHStreamVersion
Expand Down
99 changes: 48 additions & 51 deletions hstream/hstream.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ library
, hstream-common-stats
, hstream-gossip
, hstream-io
, hstream-kafka
, hstream-processing
, hstream-sql
, hstream-store
Expand Down Expand Up @@ -209,14 +210,11 @@ library
TypeApplications
UnliftedFFITypes

executable hstream-server
if flag(hstream_enable_asan)
import: shared-properties, link-asan

if !flag(hstream_enable_asan)
import: shared-properties

main-is: app/server.hs
-- Local app library
library hstream-app
import: shared-properties
hs-source-dirs: app/lib
exposed-modules: KafkaServer
build-depends:
, async
, base
Expand All @@ -227,18 +225,19 @@ executable hstream-server
, grpc-haskell
, grpc-haskell-core
, hs-grpc-server
, hstream
, hstream-admin-server
, hstream-api-hs
, hstream-common
, hstream-common-base
, hstream-common-server
, hstream-common-stats
, hstream-gossip
, hstream-kafka
, hstream-store
, http-client
, memory
, optparse-applicative
, prometheus-client
, proto3-suite
, proto3-wire
, raw-strings-qq
Expand All @@ -247,6 +246,8 @@ executable hstream-server
, text
, timers
, vector
, wai-middleware-prometheus
, warp
, Z-Data
, zoovisitor

Expand All @@ -257,52 +258,15 @@ executable hstream-server
cpp-options: -DHSTREAM_ENABLE_ASAN

default-language: Haskell2010
ghc-options:
-threaded -rtsopts "-with-rtsopts=-N -A64m -n4m -qg -qn1"

executable hstream
import: shared-properties
main-is: app/client.hs
build-depends:
, aeson
, ansi-terminal
, base
, bytestring
, containers
, grpc-haskell
, grpc-haskell-core
, haskeline
, hstream
, hstream-admin-server
, hstream-api-hs
, hstream-common
, hstream-common-base
, hstream-common-stats
, hstream-sql
, hstream-store
, network
, optparse-applicative
, proto3-suite
, random
, raw-strings-qq
, split
, text
, unix
, unordered-containers
, vector
, Z-Data

default-language: Haskell2010
ghc-options: -threaded -rtsopts -with-rtsopts=-N

executable hstream-kafka-server
executable hstream-server
if flag(hstream_enable_asan)
import: shared-properties, link-asan

if !flag(hstream_enable_asan)
import: shared-properties

main-is: app/kafka-server.hs
main-is: app/server.hs
build-depends:
, async
, base
Expand All @@ -322,10 +286,10 @@ executable hstream-kafka-server
, hstream-gossip
, hstream-kafka
, hstream-store
, hstream:{hstream, hstream-app}
, http-client
, memory
, optparse-applicative
, prometheus-client
, proto3-suite
, proto3-wire
, raw-strings-qq
Expand All @@ -334,8 +298,6 @@ executable hstream-kafka-server
, text
, timers
, vector
, wai-middleware-prometheus
, warp
, Z-Data
, zoovisitor

Expand All @@ -349,6 +311,41 @@ executable hstream-kafka-server
ghc-options:
-threaded -rtsopts "-with-rtsopts=-N -A64m -n4m -qg -qn1"

executable hstream
import: shared-properties
main-is: app/client.hs
build-depends:
, aeson
, ansi-terminal
, base
, bytestring
, containers
, grpc-haskell
, grpc-haskell-core
, haskeline
, hstream
, hstream-admin-server
, hstream-api-hs
, hstream-common
, hstream-common-base
, hstream-common-stats
, hstream-sql
, hstream-store
, network
, optparse-applicative
, proto3-suite
, random
, raw-strings-qq
, split
, text
, unix
, unordered-containers
, vector
, Z-Data

default-language: Haskell2010
ghc-options: -threaded -rtsopts -with-rtsopts=-N

executable hstream-kafka-cli
if flag(hstream_enable_asan)
import: shared-properties, link-asan
Expand Down
12 changes: 11 additions & 1 deletion hstream/src/HStream/Server/Configuration/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import System.Exit (exitSuccess)
import qualified Z.Data.CBytes as CB
import Z.Data.CBytes (CBytes)

import qualified HStream.Kafka.Server.Config as Ka
import qualified HStream.Logger as Log
import qualified HStream.Server.HStreamInternal as SAI
import HStream.Store (Compression (..))
Expand All @@ -55,11 +56,15 @@ import qualified HStream.Store.Logger as Log

data ServerCli
= Cli CliOptions
| KafkaCli Ka.CliOptions
| ShowVersion
deriving (Show)

serverCliParser :: O.Parser ServerCli
serverCliParser = (Cli <$> cliOptionsParser) <|> showVersionParser
serverCliParser =
(Cli <$> cliOptionsParser)
<|> kafkaCliParser
<|> showVersionParser

runServerCli :: [String] -> IO ServerCli
runServerCli args =
Expand All @@ -81,6 +86,11 @@ runServerCli args =
putStr msg
exitSuccess

kafkaCliParser :: O.Parser ServerCli
kafkaCliParser = O.hsubparser
(O.command "kafka" (O.info (KafkaCli <$> Ka.cliOptionsParser)
(O.progDesc "Run as kafka broker")))

showVersionParser :: O.Parser ServerCli
showVersionParser = O.flag' ShowVersion
( O.long "version" <> O.short 'v' <> O.help "Show server version." )
Expand Down
4 changes: 2 additions & 2 deletions script/dev-tools
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,10 @@ class QuickBuildDevImageCommand:
exe_renames = {}

build_targets = ["hstream", "hstream-admin"]
exe_targets = ["hstream-server", "hstream", "hadmin", "hstream-kafka-server"]
exe_targets = ["hstream-server", "hstream", "hadmin"]
if only_hstream:
build_targets = ["hstream"]
exe_targets = ["hstream-server", "hstream", "hstream-kafka-server"]
exe_targets = ["hstream-server", "hstream"]

tmp_container_name = f"tmp_build_dev_image_{gen_randoms(20)}"
try:
Expand Down

0 comments on commit 04df96e

Please sign in to comment.