Commits

Stefan Saasen committed 1c1ace5

Change protocolCount to only apply to git operations and to only count the responses.

Comments (0)

Files changed (3)

logparser/src/Stash/Log/Analyser.hs

 , ProtocolStats(..)
 , DateValuePair(..)
 , maxConcurrent
-, protocolCount
 , plotDataConcurrentConnMinute
 , plotDataConcurrentConnHour
 , protocolStatsByHour
 , showLines
 ) where
 
-import qualified Data.ByteString.Char8 as S
 import qualified Data.ByteString.Lazy.Char8 as L
-import qualified Data.HashMap.Strict as M
 import Data.List (foldl', groupBy)
-import Data.Maybe (mapMaybe)
 import Data.Function (on)
 import Text.Printf (printf)
 import Stash.Log.Parser
 maxConcurrent = countLinesWith (\x acc -> let conn = getConcurrentRequests $ getRequestId x
                                           in if conn >= acc then conn else acc)
 
-protocolCount :: Input -> [(S.ByteString,Integer)]
-protocolCount = M.toList . foldl' count' M.empty . mapMaybe parseLogLine
-        where
-            count' acc logLine = let !proto = getProtocol logLine
-                                 in M.insertWith (+) proto 1 acc
-
 isSsh :: LogLine -> Bool
 isSsh logLine = getProtocol logLine == "ssh"
 

logparser/src/Stash/Log/GitOpsAnalyser.hs

 , RequestDurationStat(..)
 , cloneRequestDuration
 , isRefAdvertisement
+, protocolCount
 ) where
 
 import qualified Data.ByteString.Char8 as S
+import qualified Data.HashMap.Strict as M
 import Data.String.Utils (split)
 import Data.List (foldl', groupBy)
-import Data.Maybe (isJust)
+import Data.Maybe (isJust, mapMaybe)
 import Data.Function (on)
 import Text.Printf (printf)
 import Stash.Log.Parser
 collectRequestDurations rawLines p = map m $ filter f $ parseLogLines rawLines
         where clientIp line = head $ split "," (S.unpack $ getRemoteAdress line)
               ops           = [isClone, isFetch, isShallowClone, isPush, isRefAdvertisement]
-              f line        = isOutgoingLogLine line && p line && (or $ map (\g -> g line) ops)
+              f line        = isOutgoingLogLine line && p line && isGitOperation line
               m line        =  let  duration    = getRequestDuration line
                                     zero        = replicate 5 0
                                     inc op      = if op line then (+duration) else id
                                     !hits'      = zipWith id hitOps hits
                                 in GitOperationStats date' misses' hits'
 
+protocolCount :: Input -> [(S.ByteString,Integer)]
+protocolCount line = M.toList $ foldl' count' M.empty (filter isOutgoingLogLine (filter isGitOperation $ mapMaybe parseLogLine line))
+        where
+            count' acc logLine = let !proto = getProtocol logLine
+                                 in M.insertWith (+) proto 1 acc
+
+
 -- =================================================================================
 --                                Predicates
 -- =================================================================================
 
+isGitOperation :: LogLine -> Bool
+isGitOperation line = (or $ map (\g -> g line) ops)
+            where ops = [isClone, isFetch, isShallowClone, isPush, isRefAdvertisement]
+
 -- As of 1.1.2 of the clone cache plugin, refs are explicitly listed in the
 -- labels field, most of the data we have does _not_ have that information though
 isRefAdvertisement :: LogLine -> Bool

logparser/tests/Properties.hs

 
 test_protocolCount = H.assertEqual
     "Should count the protocol correctly"
-    [("https", 6), ("ssh", 2)]
+    [("https", 3), ("ssh", 1)]
     (protocolCount dataLogLines)
 
 ------------------------------------------------------------------------
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.