Skip to content

Commit

Permalink
create ES index
Browse files Browse the repository at this point in the history
  • Loading branch information
giantimi committed Jan 30, 2024
1 parent 3ea6401 commit beb7381
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions exec/TXG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,35 @@ mkElasticSearchRequest esConf version start end rks = do
, "timestamp" .= now
]

createElasticsearchIndex :: MonadIO m => MonadThrow m => ElasticSearchConfig -> ChainwebVersion -> m HTTP.Request
createElasticsearchIndex esConf version = do
let indexName :: String
indexName = printf "chainweb-%s-%s" (T.unpack $ chainwebVersionToText version) (fromMaybe "" $ esIndex esConf)
req <- HTTP.parseUrlThrow $ printf "http://%s:%s/%s" (T.unpack $ hostnameToText $ esHost esConf) (show $ esPort esConf) indexName
let indexSettings = object
[ "settings" .= object
[ "number_of_shards" .= (3 :: Int)
, "number_of_replicas" .= (1 :: Int)
]
, "mappings" .= object
[ "properties" .= object
[ "batch-submission-time" .= object ["type" .= ("date" :: String), "format" .= ("epoch_millis" :: String)]
, "batch-confirmation-time" .= object ["type" .= ("date" :: String), "format" .= ("epoch_millis" :: String)]
, "requestKeys" .= object ["type" .= ("keyword" :: String)]
, "chainwebVersion" .= object ["type" .= ("text" :: String)]
, "timestamp" .= object ["type" .= ("date" :: String), "format" .= ("epoch_millis" :: String)]
]
]
]
return $
req
{ method = "PUT"
, requestBody = RequestBodyLBS $ encode indexSettings
, requestHeaders = [("Content-Type", "application/json")]
}



logStatIO :: Logger Text -> ChainId -> RequestKey -> MempoolStat' -> IO ()
logStatIO logger cid rk ms =
loggerFunIO logger Info $ T.pack $ show $ MempoolStat
Expand Down Expand Up @@ -686,6 +715,9 @@ realTransactions config (ChainwebHost h _p2p service) tcut tv distribution = do

-- Set up values for running the effect stack.
gen <- liftIO createSystemRandom
-- create elasticsearch index if ElasticSearchConfig is set
forM_ (elasticSearchConfig config) $ \esConfig -> do
createElasticsearchIndex esConfig (nodeVersion config)
let act = loop (confirmationDepth config) tcut (liftIO randomEnum >>= generateTransactions False (verbose config))
env = set (field @"confKeysets") accountMap cfg
stt = TXGState gen tv chains
Expand Down

0 comments on commit beb7381

Please sign in to comment.