Commits

Stefan Saasen committed a35f5f4

Fix compiler and hlint warnings, enable -Werror

  • Participants
  • Parent commits 31d8ad9

Comments (0)

Files changed (4)

File logparser/logparser.cabal

                             aeson
     ghc-options:
                             -Wall
-                            -- -Werror
+                            -Werror
                             -fno-warn-unused-do-bind
                             -rtsopts
                             -O2

File logparser/src/Main.hs

-{-# LANGUAGE OverloadedStrings, DeriveDataTypeable, RecordWildCards #-}
+{-# LANGUAGE OverloadedStrings, DeriveDataTypeable #-}
 module Main where
 
 import Stash.Log.Analyser hiding (ProtocolStats)
 
 
 run :: LogParser -> IO ()
-run (MaxConn files)                     = stream plotDataConcurrentConnHour printPlotDataConcurrentConn newRunConfig "printPlotDataConcurrentConn" files
-run (CountRequests files)               = stream countRequestLines parseAndPrint newRunConfig "countRequestLines" files
-run (GitOperations files progressive)   = stream analyseGitOperations printPlotDataGitOps (RunConfig progressive) "printPlotDataGitOps" files
-run (GitDurations files progressive)    = stream gitRequestDuration printGitRequestDurations (RunConfig progressive) "gitRequestDuration" files
-run (ProtocolStats files)               = stream protocolStatsByHour printProtocolData newRunConfig "printProtocolData" files
-run (Count files)                       = printCountLines countLines files
-run (DebugParser files progressive)     = stream showLines parseAndPrint newRunConfig "showLines" files
+run (MaxConn files')                     = stream plotDataConcurrentConnHour printPlotDataConcurrentConn newRunConfig "printPlotDataConcurrentConn" files'
+run (CountRequests files')               = stream countRequestLines print newRunConfig "countRequestLines" files'
+run (GitOperations files' progressive')  = stream analyseGitOperations printPlotDataGitOps (RunConfig progressive') "printPlotDataGitOps" files'
+run (GitDurations files' progressive')   = stream gitRequestDuration printGitRequestDurations (RunConfig progressive') "gitRequestDuration" files'
+run (ProtocolStats files')               = stream protocolStatsByHour printProtocolData newRunConfig "printProtocolData" files'
+run (Count files')                       = printCountLines countLines files'
+run (DebugParser files' progressive')    = stream showLines print (RunConfig progressive') "showLines" files'
 
 stream :: (Input -> a) -> (a -> IO ()) -> RunConfig -> String -> [FilePath] -> IO ()
-stream analyze output runConfig name files = output =<< (liftM analyze $ readLogFiles runConfig name files)
+stream analyze output runConfig name' files' = output =<< liftM analyze (readLogFiles runConfig name' files')
 
 main :: IO ()
 main = do

File logparser/src/Stash/Log/Input.hs

 isFileNewer :: FilePath -> Date -> Bool
 isFileNewer file date = (Just $ base (unpack date)) <= extractFileInfo file
         where base (year':month':day':_) = FileInfo year' month' day' 0
-              unpack                  = split "-"
+              base _                     = FileInfo "" "" "" 0
+              unpack                     = split "-"
 
 -- | Sort the logfiles by date and log file sequence number
 -- The logfile naming scheme is: "atlassian-stash-access-2012-11-29.0.log(.bz2)"
           logFilePred logFileName1 logFileName2 = sortPred (extractSortPairs logFileName1) (extractSortPairs logFileName2)
           extractSortPairs path = maybe ("9999", 0) asPair $ extractFileInfo path
           asPair (FileInfo year' month' day' counter') = (year' ++ "-" ++ month' ++ "-" ++ day', counter')
-          asPair _                                     = ("", 0)
 
 -- | Try to extract the FileInfo out of the given file. This function assumes
 -- that the given file follows the naming scheme for the access log archive
                                _                     -> Nothing
 
 extractFileDateInfo :: FilePath -> Maybe FileDateInfo
-extractFileDateInfo path = fmap (FileDateInfo) $ extractFileInfo path
+extractFileDateInfo path = fmap FileDateInfo $ extractFileInfo path
 
 -- | Read the list of files and return a list of lines. The input files will be
 -- filtered using the function (FilePath -> Bool)
           gr                = groupBy (\a b -> fromMaybe False $ liftM2 (==) (extractFileDateInfo a) (extractFileDateInfo b))
 
 dropUntilDate :: Date -> [FilePath] -> [FilePath]
-dropUntilDate date files = dropWhile (\f -> not $ isFileNewer f date) files
+dropUntilDate date = dropWhile (\ f -> not $ isFileNewer f date)
 
 -- =================================================================================
 
         return $ (decode json :: Maybe (M.Map String String)) >>= M.lookup key
 
 today :: IO (Integer,Int,Int) -- :: (year,month,day)
-today = getCurrentTime >>= return . toGregorian . utctDay
+today = liftM (toGregorian . utctDay) getCurrentTime
 
 readLogFiles :: RunConfig -> String -> [FilePath] -> IO [L.ByteString]
 readLogFiles cfg key path = do
         date <- readConfig key
         now <- today
         let progressive = cfgProgressive cfg
-        trace ("date: " ++ show date ++ " key: " ++ key ++ " now: " ++ show now) (if progressive && (isJust date) then
-                toLines $ (dropUntilDate $ fromJust date) $ filterLastDay path
-            else
-                toLines path
-                )
+        trace ("date: " ++ show date ++ " key: " ++ key ++ " now: " ++ show now) toLines
+            (if progressive && isJust date then dropUntilDate (fromJust date) $ filterLastDay path else path)

File logparser/src/Stash/Log/Output.hs

 , printGitRequestDurations
 , printPlotDataConcurrentConn
 , printPlotDataGitOps
-, parseAndPrint
 , printCountLines
 ) where
 
 
 import qualified Data.ByteString.Lazy.Char8 as L
 import qualified Data.ByteString.Char8 as S
-import qualified Data.Map as M
-import Control.Monad (liftM)
-import Control.Monad.Reader
-import Data.Maybe (isJust, fromJust)
 import Stash.Log.Parser
 import Stash.Log.Analyser
 import Stash.Log.GitOpsAnalyser
 import Stash.Log.Input
 import Text.Printf (printf)
-import Debug.Trace
 
 printProtocolData :: [ProtocolStats] -> IO ()
 printProtocolData plotData = do
         mapM_ (\(RequestDurationStat date clientIp [cm,fm,sm,pm,rm] [c,f,s,p,r] username)
                 -> printf "%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%s|%s\n" (show date) c cm f fm s sm p pm r rm clientIp (S.unpack username)) plotData
 
-parseAndPrint :: (Show a) => a -> IO ()
-parseAndPrint d = print d
-
 printCountLines :: (Show a) => (L.ByteString -> a) -> [FilePath] -> IO ()
 printCountLines f path = print . f =<< readFiles path