From 2d507b09125294cbf2c93d7ebb831a141c1b71b8 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 30 Oct 2018 13:46:13 -0400 Subject: [PATCH 1/7] Move the request_id field onto its own line. --- src/Semantic/Config.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Semantic/Config.hs b/src/Semantic/Config.hs index 7e7cf1b9f..70bb6f214 100644 --- a/src/Semantic/Config.hs +++ b/src/Semantic/Config.hs @@ -106,7 +106,8 @@ logOptionsFromConfig Config{..} = LogOptions , ("pid", show configProcessID) , ("hostname", configHostName) , ("sha", buildSHA) - ] <> [("request_id", x) | x <- toList (optionsRequestID configOptions) ] + ] + <> [("request_id", x) | x <- toList (optionsRequestID configOptions) ] _ -> [] From 4faf8dcc529bb92f1eee0d9a5e1c2376e0f386b3 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 30 Oct 2018 13:47:12 -0400 Subject: [PATCH 2/7] Add a SHA to Options. --- src/Semantic/CLI.hs | 2 +- src/Semantic/Config.hs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Semantic/CLI.hs b/src/Semantic/CLI.hs index 730c8b32f..13a66020b 100644 --- a/src/Semantic/CLI.hs +++ b/src/Semantic/CLI.hs @@ -48,7 +48,7 @@ optionsParser = do requestId <- optional (strOption $ long "request-id" <> help "A string to use as the request identifier for any logged messages." <> metavar "id") failOnWarning <- switch (long "fail-on-warning" <> help "Fail on assignment warnings.") failOnParseError <- switch (long "fail-on-parse-error" <> help "Fail on tree-sitter parse errors.") - pure $ Options logLevel requestId failOnWarning failOnParseError + pure $ Options logLevel requestId failOnWarning failOnParseError (Just buildSHA) argumentsParser :: Parser (Task.TaskEff ()) argumentsParser = do diff --git a/src/Semantic/Config.hs b/src/Semantic/Config.hs index 70bb6f214..9a612bbd2 100644 --- a/src/Semantic/Config.hs +++ b/src/Semantic/Config.hs @@ -54,13 +54,14 @@ data Options , optionsRequestID :: Maybe String -- ^ Optional request id for tracing across systems. , optionsFailOnWarning :: Bool -- ^ Should semantic fail fast on assignment warnings (for testing) , optionsFailOnParseError :: Bool -- ^ Should semantic fail fast on tree-sitter parser errors (for testing) + , optionsSHA :: Maybe String } defaultOptions :: Options -defaultOptions = Options (Just Warning) Nothing False False +defaultOptions = Options (Just Warning) Nothing False False Nothing debugOptions :: Options -debugOptions = Options (Just Debug) Nothing False False +debugOptions = Options (Just Debug) Nothing False False Nothing defaultConfig :: Options -> IO Config defaultConfig options@Options{..} = do From c71d9ba19954a5eb4af11e670944dbfde52c0095 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 30 Oct 2018 13:48:22 -0400 Subject: [PATCH 3/7] Include the SHA from the Options. --- src/Semantic/Config.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Semantic/Config.hs b/src/Semantic/Config.hs index 9a612bbd2..445f7534e 100644 --- a/src/Semantic/Config.hs +++ b/src/Semantic/Config.hs @@ -23,7 +23,6 @@ import Semantic.Env import Semantic.Telemetry import qualified Semantic.Telemetry.Haystack as Haystack import qualified Semantic.Telemetry.Stat as Stat -import Semantic.Version import System.Environment import System.IO (hIsTerminalDevice, stdout) import System.Posix.Process @@ -106,8 +105,8 @@ logOptionsFromConfig Config{..} = LogOptions False -> [ ("app", configAppName) , ("pid", show configProcessID) , ("hostname", configHostName) - , ("sha", buildSHA) ] + <> [("sha", x) | x <- toList (optionsSHA configOptions) ] <> [("request_id", x) | x <- toList (optionsRequestID configOptions) ] _ -> [] From e44ab265ab03e036a10f12e752fb5aa16b7bc760 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 30 Oct 2018 14:16:52 -0400 Subject: [PATCH 4/7] :memo: optionsSHA. --- src/Semantic/Config.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Semantic/Config.hs b/src/Semantic/Config.hs index 445f7534e..cb78923d7 100644 --- a/src/Semantic/Config.hs +++ b/src/Semantic/Config.hs @@ -53,7 +53,7 @@ data Options , optionsRequestID :: Maybe String -- ^ Optional request id for tracing across systems. , optionsFailOnWarning :: Bool -- ^ Should semantic fail fast on assignment warnings (for testing) , optionsFailOnParseError :: Bool -- ^ Should semantic fail fast on tree-sitter parser errors (for testing) - , optionsSHA :: Maybe String + , optionsSHA :: Maybe String -- ^ Optional SHA to include in log messages. } defaultOptions :: Options From 4ec497b793d3bdec949896c6334ae02da1d53515 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 30 Oct 2018 14:49:07 -0400 Subject: [PATCH 5/7] =?UTF-8?q?Use=20runTask=20when=20we=20aren=E2=80=99t?= =?UTF-8?q?=20setting=20the=20Options.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/Graphing/Calls/Spec.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Graphing/Calls/Spec.hs b/test/Graphing/Calls/Spec.hs index 89890be84..36b7bfa62 100644 --- a/test/Graphing/Calls/Spec.hs +++ b/test/Graphing/Calls/Spec.hs @@ -18,7 +18,7 @@ import Semantic.Config (defaultOptions) import Semantic.Graph import Semantic.IO -callGraphPythonProject paths = runTaskWithOptions defaultOptions $ do +callGraphPythonProject paths = runTask $ do let proxy = Proxy @'Language.Python let lang = Language.Python blobs <- catMaybes <$> traverse readBlobFromFile (flip File lang <$> paths) From 1ff9c7ac362b8565888ac9211c81af0c9410e953 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 30 Oct 2018 14:58:29 -0400 Subject: [PATCH 6/7] Move the SHA to Config. --- src/Semantic/CLI.hs | 10 ++++++++-- src/Semantic/Config.hs | 9 +++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Semantic/CLI.hs b/src/Semantic/CLI.hs index 13a66020b..b82e1f600 100644 --- a/src/Semantic/CLI.hs +++ b/src/Semantic/CLI.hs @@ -6,6 +6,7 @@ module Semantic.CLI , Parse.runParse ) where +import Control.Exception as Exc (displayException) import Data.File import Data.Language (ensureLanguage, languageForFilePath) import Data.List (intercalate, uncons) @@ -24,12 +25,17 @@ import qualified Semantic.Task as Task import Semantic.Task.Files import qualified Semantic.Telemetry.Log as Log import Semantic.Version +import System.Exit (die) import System.FilePath import Serializing.Format hiding (Options) import Text.Read main :: IO () -main = customExecParser (prefs showHelpOnEmpty) arguments >>= uncurry Task.runTaskWithOptions +main = do + (options, task) <- customExecParser (prefs showHelpOnEmpty) arguments + res <- Task.withOptions options $ \ config logger statter -> + Task.runTaskWithConfig config { configSHA = Just buildSHA } logger statter task + either (die . displayException) pure res -- | A parser for the application's command-line arguments. -- @@ -48,7 +54,7 @@ optionsParser = do requestId <- optional (strOption $ long "request-id" <> help "A string to use as the request identifier for any logged messages." <> metavar "id") failOnWarning <- switch (long "fail-on-warning" <> help "Fail on assignment warnings.") failOnParseError <- switch (long "fail-on-parse-error" <> help "Fail on tree-sitter parse errors.") - pure $ Options logLevel requestId failOnWarning failOnParseError (Just buildSHA) + pure $ Options logLevel requestId failOnWarning failOnParseError argumentsParser :: Parser (Task.TaskEff ()) argumentsParser = do diff --git a/src/Semantic/Config.hs b/src/Semantic/Config.hs index cb78923d7..f8509be07 100644 --- a/src/Semantic/Config.hs +++ b/src/Semantic/Config.hs @@ -42,6 +42,7 @@ data Config , configIsTerminal :: Bool -- ^ Whether a terminal is attached (set automaticaly at runtime). , configLogPrintSource :: Bool -- ^ Whether to print the source reference when logging errors (set automatically at runtime). , configLogFormatter :: LogFormatter -- ^ Log formatter to use (set automaticaly at runtime). + , configSHA :: Maybe String -- ^ Optional SHA to include in log messages. , configOptions :: Options -- ^ Options configurable via command line arguments. } @@ -53,14 +54,13 @@ data Options , optionsRequestID :: Maybe String -- ^ Optional request id for tracing across systems. , optionsFailOnWarning :: Bool -- ^ Should semantic fail fast on assignment warnings (for testing) , optionsFailOnParseError :: Bool -- ^ Should semantic fail fast on tree-sitter parser errors (for testing) - , optionsSHA :: Maybe String -- ^ Optional SHA to include in log messages. } defaultOptions :: Options -defaultOptions = Options (Just Warning) Nothing False False Nothing +defaultOptions = Options (Just Warning) Nothing False False debugOptions :: Options -debugOptions = Options (Just Debug) Nothing False False Nothing +debugOptions = Options (Just Debug) Nothing False False defaultConfig :: Options -> IO Config defaultConfig options@Options{..} = do @@ -84,6 +84,7 @@ defaultConfig options@Options{..} = do , configIsTerminal = isTerminal , configLogPrintSource = isTerminal , configLogFormatter = if isTerminal then terminalFormatter else logfmtFormatter + , configSHA = Nothing , configOptions = options } @@ -106,7 +107,7 @@ logOptionsFromConfig Config{..} = LogOptions , ("pid", show configProcessID) , ("hostname", configHostName) ] - <> [("sha", x) | x <- toList (optionsSHA configOptions) ] + <> [("sha", x) | x <- toList configSHA ] <> [("request_id", x) | x <- toList (optionsRequestID configOptions) ] _ -> [] From 8389097a815993dbf398eb22f3b64b5d52b61db4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 30 Oct 2018 14:59:14 -0400 Subject: [PATCH 7/7] =?UTF-8?q?Log=20a=20SHA=20of=20=E2=80=9Cdevelopment?= =?UTF-8?q?=E2=80=9D=20when=20it=E2=80=99s=20absent=20from=20the=20Config.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Semantic/Config.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Semantic/Config.hs b/src/Semantic/Config.hs index f8509be07..f0a3add28 100644 --- a/src/Semantic/Config.hs +++ b/src/Semantic/Config.hs @@ -106,8 +106,8 @@ logOptionsFromConfig Config{..} = LogOptions False -> [ ("app", configAppName) , ("pid", show configProcessID) , ("hostname", configHostName) + , ("sha", fromMaybe "development" configSHA) ] - <> [("sha", x) | x <- toList configSHA ] <> [("request_id", x) | x <- toList (optionsRequestID configOptions) ] _ -> []