PLAT-75: Log uncompressed_response_size

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5827
GitOrigin-RevId: c98e5075f38737d9eb9cf467a62032ca5984304e
This commit is contained in:
Brandon Simmons 2022-09-13 11:35:58 -04:00 committed by hasura-bot
parent 3fd5ea3965
commit 82f129ff7c
2 changed files with 12 additions and 4 deletions

View File

@ -61,6 +61,7 @@ import Control.Monad.Trans.Managed (ManagedT (..), allocate_)
import Control.Retry qualified as Retry import Control.Retry qualified as Retry
import Data.Aeson qualified as A import Data.Aeson qualified as A
import Data.ByteString.Char8 qualified as BC import Data.ByteString.Char8 qualified as BC
import Data.ByteString.Lazy qualified as BL
import Data.ByteString.Lazy.Char8 qualified as BLC import Data.ByteString.Lazy.Char8 qualified as BLC
import Data.Environment qualified as Env import Data.Environment qualified as Env
import Data.FileEmbed (makeRelativeToProject) import Data.FileEmbed (makeRelativeToProject)
@ -1028,10 +1029,10 @@ instance (MonadIO m) => HttpLog (PGMetadataStorageAppT m) where
mkHttpLog $ mkHttpLog $
mkHttpErrorLogContext userInfoM loggingSettings reqId waiReq req qErr Nothing Nothing headers mkHttpErrorLogContext userInfoM loggingSettings reqId waiReq req qErr Nothing Nothing headers
logHttpSuccess logger loggingSettings userInfoM reqId waiReq reqBody _response compressedResponse qTime cType headers (CommonHttpLogMetadata rb batchQueryOpLogs, ()) = logHttpSuccess logger loggingSettings userInfoM reqId waiReq reqBody response compressedResponse qTime cType headers (CommonHttpLogMetadata rb batchQueryOpLogs, ()) =
unLogger logger $ unLogger logger $
mkHttpLog $ mkHttpLog $
mkHttpAccessLogContext userInfoM loggingSettings reqId waiReq reqBody compressedResponse qTime cType headers rb batchQueryOpLogs mkHttpAccessLogContext userInfoM loggingSettings reqId waiReq reqBody (BL.length response) compressedResponse qTime cType headers rb batchQueryOpLogs
instance (Monad m) => MonadExecuteQuery (PGMetadataStorageAppT m) where instance (Monad m) => MonadExecuteQuery (PGMetadataStorageAppT m) where
cacheLookup _ _ _ _ = pure ([], Nothing) cacheLookup _ _ _ _ = pure ([], Nothing)

View File

@ -381,6 +381,8 @@ data OperationLog = OperationLog
{ olRequestId :: !RequestId, { olRequestId :: !RequestId,
olUserVars :: !(Maybe SessionVariables), olUserVars :: !(Maybe SessionVariables),
olResponseSize :: !(Maybe Int64), olResponseSize :: !(Maybe Int64),
-- | Response size before compression
olUncompressedResponseSize :: !Int64,
-- | Request IO wait time, i.e. time spent reading the full request from the socket. -- | Request IO wait time, i.e. time spent reading the full request from the socket.
olRequestReadTime :: !(Maybe Seconds), olRequestReadTime :: !(Maybe Seconds),
-- | Service time, not including request IO wait time. -- | Service time, not including request IO wait time.
@ -455,6 +457,8 @@ mkHttpAccessLogContext ::
RequestId -> RequestId ->
Wai.Request -> Wai.Request ->
(BL.ByteString, Maybe Value) -> (BL.ByteString, Maybe Value) ->
-- | Size of response body, before compression
Int64 ->
BL.ByteString -> BL.ByteString ->
Maybe (DiffTime, DiffTime) -> Maybe (DiffTime, DiffTime) ->
Maybe CompressionType -> Maybe CompressionType ->
@ -462,7 +466,7 @@ mkHttpAccessLogContext ::
RequestMode -> RequestMode ->
Maybe (GH.GQLBatchedReqs GQLBatchQueryOperationLog) -> Maybe (GH.GQLBatchedReqs GQLBatchQueryOperationLog) ->
HttpLogContext HttpLogContext
mkHttpAccessLogContext userInfoM loggingSettings reqId req (_, parsedReq) res mTiming compressTypeM headers batching queryLogMetadata = mkHttpAccessLogContext userInfoM loggingSettings reqId req (_, parsedReq) uncompressedResponseSize res mTiming compressTypeM headers batching queryLogMetadata =
let http = let http =
HttpInfoLog HttpInfoLog
{ hlStatus = status, { hlStatus = status,
@ -478,6 +482,7 @@ mkHttpAccessLogContext userInfoM loggingSettings reqId req (_, parsedReq) res mT
{ olRequestId = reqId, { olRequestId = reqId,
olUserVars = _uiSession <$> userInfoM, olUserVars = _uiSession <$> userInfoM,
olResponseSize = respSize, olResponseSize = respSize,
olUncompressedResponseSize = uncompressedResponseSize,
olRequestReadTime = Seconds . fst <$> mTiming, olRequestReadTime = Seconds . fst <$> mTiming,
olQueryExecutionTime = Seconds . snd <$> mTiming, olQueryExecutionTime = Seconds . snd <$> mTiming,
olRequestMode = batching, olRequestMode = batching,
@ -535,11 +540,13 @@ mkHttpErrorLogContext userInfoM loggingSettings reqId waiReq (reqBody, parsedReq
hlCompression = compressTypeM, hlCompression = compressTypeM,
hlHeaders = headers hlHeaders = headers
} }
responseSize = BL.length $ encode err
op = op =
OperationLog OperationLog
{ olRequestId = reqId, { olRequestId = reqId,
olUserVars = _uiSession <$> userInfoM, olUserVars = _uiSession <$> userInfoM,
olResponseSize = Just $ BL.length $ encode err, olResponseSize = Just responseSize,
olUncompressedResponseSize = responseSize,
olRequestReadTime = Seconds . fst <$> mTiming, olRequestReadTime = Seconds . fst <$> mTiming,
olQueryExecutionTime = Seconds . snd <$> mTiming, olQueryExecutionTime = Seconds . snd <$> mTiming,
olQuery = if (isQueryIncludedInLogs (hlPath http) loggingSettings) then parsedReq else Nothing, olQuery = if (isQueryIncludedInLogs (hlPath http) loggingSettings) then parsedReq else Nothing,