Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAD-2907 workbench: add locli, a log analysis tool
- Loading branch information
Showing
21 changed files
with
2,129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright 2020 Input Output (Hong Kong) Ltd. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
import Cardano.Prelude hiding (option) | ||
|
||
import Control.Monad.Trans.Except.Exit (orDie) | ||
import qualified Options.Applicative as Opt | ||
|
||
import Cardano.Unlog.Parsers (opts, pref) | ||
import Cardano.Unlog.Run (renderCommandError, runCommand) | ||
import Cardano.TopHandler | ||
|
||
|
||
main :: IO () | ||
main = toplevelExceptionHandler $ do | ||
|
||
co <- Opt.customExecParser pref opts | ||
|
||
orDie renderCommandError $ runCommand co |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
cabal-version: 2.4 | ||
|
||
name: locli | ||
version: 1.27 | ||
description: Log parsing CLI. | ||
author: IOHK | ||
maintainer: operations@iohk.io | ||
license: Apache-2.0 | ||
license-files: | ||
NOTICE | ||
build-type: Simple | ||
|
||
library | ||
|
||
hs-source-dirs: src | ||
|
||
exposed-modules: Data.Accum | ||
Data.Distribution | ||
|
||
Cardano.Config.Git.Rev | ||
Cardano.Config.Git.RevFromGit | ||
|
||
Cardano.Profile | ||
|
||
Cardano.TopHandler | ||
|
||
Cardano.Unlog.Analysis | ||
Cardano.Unlog.Commands | ||
Cardano.Unlog.LogObject | ||
Cardano.Unlog.Parsers | ||
Cardano.Unlog.Resources | ||
Cardano.Unlog.Run | ||
Cardano.Unlog.SlotStats | ||
Cardano.Unlog.Summary | ||
|
||
other-modules: Paths_locli | ||
|
||
build-depends: base | ||
, aeson | ||
, aeson-pretty | ||
, attoparsec | ||
, attoparsec-iso8601 | ||
, bytestring | ||
, cardano-prelude | ||
, containers | ||
, directory | ||
, filepath | ||
, file-embed | ||
, gnuplot | ||
, Histogram | ||
, iohk-monitoring | ||
, optparse-applicative | ||
, optparse-generic | ||
, process | ||
, scientific | ||
, split | ||
, template-haskell | ||
, text | ||
, text-short | ||
, time | ||
, transformers | ||
, transformers-except | ||
, unordered-containers | ||
, utf8-string | ||
, vector | ||
|
||
default-language: Haskell2010 | ||
default-extensions: NoImplicitPrelude | ||
OverloadedStrings | ||
TupleSections | ||
|
||
ghc-options: -Wall | ||
-Wincomplete-record-updates | ||
-Wincomplete-uni-patterns | ||
-Wredundant-constraints | ||
-Wpartial-fields | ||
-Wcompat | ||
-Wno-all-missed-specialisations | ||
|
||
executable locli | ||
hs-source-dirs: app | ||
main-is: locli.hs | ||
default-language: Haskell2010 | ||
ghc-options: -threaded | ||
-Wall | ||
-rtsopts | ||
"-with-rtsopts=-T" | ||
build-depends: base | ||
, cardano-prelude | ||
, locli | ||
, optparse-applicative | ||
, text | ||
, text-short | ||
, transformers | ||
, transformers-except | ||
default-extensions: NoImplicitPrelude |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Cardano.Config.Git.Rev ( | ||
gitRev | ||
) where | ||
|
||
import Cardano.Prelude | ||
|
||
import Data.FileEmbed (dummySpaceWith) | ||
import qualified Data.Text as T | ||
|
||
import Cardano.Config.Git.RevFromGit (gitRevFromGit) | ||
|
||
gitRev :: Text | ||
gitRev | gitRevEmbed /= zeroRev = gitRevEmbed | ||
| T.null fromGit = zeroRev | ||
| otherwise = fromGit | ||
where | ||
-- Git revision embedded after compilation using | ||
-- Data.FileEmbed.injectWith. If nothing has been injected, | ||
-- this will be filled with 0 characters. | ||
gitRevEmbed :: Text | ||
gitRevEmbed = decodeUtf8 $(dummySpaceWith "gitrev" 40) | ||
|
||
-- Git revision found during compilation by running git. If | ||
-- git could not be run, then this will be empty. | ||
#if defined(arm_HOST_ARCH) | ||
-- cross compiling to arm fails; due to a linker bug | ||
fromGit = "" | ||
#else | ||
fromGit = T.strip (T.pack $(gitRevFromGit)) | ||
#endif | ||
|
||
zeroRev :: Text | ||
zeroRev = "0000000000000000000000000000000000000000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Cardano.Config.Git.RevFromGit ( | ||
gitRevFromGit | ||
) where | ||
|
||
import Cardano.Prelude | ||
import Prelude (String) | ||
|
||
import qualified Language.Haskell.TH as TH | ||
import System.IO.Error (ioeGetErrorType, isDoesNotExistErrorType) | ||
import System.Process (readProcessWithExitCode) | ||
|
||
-- | Git revision found by running git rev-parse. If git could not be | ||
-- executed, then this will be an empty string. | ||
gitRevFromGit :: TH.Q TH.Exp | ||
gitRevFromGit = TH.LitE . TH.StringL <$> TH.runIO runGitRevParse | ||
where | ||
runGitRevParse :: IO String | ||
runGitRevParse = handleJust missingGit (const $ pure "") $ do | ||
(exitCode, output, _) <- | ||
readProcessWithExitCode "git" ["rev-parse", "--verify", "HEAD"] "" | ||
pure $ case exitCode of | ||
ExitSuccess -> output | ||
_ -> "" | ||
|
||
missingGit e = if isDoesNotExistErrorType (ioeGetErrorType e) then Just () else Nothing | ||
|
Oops, something went wrong.