Commits

Stefan Saasen committed 75e6faf

Add support for the new label format with separate 'shallow' information

Instead of the string "shallow clone", the words "shallow" and "clone" are now
listed separately (i.e. "shallow, clone").

This change introduces support for the new comma separated format while still
supporting the old format.

Comments (0)

Files changed (2)

logparser/src/Stash/Log/GitOpsAnalyser.hs

 , RepositoryStat(..)
 , gitRequestDuration
 , isRefAdvertisement
+, isClone
+, isShallowClone
 , protocolStatsByHour
 , ProtocolStats(..)
 , repositoryStats
                 path        = getPath action
                 method      = getMethod action
                 refAdvertisement line
-                            | isSsh line        = isRefs line || not (any (inLabel line) ["clone", "fetch", "shallow clone"])
+                            | isSsh line        = isRefs line || not (any ($ line) [isClone, isFetch, isShallowClone])
                             | isHttp line       = ".git/info/refs" `S.isSuffixOf` path && "GET" == method
                             | otherwise         = False
 
-isCacheHit :: LogLine -> Bool
-isCacheHit logLine = inLabel logLine "cache:hit"
+isCacheHit, isCacheMiss, isFetch, isClone, isShallowClone, isPush, isRefs, isShallow :: LogLine -> Bool
+isCacheHit = inLabel "cache:hit"
 
-isCacheMiss :: LogLine -> Bool
-isCacheMiss = not . flip inLabel "cache:hit" -- treat as cache miss if the cache:* label is missing
+isCacheMiss = not . inLabel "cache:hit" -- treat as cache miss if the cache:* label is missing
 
-isFetch :: LogLine -> Bool
-isFetch logLine = inLabel logLine "fetch" && not (inLabel logLine "clone" || inLabel logLine "shallow clone")
+isFetch logLine = inLabel "fetch" logLine && not (isClone logLine || isShallowClone logLine)
 
-isClone :: LogLine -> Bool
-isClone logLine = inLabel logLine "clone"
+isClone line = inLabel "clone" line && not (isShallow line)
 
-isShallowClone :: LogLine -> Bool
-isShallowClone logLine = inLabel logLine "shallow clone"
+isShallowClone logLine = inLabel "shallow clone" logLine || (
+            inLabel "clone" logLine && isShallow logLine)
 
-isPush :: LogLine -> Bool
-isPush logLine = inLabel logLine "push" || isPushAction (getAction logLine)
+isPush logLine = inLabel "push" logLine || isPushAction (getAction logLine)
     where isPushAction (HttpAction method path) =
                     ".git/git-receive-pack" `S.isSuffixOf` path && "POST" == method
           isPushAction (SshAction method _)  =
                     "git-receive-pack" `S.isInfixOf` method
 
-isRefs :: LogLine -> Bool
-isRefs logLine = inLabel logLine "refs"
+isRefs = inLabel "refs"
 
-inLabel :: LogLine -> String -> Bool
-inLabel logLine name =  let labels = getLabels logLine
+isShallow = inLabel "shallow"
+
+inLabel :: String -> LogLine -> Bool
+inLabel name logLine =  let labels = getLabels logLine
                         in name `elem` labels
 
 cachedOperation :: (LogLine -> Bool) -> LogLine -> Bool

logparser/tests/Properties.hs

 parsedLogLine9 = parseLogLine inputLine
     where inputLine = "172.16.3.7 | ssh | o357x407998x2 | atlaseye_user | 2013-03-05 05:57:20,505 | SSH - git-receive-pack '/CONF/teamcal.git' | - | - | 145 | ofq0l6 | "
 
+parsedLogLineShallowNegotiation = parseLogLine inputLine
+    where inputLine = "23.23.30.99,172.24.4.5,127.0.0.1 | https | o1439x1423920x69 | bamboo_user | 2013-08-22 23:59:57,763 | \"POST /scm/JIRA/servicedesk.git/git-upload-pack HTTP/1.1\" | \"\" \"git/1.7.9.5\" | shallow negotiation, cache:hit | 70 | q09lhc |"
+
+parsedLogLineShallowCloneLabelNew = parseLogLine inputLine
+    where inputLine = "23.23.30.99,172.24.4.5,127.0.0.1 | https | o1439x1423920x69 | bamboo_user | 2013-08-22 23:59:57,763 | \"POST /scm/JIRA/servicedesk.git/git-upload-pack HTTP/1.1\" | \"\" \"git/1.7.9.5\" | shallow, clone, cache:hit | 70 | q09lhc | "
+
+parsedLogLineShallowCloneLabelOld = parseLogLine inputLine
+    where inputLine = "23.23.30.99,172.24.4.5,127.0.0.1 | https | o1439x1423920x69 | bamboo_user | 2013-08-22 23:59:57,763 | \"POST /scm/JIRA/servicedesk.git/git-upload-pack HTTP/1.1\" | \"\" \"git/1.7.9.5\" | shallow clone, cache:hit | 70 | q09lhc | "
+
+
 test_parseLogEntryDate = H.assertEqual
     "Should parse the date correctly"
     (LogDate 2012 8 22 18 32 08 505)
     ["clone"]
     (getLabels $ fromJust parsedLogLine5)
 
+test_logLineParseLabelsShallowCloneOld = H.assertBool
+    "Should parse the old 'shallow clone' label correctly"
+    (isShallowClone $ fromJust parsedLogLineShallowCloneLabelOld)
+
+test_logLineParseLabelsShallowCloneNew = H.assertBool
+    "Should parse the new 'shallow, clone' labels correctly"
+    (isShallowClone $ fromJust parsedLogLineShallowCloneLabelNew)
+
+test_logLineParseLabelsCloneOld = H.assertBool
+    "Should parse the old 'shallow clone' label correctly"
+    (not $ isClone $ fromJust parsedLogLineShallowCloneLabelOld)
+
+test_logLineParseLabelsCloneNew = H.assertBool
+    "Should parse the new 'shallow, clone' labels correctly"
+    (not $ isClone $ fromJust parsedLogLineShallowCloneLabelNew)
+
 test_logLineParseDuration = H.assertEqual
     "Should parse the duration correctly"
     (Just 117)
         ,testCase "analyser/isRefAdvertisement ignore clones ssh" test_identifyRefAdvertisement_SSHClone
         ,testCase "analyser/isRefAdvertisement http action" test_identifyRefAdvertisement_HttpAction
         ,testCase "analyser/isRefAdvertisement http label" test_identifyRefAdvertisement_HttpLabel
+        ,testCase "analyser/isShallowClone (shallow clone)" test_logLineParseLabelsShallowCloneOld
+        ,testCase "analyser/isShallowClone (shallow, clone)" test_logLineParseLabelsShallowCloneNew
+        ,testCase "analyser/not isClone (shallow clone)" test_logLineParseLabelsCloneNew
+        ,testCase "analyser/not isClone (shallow, clone)" test_logLineParseLabelsCloneOld
       ],
       testGroup "Files"
       [