mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 02:11:53 +00:00
make metrics specifc to apps
This commit is contained in:
@@ -38,11 +38,10 @@ createAppVersion sId VersionInfo{..} = do
|
|||||||
versionInfoVersion
|
versionInfoVersion
|
||||||
versionInfoReleaseNotes
|
versionInfoReleaseNotes
|
||||||
|
|
||||||
createMetric :: MonadIO m => Maybe (Key SApp) -> Maybe (Key Version) -> AppIdentifier -> ReaderT SqlBackend m ()
|
createMetric :: MonadIO m => Key SApp -> Key Version -> ReaderT SqlBackend m ()
|
||||||
createMetric appId versionId event = do
|
createMetric appId versionId = do
|
||||||
time <- liftIO $ getCurrentTime
|
time <- liftIO $ getCurrentTime
|
||||||
insert_ $ Metric
|
insert_ $ Metric
|
||||||
time
|
time
|
||||||
appId
|
appId
|
||||||
versionId
|
versionId
|
||||||
event
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ getApp rootDir ext@(Extension appId) = do
|
|||||||
av <- runDB $ createAppVersion appKey' versionInfo
|
av <- runDB $ createAppVersion appKey' versionInfo
|
||||||
pure (appKey', av)
|
pure (appKey', av)
|
||||||
Just v -> pure (appKey', entityKey v)
|
Just v -> pure (appKey', entityKey v)
|
||||||
runDB $ createMetric (Just appKey) (Just versionKey) appId'
|
runDB $ createMetric appKey versionKey
|
||||||
sz <- liftIO $ fileSize <$> getFileStatus filePath
|
sz <- liftIO $ fileSize <$> getFileStatus filePath
|
||||||
addHeader "Content-Length" (show sz)
|
addHeader "Content-Length" (show sz)
|
||||||
respondSource typePlain $ CB.sourceFile filePath .| awaitForever sendChunkBS
|
respondSource typePlain $ CB.sourceFile filePath .| awaitForever sendChunkBS
|
||||||
|
|||||||
@@ -30,16 +30,15 @@ Version
|
|||||||
appId SAppId
|
appId SAppId
|
||||||
number AppVersion
|
number AppVersion
|
||||||
releaseNotes Text
|
releaseNotes Text
|
||||||
UniqueNumber number
|
UniqueBin appId number
|
||||||
deriving Eq
|
deriving Eq
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
|
|
||||||
Metric
|
Metric
|
||||||
createdAt UTCTime
|
createdAt UTCTime
|
||||||
appId SAppId Maybe default=null
|
appId SAppId
|
||||||
version VersionId Maybe default=null
|
version VersionId
|
||||||
event Text
|
|
||||||
deriving Eq
|
deriving Eq
|
||||||
deriving Show
|
deriving Show
|
||||||
|]
|
|]
|
||||||
|
|||||||
@@ -38,8 +38,9 @@ spec = do
|
|||||||
setUrl ("/apps/bitcoind.s9pk?spec=0.18.1" :: Text)
|
setUrl ("/apps/bitcoind.s9pk?spec=0.18.1" :: Text)
|
||||||
statusIs 200
|
statusIs 200
|
||||||
apps <- runDBtest $ selectList [SAppAppId ==. "bitcoind"] []
|
apps <- runDBtest $ selectList [SAppAppId ==. "bitcoind"] []
|
||||||
metrics <- runDBtest $ selectList [MetricEvent ==. "bitcoind"] []
|
|
||||||
assertEq "app should exist" (length apps) 1
|
assertEq "app should exist" (length apps) 1
|
||||||
|
let app = fromJust $ head apps
|
||||||
|
metrics <- runDBtest $ selectList [MetricAppId ==. entityKey app] []
|
||||||
assertEq "metric should exist" (length metrics) 1
|
assertEq "metric should exist" (length metrics) 1
|
||||||
describe "GET /apps/:appId with existing version spec for cups" $
|
describe "GET /apps/:appId with existing version spec for cups" $
|
||||||
withApp $ it "creates app and metric records" $ do
|
withApp $ it "creates app and metric records" $ do
|
||||||
@@ -48,9 +49,9 @@ spec = do
|
|||||||
setUrl ("/apps/cups.s9pk?spec=0.2.1" :: Text)
|
setUrl ("/apps/cups.s9pk?spec=0.2.1" :: Text)
|
||||||
statusIs 200
|
statusIs 200
|
||||||
apps <- runDBtest $ selectList [SAppAppId ==. "cups"] []
|
apps <- runDBtest $ selectList [SAppAppId ==. "cups"] []
|
||||||
metrics <- runDBtest $ selectList [MetricEvent ==. "cups"] []
|
|
||||||
assertEq "app should exist" (length apps) 1
|
assertEq "app should exist" (length apps) 1
|
||||||
assertEq "metric should exist" (length metrics) 1
|
|
||||||
let app = fromJust $ head apps
|
let app = fromJust $ head apps
|
||||||
|
metrics <- runDBtest $ selectList [MetricAppId ==. entityKey app] []
|
||||||
|
assertEq "metric should exist" (length metrics) 1
|
||||||
version <- runDBtest $ selectList [VersionAppId ==. entityKey app] []
|
version <- runDBtest $ selectList [VersionAppId ==. entityKey app] []
|
||||||
assertEq "version should exist" (length version) 1
|
assertEq "version should exist" (length version) 1
|
||||||
Reference in New Issue
Block a user