|
| 1 | +{-# LANGUAGE CPP #-} |
| 2 | +{-# LANGUAGE OverloadedStrings #-} |
| 3 | +{-# LANGUAGE RecordWildCards #-} |
| 4 | +{-# LANGUAGE TemplateHaskell #-} |
| 5 | + |
| 6 | +{-# OPTIONS_GHC -Wno-name-shadowing #-} |
| 7 | + |
| 8 | +module Cardano.Node.Tracing.Tracers.NodeVersion |
| 9 | +( |
| 10 | + NodeVersionTrace (..) |
| 11 | + , getNodeVersion |
| 12 | + , getCardanoBuildInfo |
| 13 | +) |
| 14 | + where |
| 15 | + |
| 16 | +import Data.Aeson (toJSON, (.=)) |
| 17 | +import Data.Text (Text, pack) |
| 18 | +import Data.Version (Version (..), showVersion) |
| 19 | +#if MIN_VERSION_base(4,15,0) |
| 20 | +import System.Info (arch, compilerName, fullCompilerVersion, os) |
| 21 | +#else |
| 22 | +import System.Info (arch, compilerName, compilerVersion, os) |
| 23 | +#endif |
| 24 | + |
| 25 | +import Cardano.Git.Rev (gitRev) |
| 26 | +import Cardano.Logging |
| 27 | + |
| 28 | +import Paths_cardano_node (version) |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +-- | Node version information |
| 33 | + |
| 34 | +data NodeVersionTrace = NodeVersionTrace |
| 35 | + { applicationName :: Text |
| 36 | + , applicationVersion :: Version |
| 37 | + , osName :: Text |
| 38 | + , architecture :: Text |
| 39 | + , compilerName :: Text |
| 40 | + , compilerVersion :: Version |
| 41 | + , gitRevision :: Text |
| 42 | + } deriving (Eq, Show) |
| 43 | + |
| 44 | +-- | Get the node version information |
| 45 | + |
| 46 | +getComplierVersion :: Version |
| 47 | +#if MIN_VERSION_base(4,15,0) |
| 48 | +getComplierVersion = System.Info.fullCompilerVersion |
| 49 | +#else |
| 50 | +getComplierVersion = System.Info.compilerVersion |
| 51 | +#endif |
| 52 | + |
| 53 | +getNodeVersion :: NodeVersionTrace |
| 54 | +getNodeVersion = |
| 55 | + let applicationName = "cardano-node" |
| 56 | + applicationVersion = version |
| 57 | + osName = pack os |
| 58 | + architecture = pack arch |
| 59 | + compilerName = pack System.Info.compilerName |
| 60 | + compilerVersion = getComplierVersion |
| 61 | + gitRevision = $(gitRev) |
| 62 | + in NodeVersionTrace {..} |
| 63 | + |
| 64 | + |
| 65 | +instance MetaTrace NodeVersionTrace where |
| 66 | + namespaceFor NodeVersionTrace {} = |
| 67 | + Namespace [] ["NodeVersion"] |
| 68 | + severityFor (Namespace _ ["NodeVersion"]) _ = Just Info |
| 69 | + severityFor _ _ = Nothing |
| 70 | + |
| 71 | + documentFor (Namespace _ ["NodeVersion"]) = Just "Node version information" |
| 72 | + |
| 73 | + documentFor _ = Nothing |
| 74 | + |
| 75 | + metricsDocFor (Namespace _ ["NodeVersion"]) = |
| 76 | + [("cardano_version_major", "Cardano node version information") |
| 77 | + ,("cardano_version_minor", "Cardano node version information") |
| 78 | + ,("cardano_version_patch", "Cardano node version information") |
| 79 | + ,("haskell_compiler_major", "Cardano compiler version information") |
| 80 | + ,("haskell_compiler_minor", "Cardano compiler version information") |
| 81 | + |
| 82 | +#if MIN_VERSION_base(4,15,0) |
| 83 | + ,("haskell_compiler_patch", "Cardano compiler version information") |
| 84 | +#endif |
| 85 | + ,("cardano_build_info", "Cardano node build info") |
| 86 | + ] |
| 87 | + metricsDocFor _ = [] |
| 88 | + |
| 89 | + allNamespaces = [Namespace [] ["NodeVersion"]] |
| 90 | + |
| 91 | +instance LogFormatting NodeVersionTrace where |
| 92 | + forHuman NodeVersionTrace {..} = mconcat |
| 93 | + [ "cardano-node ", pack (showVersion applicationVersion) |
| 94 | + , " git rev ", gitRevision |
| 95 | + , " - ", pack os, "-", pack arch |
| 96 | + , " - ", compilerName, "-", pack (showVersion compilerVersion) |
| 97 | + ] |
| 98 | + |
| 99 | + forMachine _dtal NodeVersionTrace {..} = mconcat |
| 100 | + |
| 101 | + [ "applicationName" .= applicationName |
| 102 | + , "applicationVersion" .= toJSON applicationVersion |
| 103 | + , "gitRevision" .= gitRevision |
| 104 | + , "osName" .= osName |
| 105 | + , "architecture" .= architecture |
| 106 | + , "compilerName" .= compilerName |
| 107 | + , "compilerVersion" .= toJSON compilerVersion |
| 108 | + ] |
| 109 | + |
| 110 | + asMetrics nvt@NodeVersionTrace {..} = |
| 111 | + [ IntM "cardano_version_major" (fromIntegral (getMajor applicationVersion)) |
| 112 | + , IntM "cardano_version_minor" (fromIntegral (getMinor applicationVersion)) |
| 113 | + , IntM "cardano_version_patch" (fromIntegral (getPatch applicationVersion)) |
| 114 | + , IntM "haskell_compiler_major" (fromIntegral (getMajor compilerVersion)) |
| 115 | + , IntM "haskell_compiler_minor" (fromIntegral (getMinor compilerVersion)) |
| 116 | +#if MIN_VERSION_base(4,15,0) |
| 117 | + , IntM "haskell_compiler_patch" (fromIntegral (getPatch compilerVersion)) |
| 118 | +#endif |
| 119 | + , PrometheusM "cardano_build_info" (getCardanoBuildInfo nvt) |
| 120 | + ] |
| 121 | + |
| 122 | +getCardanoBuildInfo :: NodeVersionTrace -> [(Text,Text)] |
| 123 | +getCardanoBuildInfo NodeVersionTrace {..} = |
| 124 | + [ ("version_major", pack (show (getMajor applicationVersion))) |
| 125 | + , ("version_minor", pack (show (getMinor applicationVersion))) |
| 126 | + , ("version_patch", pack (show (getPatch applicationVersion))) |
| 127 | + , ("version", pack (showVersion applicationVersion)) |
| 128 | + , ("revision", gitRevision) |
| 129 | + , ("compiler_name", compilerName) |
| 130 | + , ("compiler_version", pack (showVersion compilerVersion)) |
| 131 | + , ("compiler_version_major", pack (show (getMajor compilerVersion))) |
| 132 | + , ("compiler_version_minor", pack (show (getMinor compilerVersion))) |
| 133 | +#if MIN_VERSION_base(4,15,0) |
| 134 | + , ("compiler_version_patch", pack (show (getPatch compilerVersion))) |
| 135 | +#endif |
| 136 | + , ("architecture", architecture) |
| 137 | + , ("os_name", osName) |
| 138 | + ] |
| 139 | + |
| 140 | +getMajor :: Version -> Int |
| 141 | +getMajor (Version (x:_) _) = x |
| 142 | +getMajor _ = 0 |
| 143 | + |
| 144 | +getMinor :: Version -> Int |
| 145 | +getMinor (Version (_:x:_) _) = x |
| 146 | +getMinor _ = 0 |
| 147 | + |
| 148 | +getPatch :: Version -> Int |
| 149 | +getPatch (Version (_:_:x:_) _) = x |
| 150 | +getPatch _ = 0 |
| 151 | + |
| 152 | + |
| 153 | + |
0 commit comments