Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Chain Indexer Performance #738

Merged
merged 14 commits into from
Nov 7, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import Control.Concurrent.STM (atomically)
import Control.Monad (join)
import Control.Monad.Event.Class (Inject, MonadEvent)
import Data.ByteString (ByteString)
import Data.Int (Int64)
import Data.Maybe (catMaybes)
import Data.String (fromString)
import Data.Text (Text)
import Data.Text.Encoding (decodeUtf8)
import Data.Time (NominalDiffTime)
import Language.Marlowe.Runtime.ChainIndexer.Database (DatabaseQueries (..))
Expand Down Expand Up @@ -142,14 +144,32 @@ renderDatabaseSelectorOTel dbName dbUser host port = \case
, renderField = \case
SqlStatement sql -> [("db.statement", toAttribute $ decodeUtf8 sql)]
Parameters params -> [("db.parameters", toAttribute params)]
Operation operation ->
catMaybes
[ Just ("db.system", "postgresql")
, ("db.user",) . toAttribute . decodeUtf8 <$> dbUser
, ("net.peer.name",) . toAttribute . decodeUtf8 <$> host
, ("net.peer.port",) . toAttribute . decodeUtf8 <$> port
, ("db.name",) . toAttribute . decodeUtf8 <$> dbName
, Just ("net.transport", "ip_tcp")
, Just ("db.operation", toAttribute operation)
]
Operation operation -> ("db.operation", toAttribute operation) : standardAttributes
}
CopyBlocks -> renderCopy "block"
CopyTxs -> renderCopy "tx"
CopyTxOuts -> renderCopy "txOut"
CopyTxIns -> renderCopy "txIn"
CopyAssetOuts -> renderCopy "assetOut"
CopyAssetMints -> renderCopy "assetMint"
where
standardAttributes =
catMaybes
[ Just ("db.system", "postgresql")
, ("db.user",) . toAttribute . decodeUtf8 <$> dbUser
, ("net.peer.name",) . toAttribute . decodeUtf8 <$> host
, ("net.peer.port",) . toAttribute . decodeUtf8 <$> port
, ("db.name",) . toAttribute . decodeUtf8 <$> dbName
, Just ("net.transport", "ip_tcp")
]
renderCopy :: Text -> OTelRendered Int64
renderCopy table =
OTelRendered
{ eventName = "COPY chain." <> table
, eventKind = Internal
, renderField = \rows ->
standardAttributes
<> [ ("db.statement", toAttribute $ "COPY chain." <> table <> " FROM STDIN WITH (FORMAT 'csv')")
, ("db.rowsAffected", toAttribute rows)
]
}
Loading