on master help sign in
Take index settings in es scribe options
d8e7d92Michael Xavier
katip-elasticsearch/katip-elasticsearch.cabal+5
@@ -84,3 +84,8 @@ test-suite test
84 , vector
84 , vector
85 , unordered-containers
85 , unordered-containers
86 , scientific
86 , 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
16 , essQueueSize
16 , essQueueSize
17 , essPoolSize
17 , essPoolSize
18 , essAnnotateTypes
18 , essAnnotateTypes
19+ , essIndexSettings
19 , defaultEsScribeCfg
20 , defaultEsScribeCfg
20 -- * Utilities
21 -- * Utilities
21 , mkDocId
22 , mkDocId
@@ -73,6 +74,7 @@ data EsScribeCfg = EsScribeCfg {
73 -- exposes a querying API, we will try to make deserialization and
74 -- exposes a querying API, we will try to make deserialization and
74 -- querying transparently remove the type annotations if this is
75 -- querying transparently remove the type annotations if this is
75 -- enabled.
76 -- enabled.
77+ , essIndexSettings :: IndexSettings
76 } deriving (Typeable)
78 } deriving (Typeable)
77
79
78
80
@@ -94,6 +96,7 @@ defaultEsScribeCfg = EsScribeCfg {
94 , essQueueSize = EsQueueSize 1000
96 , essQueueSize = EsQueueSize 1000
95 , essPoolSize = EsPoolSize 2
97 , essPoolSize = EsPoolSize 2
96 , essAnnotateTypes = False
98 , essAnnotateTypes = False
99+ , essIndexSettings = defaultIndexSettings
97 }
100 }
98
101
99
102
@@ -116,6 +119,12 @@ mkEsScribe cfg@EsScribeCfg {..} server ix mapping sev verb = do
116 }
119 }
117 endSig <- newEmptyMVar
120 endSig <- newEmptyMVar
118
121
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+
119 workers <- replicateM (unEsPoolSize essPoolSize) $ async $
128 workers <- replicateM (unEsPoolSize essPoolSize) $ async $
120 startWorker cfg env ix mapping q
129 startWorker cfg env ix mapping q
121
130
@@ -123,7 +132,6 @@ mkEsScribe cfg@EsScribeCfg {..} server ix mapping sev verb = do
123 takeMVar endSig
132 takeMVar endSig
124 atomically $ closeTBMQueue q
133 atomically $ closeTBMQueue q
125 mapM_ wait workers
134 mapM_ wait workers
126− closeManager mgr
127 putMVar endSig ()
135 putMVar endSig ()
128
136
129 let scribe = Scribe $ \ i ->
137 let scribe = Scribe $ \ i ->
katip-elasticsearch/test/Main.hs+9−7
@@ -2,6 +2,7 @@
2{-# LANGUAGE RecordWildCards #-}
2{-# LANGUAGE RecordWildCards #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE TemplateHaskell #-}
4{-# LANGUAGE TemplateHaskell #-}
5+{-# OPTIONS_GHC -fno-warn-orphans #-}
5module Main
6module Main
6 ( main
7 ( main
7 ) where
8 ) where
@@ -45,7 +46,7 @@ main = defaultMain $ testGroup "katip-elasticsearch"
45setupSearch :: IO (Scribe, IO ())
46setupSearch :: IO (Scribe, IO ())
46setupSearch = do
47setupSearch = do
47 bh recreateESSchema
48 bh recreateESSchema
48− mkEsScribe defaultEsScribeCfg { essAnnotateTypes = True } svr ixn mn DebugS V3
49+ mkEsScribe defaultEsScribeCfg { essAnnotateTypes = True, essIndexSettings = ixs } svr ixn mn DebugS V3
49
50
50
51
51-------------------------------------------------------------------------------
52-------------------------------------------------------------------------------
@@ -62,7 +63,7 @@ esTests setup = testGroup "elasticsearch scribe"
62 testCase "it flushes to elasticsearch" $ withTestLogging setup $ \done -> do
63 testCase "it flushes to elasticsearch" $ withTestLogging setup $ \done -> do
63 $(logT) (ExampleCtx True) mempty InfoS "A test message"
64 $(logT) (ExampleCtx True) mempty InfoS "A test message"
64 liftIO $ do
65 liftIO $ do
65− done
66+ void done
66 logs <- getLogs
67 logs <- getLogs
67 length logs @?= 1
68 length logs @?= 1
68 let l = head logs
69 let l = head logs
@@ -168,7 +169,8 @@ ixn = IndexName "katip-elasticsearch-tests"
168
169
169-------------------------------------------------------------------------------
170-------------------------------------------------------------------------------
170ixs :: IndexSettings
171ixs :: IndexSettings
171−ixs = defaultIndexSettings
172+ixs = defaultIndexSettings { indexShards = ShardCount 1
173+ , indexReplicas = ReplicaCount 1}
172
174
173-------------------------------------------------------------------------------
175-------------------------------------------------------------------------------
174mn :: MappingName
176mn :: MappingName
@@ -181,7 +183,7 @@ mapping = () -- ehhh
181
183
182
184
183-------------------------------------------------------------------------------
185-------------------------------------------------------------------------------
184−recreateESSchema :: BH IO Reply
186+recreateESSchema :: BH IO ()
185recreateESSchema = dropESSchema >> createESSchema
187recreateESSchema = dropESSchema >> createESSchema
186
188
187
189
@@ -191,9 +193,9 @@ dropESSchema = void $ deleteIndex ixn
191
193
192
194
193-------------------------------------------------------------------------------
195-------------------------------------------------------------------------------
194−createESSchema :: BH IO Reply
196+createESSchema :: BH IO ()
195−createESSchema = do
197+createESSchema = void $ do
196− createIndex ixs ixn
198+ void $ createIndex ixs ixn
197 putMapping ixn mn mapping
199 putMapping ixn mn mapping
198
200
199
201