Skip to content

RTView: history backup, MVP #4192

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

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cardano-tracer/cardano-tracer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ library
, bytestring
, cardano-git-rev
, cardano-node
, cassava
, cborg
, containers
, contra-tracer
Expand All @@ -137,6 +138,7 @@ library
, optparse-applicative
, ouroboros-network
, ouroboros-network-framework
, signal
, smtp-mail == 0.3.0.0
, snap-blaze
, snap-core
Expand All @@ -149,6 +151,7 @@ library
, trace-dispatcher
, trace-forward
, unordered-containers
, vector
, yaml

if os(linux)
Expand Down
20 changes: 14 additions & 6 deletions cardano-tracer/src/Cardano/Tracer/Handlers/RTView/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ runRTView
-> ConnectedNodes
-> AcceptedMetrics
-> SavedTraceObjects
-> BlockchainHistory
-> ResourcesHistory
-> TransactionsHistory
-> DataPointRequestors
-> Lock
-> EventsQueues
-> IO ()
runRTView TracerConfig{logging, network, hasRTView}
connectedNodes acceptedMetrics savedTO
chainHistory resourcesHistory txHistory
dpRequestors currentDPLock eventsQueues =
whenJust hasRTView $ \(Endpoint host port) -> do
-- Pause to prevent collision between "Listening"-notifications from servers.
Expand All @@ -65,12 +69,9 @@ runRTView TracerConfig{logging, network, hasRTView}
-- independently from RTView web-server. As a result, we'll be able to
-- show charts with historical data (where X axis is the time) for the
-- period when RTView web-page wasn't opened.
resourcesHistory <- initResourcesHistory
lastResources <- initLastResources
chainHistory <- initBlockchainHistory
txHistory <- initTransactionsHistory
eraSettings <- initErasSettings
errors <- initErrors
lastResources <- initLastResources
eraSettings <- initErasSettings
errors <- initErrors

void . sequenceConcurrently $
[ UI.startGUI (config host port certFile keyFile) $
Expand All @@ -97,6 +98,13 @@ runRTView TracerConfig{logging, network, hasRTView}
lastResources
chainHistory
txHistory
, runHistoricalBackup
connectedNodes
chainHistory
resourcesHistory
txHistory
dpRequestors
currentDPLock
, runEraSettingsUpdater
connectedNodes
eraSettings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}

module Cardano.Tracer.Handlers.RTView.State.Historical
( BlockchainHistory (..)
, DataName (..)
, History
, HistoricalPoint
, HistoricalPoints
, POSIXTime
, ResourcesHistory (..)
, TransactionsHistory (..)
Expand All @@ -20,14 +23,19 @@ module Cardano.Tracer.Handlers.RTView.State.Historical

import Control.Concurrent.STM (atomically)
import Control.Concurrent.STM.TVar (TVar, modifyTVar', newTVarIO, readTVarIO)
import Control.Monad (mzero)
import qualified Data.ByteString.Char8 as BSC
import Data.Csv (FromField (..), ToField (..))
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import Data.Set (Set)
import qualified Data.Set as S
import Data.Text (Text)
import Data.Text (Text, isInfixOf)
import Data.Text.Encoding (decodeUtf8)
import Data.Text.Read (decimal, double)
import Data.Time.Clock (UTCTime)
import Data.Word (Word64)
import Text.Printf (printf)

import Cardano.Tracer.Handlers.RTView.Update.Utils
import Cardano.Tracer.Types (NodeId)
Expand Down Expand Up @@ -73,6 +81,17 @@ instance Num ValueH where

type HistoricalPoint = (POSIXTime, ValueH)

instance FromField ValueH where
parseField s =
let t = decodeUtf8 s in
if "." `isInfixOf` t
then either (const mzero) (return . ValueD . fst) $ double t
else either (const mzero) (return . ValueI . fst) $ decimal t

instance ToField ValueH where
toField (ValueI i) = toField i
toField (ValueD d) = BSC.pack $ printf "%.3f" d

type HistoricalPoints = Set HistoricalPoint

-- | Historical points for particular data.
Expand Down Expand Up @@ -104,7 +123,7 @@ data DataName
| TxsProcessedNumData
| MempoolBytesData
| TxsInMempoolData
deriving (Eq, Ord)
deriving (Eq, Ord, Read, Show)

type HistoricalData = Map DataName HistoricalPoints
type History = TVar (Map NodeId HistoricalData)
Expand Down
15 changes: 13 additions & 2 deletions cardano-tracer/src/Cardano/Tracer/Handlers/RTView/System.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{-# LANGUAGE CPP #-}

module Cardano.Tracer.Handlers.RTView.System
( getPathToChartsConfig
( getPathToBackupDir
, getPathToChartsConfig
, getPathToThemeConfig
, getPathsToNotificationsSettings
, getPathsToSSLCerts
Expand Down Expand Up @@ -59,6 +60,16 @@ getPathsToNotificationsSettings = do
getPathToConfigDir :: IO FilePath
getPathToConfigDir = do
configDir <- D.getXdgDirectory D.XdgConfig ""
let pathToRTViewConfigDir = configDir </> "cardano-rt-view"
let pathToRTViewConfigDir = configDir </> rtViewRootDir
D.createDirectoryIfMissing True pathToRTViewConfigDir
return pathToRTViewConfigDir

getPathToBackupDir :: IO FilePath
getPathToBackupDir = do
dataDir <- D.getXdgDirectory D.XdgData ""
let pathToRTViewBackupDir = dataDir </> rtViewRootDir </> "backup"
D.createDirectoryIfMissing True pathToRTViewBackupDir
return pathToRTViewBackupDir

rtViewRootDir :: FilePath
rtViewRootDir = "cardano-rt-view"
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ readSavedChartsSettings = liftIO $
[ (chartId, ChartSettings defaultTimeRangeInS defaultUpdatePeriodInS)
| chartId <- chartsIds
]
defaultTimeRangeInS = 0 -- All time
defaultTimeRangeInS = 21600 -- Last 6 hours
defaultUpdatePeriodInS = 15

changeChartsToLightTheme :: UI ()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}

module Cardano.Tracer.Handlers.RTView.UI.HTML.About
( mkAboutInfo
) where

import Data.List.Extra (lower)
import qualified Data.Text as T
import Data.Version (showVersion)
import qualified Graphics.UI.Threepenny as UI
import Graphics.UI.Threepenny.Core
import System.Directory (makeAbsolute)
import System.Environment (getArgs)
import System.Info.Extra (isMac, isWindows)
import System.Info (os)

import Cardano.Git.Rev (gitRev)

Expand Down Expand Up @@ -80,9 +80,7 @@ mkAboutInfo = do
, image "rt-view-href-icon" externalLinkSVG
]
, UI.p #. "mb-3" #+
[ string $ if | isWindows -> "Windows"
| isMac -> "macOS"
| otherwise -> "Linux"
[ string currentOS
]
, UI.p #. "mb-3" #+
[ UI.div #. "field has-addons" #+
Expand All @@ -109,3 +107,14 @@ mkAboutInfo = do
return info
where
commit = T.unpack . T.take 7 $ gitRev

currentOS :: String
currentOS =
case lower os of
"darwin" -> "macOS"
"mingw32" -> "Windows"
"linux" -> "Linux"
"freebsd" -> "FreeBSD"
"netbsd" -> "NetBSD"
"openbsd" -> "OpenBSD"
_ -> "Unknown"
Loading