Skip to content

Commit

Permalink
Add tx log to elasticsearch
Browse files Browse the repository at this point in the history
Allow tx log to be sent to elasticsearch instead of stdout.
  • Loading branch information
giantimi committed Jan 9, 2024
1 parent 9619604 commit 3d66aa6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions exec/TXG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ mkElasticSearchRequest esConf version start end rks = do
, HTTP.responseTimeout = HTTP.responseTimeoutMicro 5_000_000
, HTTP.checkResponse = HTTP.throwErrorStatusCodes
, HTTP.requestHeaders =
("Content-Type", "application/x-ndjson") :
maybe [] (\k -> [("Authoriation", "ApiKey " <> T.encodeUtf8 k)]) (esApiKey esConf)
("Content-Type", "application/x-ndjson")
: maybe [] (\k -> [("Authorization", "ApiKey " <> T.encodeUtf8 k)]) (esApiKey esConf)
, HTTP.requestBody = body currentTime
}
where
Expand Down
23 changes: 10 additions & 13 deletions exec/TXG/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ instance FromJSON ChainwebHost where
data ElasticSearchConfig = ElasticSearchConfig
{ esHost :: !Hostname
, esPort :: !Port
, esIndex :: !Text
, esIndex :: !(Maybe Text)
, esApiKey :: !(Maybe Text)
} deriving (Show, Generic)

Expand Down Expand Up @@ -353,7 +353,7 @@ scriptConfigParser = id
<> metavar "INT"
<> help "Confirmation depth"
<*< field @"logLevel" .:: pLogLevel
<*< field @"elasticSearchConfig" .:: pElasticSearchConfig
<*< field @"elasticSearchConfig" .:: fmap Just % pElasticSearchConfig
where
read' :: Read a => String -> ReadM a
read' msg = eitherReader (bimap (const msg) id . readEither)
Expand All @@ -377,29 +377,26 @@ pChainId = textOption cidFromText
<> metavar "INT"
<> help "The specific chain that will receive generated transactions. Can be used multiple times."

pElasticSearchConfig :: O.Parser (Maybe ElasticSearchConfig)
pElasticSearchConfig = optional $ ElasticSearchConfig
pElasticSearchConfig :: O.Parser ElasticSearchConfig
pElasticSearchConfig = ElasticSearchConfig
<$> pHostname (Just "elastic-search")
<*> pPort (Just "elastic-search")
<*> pIndexName (Just "transaction-generator")
<*> pApiKey Nothing
<*> pIndexName
<*> pApiKey


pApiKey :: Maybe Text -> O.Parser (Maybe Text)
pApiKey def = optional $ strOption
pApiKey :: O.Parser (Maybe Text)
pApiKey = optional $ strOption
% long "elastic-search-api-key"
<> short 'k'
<> metavar "STRING"
<> help "The api key to use for elastic search."
<> value (foldr const "" def)

pIndexName :: Maybe Text -> O.Parser Text
pIndexName def = strOption
pIndexName :: O.Parser (Maybe Text)
pIndexName = optional $ strOption
% long "elastic-search-index-name"
<> short 'n'
<> metavar "STRING"
<> help "The name of the index to write to."
<> value (foldr const "transaction-generator" def)

------------
-- TXG Monad
Expand Down

0 comments on commit 3d66aa6

Please sign in to comment.