on master help sign in
Take index settings in es scribe options
commitd8e7d924bc824000c7403124a8080ffbe6b82a61 authorMichael Xavier <michael@michaelxavier.net> dateTue 13 Oct 2015, 15:49 (11 years ago) parentef5850b
3 files changed+23−8
katip-elasticsearch/katip-elasticsearch.cabal+5 katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs+9−1 katip-elasticsearch/test/Main.hs+9−7
katip-elasticsearch/katip-elasticsearch.cabal+5
@@ -84,3 +84,8 @@ test-suite test
8484 , vector
8585 , unordered-containers
8686 , scientific
87+
88+ if flag(lib-Werror)
89+ ghc-options: -Wall -Werror
90+
91+ ghc-options: -threaded -rtsopts
katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs+9−1
@@ -16,6 +16,7 @@ module Katip.Scribes.ElasticSearch
1616 , essQueueSize
1717 , essPoolSize
1818 , essAnnotateTypes
19+ , essIndexSettings
1920 , defaultEsScribeCfg
2021 -- * Utilities
2122 , mkDocId
@@ -73,6 +74,7 @@ data EsScribeCfg = EsScribeCfg {
7374 -- exposes a querying API, we will try to make deserialization and
7475 -- querying transparently remove the type annotations if this is
7576 -- enabled.
77+ , essIndexSettings :: IndexSettings
7678 } deriving (Typeable)
7779
7880
@@ -94,6 +96,7 @@ defaultEsScribeCfg = EsScribeCfg {
9496 , essQueueSize = EsQueueSize 1000
9597 , essPoolSize = EsPoolSize 2
9698 , essAnnotateTypes = False
99+ , essIndexSettings = defaultIndexSettings
97100 }
98101
99102
@@ -116,6 +119,12 @@ mkEsScribe cfg@EsScribeCfg {..} server ix mapping sev verb = do
116119 }
117120 endSig <- newEmptyMVar
118121
122+ runBH env $ do
123+ chk <- indexExists ix
124+ -- note that this doesn't update settings. That's not available
125+ -- through the Bloodhound API yet
126+ unless chk $ void $ createIndex essIndexSettings ix
127+
119128 workers <- replicateM (unEsPoolSize essPoolSize) $ async $
120129 startWorker cfg env ix mapping q
121130
@@ -123,7 +132,6 @@ mkEsScribe cfg@EsScribeCfg {..} server ix mapping sev verb = do
123132 takeMVar endSig
124133 atomically $ closeTBMQueue q
125134 mapM_ wait workers
126− closeManager mgr
127135 putMVar endSig ()
128136
129137 let scribe = Scribe $ \ i ->
katip-elasticsearch/test/Main.hs+9−7
@@ -2,6 +2,7 @@
22{-# LANGUAGE RecordWildCards #-}
33{-# LANGUAGE ScopedTypeVariables #-}
44{-# LANGUAGE TemplateHaskell #-}
5+{-# OPTIONS_GHC -fno-warn-orphans #-}
56module Main
67 ( main
78 ) where
@@ -45,7 +46,7 @@ main = defaultMain $ testGroup "katip-elasticsearch"
4546setupSearch :: IO (Scribe, IO ())
4647setupSearch = do
4748 bh recreateESSchema
48− mkEsScribe defaultEsScribeCfg { essAnnotateTypes = True } svr ixn mn DebugS V3
49+ mkEsScribe defaultEsScribeCfg { essAnnotateTypes = True, essIndexSettings = ixs } svr ixn mn DebugS V3
4950
5051
5152-------------------------------------------------------------------------------
@@ -62,7 +63,7 @@ esTests setup = testGroup "elasticsearch scribe"
6263 testCase "it flushes to elasticsearch" $ withTestLogging setup $ \done -> do
6364 $(logT) (ExampleCtx True) mempty InfoS "A test message"
6465 liftIO $ do
65− done
66+ void done
6667 logs <- getLogs
6768 length logs @?= 1
6869 let l = head logs
@@ -168,7 +169,8 @@ ixn = IndexName "katip-elasticsearch-tests"
168169
169170-------------------------------------------------------------------------------
170171ixs :: IndexSettings
171−ixs = defaultIndexSettings
172+ixs = defaultIndexSettings { indexShards = ShardCount 1
173+ , indexReplicas = ReplicaCount 1}
172174
173175-------------------------------------------------------------------------------
174176mn :: MappingName
@@ -181,7 +183,7 @@ mapping = () -- ehhh
181183
182184
183185-------------------------------------------------------------------------------
184−recreateESSchema :: BH IO Reply
186+recreateESSchema :: BH IO ()
185187recreateESSchema = dropESSchema >> createESSchema
186188
187189
@@ -191,9 +193,9 @@ dropESSchema = void $ deleteIndex ixn
191193
192194
193195-------------------------------------------------------------------------------
194−createESSchema :: BH IO Reply
195−createESSchema = do
196− createIndex ixs ixn
196+createESSchema :: BH IO ()
197+createESSchema = void $ do
198+ void $ createIndex ixs ixn
197199 putMapping ixn mn mapping
198200
199201