Skip to content

Commit 9f1051b

Browse files
Wen Kokkewenkokke
authored andcommitted
feat(eventlog-live-otelcol): pack configuration file JSON Schema
1 parent 4530fdf commit 9f1051b

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

eventlog-live-otelcol/eventlog-live-otelcol.cabal

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ copyright: (c) 2025 Well-Typed
8282
build-type: Simple
8383
category: Debug, Monitoring, System
8484
extra-doc-files: CHANGELOG.md
85-
extra-source-files: data/default.yaml
85+
extra-source-files:
86+
data/config.schema.json
87+
data/default.yaml
88+
8689
tested-with:
8790
GHC ==9.2.8 || ==9.4.8 || ==9.6.7 || ==9.8.4 || ==9.10.2
8891

eventlog-live-otelcol/src/GHC/Eventlog/Live/Otelcol.hs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import GHC.Eventlog.Live.Machine.WithStartTime qualified as M
5555
import GHC.Eventlog.Live.Options
5656
import GHC.Eventlog.Live.Otelcol.Config (Config)
5757
import GHC.Eventlog.Live.Otelcol.Config qualified as C
58-
import GHC.Eventlog.Live.Otelcol.Config.Default.Raw (defaultConfigString)
58+
import GHC.Eventlog.Live.Otelcol.Config.Default.Raw (defaultConfigByteString, defaultConfigJSONSchemaByteString)
5959
import GHC.Eventlog.Live.Otelcol.Exporter (exportResourceMetrics, exportResourceSpans)
6060
import GHC.Eventlog.Live.Otelcol.Stats (Stat (..), eventCountTick, processStats)
6161
import GHC.Eventlog.Live.Socket (runWithEventlogSource)
@@ -851,6 +851,7 @@ options =
851851
( optionsParser
852852
O.<**> defaultsPrinter
853853
O.<**> debugDefaultsPrinter
854+
O.<**> configJSONSchemaPrinter
854855
O.<**> OE.helperWith (O.long "help" <> O.help "Show this help text.")
855856
O.<**> OC.simpleVersioner (showVersion EventlogLive.version)
856857
)
@@ -938,9 +939,16 @@ configFileParser =
938939

939940
defaultsPrinter :: O.Parser (a -> a)
940941
defaultsPrinter =
941-
O.infoOption defaultConfigString . mconcat $
942+
O.infoOption (fromByteString defaultConfigByteString) . mconcat $
942943
[ O.long "print-defaults"
943-
, O.help "Print default configuration options that can be used in config.yaml"
944+
, O.help "Print default configuration options."
945+
]
946+
947+
configJSONSchemaPrinter :: O.Parser (a -> a)
948+
configJSONSchemaPrinter =
949+
O.infoOption (fromByteString defaultConfigJSONSchemaByteString) . mconcat $
950+
[ O.long "print-config-json-schema"
951+
, O.help "Print JSON Schema for configuration format."
944952
]
945953

946954
debugDefaultsPrinter :: O.Parser (a -> a)
@@ -952,7 +960,14 @@ debugDefaultsPrinter =
952960
]
953961
where
954962
defaultConfigDebugString =
955-
T.unpack . TE.decodeUtf8Lenient . Y.encode $ (def :: Config)
963+
fromByteString . Y.encode $ (def :: Config)
964+
965+
{- |
966+
Internal helper.
967+
Decode a `ByteString` to a `String`.
968+
-}
969+
fromByteString :: ByteString -> String
970+
fromByteString = T.unpack . TE.decodeUtf8Lenient
956971

957972
--------------------------------------------------------------------------------
958973
-- Service Name

eventlog-live-otelcol/src/GHC/Eventlog/Live/Otelcol/Config/Default/Raw.hs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,22 @@ Portability : portable
88
-}
99
module GHC.Eventlog.Live.Otelcol.Config.Default.Raw (
1010
defaultConfigByteString,
11-
defaultConfigString,
12-
defaultConfigText,
11+
defaultConfigJSONSchemaByteString,
1312
) where
1413

1514
import Data.ByteString (ByteString)
1615
import Data.FileEmbed (embedFileRelative)
17-
import Data.Text (Text)
18-
import Data.Text qualified as T
19-
import Data.Text.Encoding qualified as TE (decodeUtf8Lenient)
2016

2117
{- |
2218
Internal helper.
2319
The default configuration as a `ByteString`.
2420
-}
25-
defaultConfigByteString :: ByteString
26-
defaultConfigByteString = $(embedFileRelative "data/default.yaml")
21+
defaultConfigJSONSchemaByteString :: ByteString
22+
defaultConfigJSONSchemaByteString = $(embedFileRelative "data/config.schema.json")
2723

2824
{- |
2925
Internal helper.
30-
The default configuration as a `String`.
31-
-}
32-
defaultConfigString :: String
33-
defaultConfigString = T.unpack defaultConfigText
34-
35-
{- |
36-
Internal helper.
37-
The default configuration as a `Text`.
26+
The default configuration as a `ByteString`.
3827
-}
39-
defaultConfigText :: Text
40-
defaultConfigText = TE.decodeUtf8Lenient defaultConfigByteString
28+
defaultConfigByteString :: ByteString
29+
defaultConfigByteString = $(embedFileRelative "data/default.yaml")

0 commit comments

Comments
 (0)