on master help sign in
Zero pad date segments

We'll put this in a breaking version number change. At worse case this will give us split indices on the day the change goes live, but overall I think this is a good idea. All existing elasticsearch tooling seems to assume zero-padded month and day segments. Currently, tools like curator can only see katip indices from october-december and dates from the 10th onwards. Switching to zero padding means users can out of the box use tools like curator to rotate logs and we won't really have to build it into the library itself.

commitfc65653ca4088bb2a47173441c2d5ed15b2554f3 authorMichael Xavier <michael@michaelxavier.net> dateWed 7 Sep 2016, 09:48 (10 years ago) parent1f556c6
2 files changed+9−6
katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs+5−2 katip-elasticsearch/test/Main.hs+4−4
katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs+5−2
@@ -75,6 +75,7 @@ import qualified Data.UUID.V4 as UUID4
7575import Database.Bloodhound
7676import Network.HTTP.Client
7777import Network.HTTP.Types.Status
78+import Text.Printf (printf)
7879-------------------------------------------------------------------------------
7980import Katip.Core
8081import Katip.Scribes.ElasticSearch.Annotations
@@ -231,8 +232,10 @@ chooseIxn (IndexName ixn) p i =
231232
232233
233234-------------------------------------------------------------------------------
234−sis :: Show a => a -> IndexNameSegment
235−sis = IndexNameSegment . T.pack . show
235+sis :: Integral a => a -> IndexNameSegment
236+sis = IndexNameSegment . T.pack . fmt
237+ where
238+ fmt = printf "%02d" . toInteger
236239
237240
238241-------------------------------------------------------------------------------
katip-elasticsearch/test/Main.hs+4−4
@@ -100,8 +100,8 @@ esTests = testGroup "elasticsearch scribe"
100100 $(logT) (ExampleCtx True) mempty InfoS "tomorrow"
101101 liftIO $ do
102102 void done
103− todayLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-1-2")
104− tomorrowLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-1-3")
103+ todayLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-01-02")
104+ tomorrowLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-01-03")
105105 assertBool ("todayLogs has " <> show (length todayLogs) <> " items") (length todayLogs == 1)
106106 assertBool ("tomorrowLogs has " <> show (length tomorrowLogs) <> " items") (length tomorrowLogs == 1)
107107 let logToday = head todayLogs
@@ -118,8 +118,8 @@ esTests = testGroup "elasticsearch scribe"
118118 $(logT) (ExampleCtx True) mempty InfoS "tomorrow"
119119 liftIO $ do
120120 void done
121− todayLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-2-28") -- rounds back to previous sunday
122− tomorrowLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-3-6") -- is on sunday, so uses current date
121+ todayLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-02-28") -- rounds back to previous sunday
122+ tomorrowLogs <- getLogsByIndex (IndexName "katip-elasticsearch-tests-2016-03-06") -- is on sunday, so uses current date
123123 assertBool ("todayLogs has " <> show (length todayLogs) <> " items") (length todayLogs == 1)
124124 assertBool ("tomorrowLogs has " <> show (length tomorrowLogs) <> " items") (length tomorrowLogs == 1)
125125 let logToday = head todayLogs