Browse Source

Merge pull request #433 from input-output-hk/organise_backends_in_plugins

Organise backends in plugins
master
Alexander Diemand 3 years ago committed by GitHub
parent
commit
1ebe57df3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      .buildkite/pipeline.yml
  2. 4
      .gitignore
  3. 14
      cabal.project
  4. 12
      docs/Code.lhs
  5. 15
      docs/Makefile
  6. 202
      examples/LICENSE
  7. 2
      examples/Setup.hs
  8. 42
      examples/complex/Main.lhs
  9. 79
      examples/lobemo-examples.cabal
  10. 2
      examples/performance/Main.lhs
  11. 0
      examples/performance/README.md
  12. 24
      examples/simple/Main.lhs
  13. 2
      hie.yaml
  14. 210
      iohk-monitoring/iohk-monitoring.cabal
  15. 175
      iohk-monitoring/src/Cardano/BM/Backend/Log.lhs
  16. 2
      iohk-monitoring/src/Cardano/BM/Backend/LogBuffer.lhs
  17. 200
      iohk-monitoring/src/Cardano/BM/Backend/Switchboard.lhs
  18. 2
      iohk-monitoring/src/Cardano/BM/Backend/TraceForwarder.lhs
  19. 6
      iohk-monitoring/src/Cardano/BM/Configuration.lhs
  20. 5
      iohk-monitoring/src/Cardano/BM/Configuration/Model.lhs
  21. 5
      iohk-monitoring/src/Cardano/BM/Configuration/Static.lhs
  22. 91
      iohk-monitoring/src/Cardano/BM/Data/Aggregated.lhs
  23. 13
      iohk-monitoring/src/Cardano/BM/Data/Backend.lhs
  24. 5
      iohk-monitoring/src/Cardano/BM/Data/Configuration.lhs
  25. 6
      iohk-monitoring/src/Cardano/BM/Data/Output.lhs
  26. 42
      iohk-monitoring/src/Cardano/BM/Plugin.lhs
  27. 2
      iohk-monitoring/src/Cardano/BM/Rotator.lhs
  28. 8
      iohk-monitoring/static/configuration-editor.html
  29. 32
      iohk-monitoring/test/Cardano/BM/Test/Aggregated.lhs
  30. 90
      iohk-monitoring/test/Cardano/BM/Test/Configuration.lhs
  31. 67
      iohk-monitoring/test/Cardano/BM/Test/Mock.lhs
  32. 2
      iohk-monitoring/test/Cardano/BM/Test/Structured.lhs
  33. 13
      iohk-monitoring/test/Cardano/BM/Test/Trace.lhs
  34. 14
      iohk-monitoring/test/Test.lhs
  35. 10
      nix/.stack.nix/default.nix
  36. 75
      nix/.stack.nix/iohk-monitoring.nix
  37. 37
      nix/.stack.nix/lobemo-backend-aggregation.nix
  38. 38
      nix/.stack.nix/lobemo-backend-editor.nix
  39. 34
      nix/.stack.nix/lobemo-backend-ekg.nix
  40. 33
      nix/.stack.nix/lobemo-backend-graylog.nix
  41. 72
      nix/.stack.nix/lobemo-backend-monitoring.nix
  42. 31
      nix/.stack.nix/lobemo-backend-prometheus.nix
  43. 66
      nix/.stack.nix/lobemo-examples.nix
  44. 36
      nix/.stack.nix/lobemo-scribe-systemd.nix
  45. 6
      nix/iohk-nix-src.json
  46. 9
      nix/pkgs.nix
  47. 202
      plugins/backend-aggregation/LICENSE
  48. 5
      plugins/backend-aggregation/NOTICE
  49. 2
      plugins/backend-aggregation/README.md
  50. 2
      plugins/backend-aggregation/Setup.hs
  51. 37
      plugins/backend-aggregation/lobemo-backend-aggregation.cabal
  52. 118
      plugins/backend-aggregation/src/Cardano/BM/Backend/Aggregation.lhs
  53. 202
      plugins/backend-editor/LICENSE
  54. 5
      plugins/backend-editor/NOTICE
  55. 4
      plugins/backend-editor/README.md
  56. 2
      plugins/backend-editor/Setup.hs
  57. 41
      plugins/backend-editor/lobemo-backend-editor.cabal
  58. 31
      plugins/backend-editor/src/Cardano/BM/Backend/Editor.lhs
  59. 202
      plugins/backend-ekg/LICENSE
  60. 5
      plugins/backend-ekg/NOTICE
  61. 4
      plugins/backend-ekg/README.md
  62. 2
      plugins/backend-ekg/Setup.hs
  63. 34
      plugins/backend-ekg/lobemo-backend-ekg.cabal
  64. 35
      plugins/backend-ekg/src/Cardano/BM/Backend/EKGView.lhs
  65. 202
      plugins/backend-graylog/LICENSE
  66. 5
      plugins/backend-graylog/NOTICE
  67. 4
      plugins/backend-graylog/README.md
  68. 2
      plugins/backend-graylog/Setup.hs
  69. 33
      plugins/backend-graylog/lobemo-backend-graylog.cabal
  70. 26
      plugins/backend-graylog/src/Cardano/BM/Backend/Graylog.lhs
  71. 202
      plugins/backend-monitoring/LICENSE
  72. 5
      plugins/backend-monitoring/NOTICE
  73. 2
      plugins/backend-monitoring/README.md
  74. 2
      plugins/backend-monitoring/Setup.hs
  75. 79
      plugins/backend-monitoring/lobemo-backend-monitoring.cabal
  76. 53
      plugins/backend-monitoring/src/Cardano/BM/Backend/Monitoring.lhs
  77. 56
      plugins/backend-monitoring/test/Cardano/BM/Test/Monitoring.lhs
  78. 29
      plugins/backend-monitoring/test/Test.lhs
  79. 202
      plugins/backend-prometheus/LICENSE
  80. 5
      plugins/backend-prometheus/NOTICE
  81. 4
      plugins/backend-prometheus/README.md
  82. 2
      plugins/backend-prometheus/Setup.hs
  83. 31
      plugins/backend-prometheus/lobemo-backend-prometheus.cabal
  84. 0
      plugins/backend-prometheus/src/Cardano/BM/Backend/Prometheus.lhs
  85. 202
      plugins/scribe-systemd/LICENSE
  86. 5
      plugins/scribe-systemd/NOTICE
  87. 2
      plugins/scribe-systemd/README.md
  88. 2
      plugins/scribe-systemd/Setup.hs
  89. 40
      plugins/scribe-systemd/lobemo-scribe-systemd.cabal
  90. 146
      plugins/scribe-systemd/src/Cardano/BM/Scribe/Systemd.lhs
  91. 14
      release.nix
  92. 10
      stack.yaml

7
.buildkite/pipeline.yml

@ -18,13 +18,6 @@ steps:
branches: "master"
timeout: 30
- label: "make TeX documentation"
command: "cd docs; nix-shell --run make"
agents:
"system=x86_64-linux"
artifact_paths: "docs/IOHK-Monitoring.pdf ; docs/IOHK-Monitoring.log"
timeout: 5
- label: 'check-hydra'
command: 'ci/check-hydra.sh'
agents:

4
.gitignore vendored

@ -24,7 +24,7 @@ cabal.project.local~
.DS_Store
.liquid/
docs/IOHK-Monitoring-code.*
/docs/*
/result*
.stack-to-nix.cache
.stack-to-nix.cache

14
cabal.project

@ -1,8 +1,16 @@
packages:
iohk-monitoring
contra-tracer
tracer-transformers
iohk-monitoring
plugins/backend-aggregation
plugins/backend-editor
plugins/backend-ekg
plugins/backend-graylog
plugins/backend-monitoring
plugins/backend-prometheus
plugins/scribe-systemd
examples
package iohk-monitoring
tests: True
@ -10,13 +18,13 @@ package iohk-monitoring
package contra-tracer
-- Currently does not have tests, but set it True in case any are added.
tests: True
documentation: True
documentation: False
haddock-hyperlink-source: True
package tracer-transformers
-- Currently does not have tests, but set it True in case any are added.
tests: True
documentation: True
documentation: False
haddock-hyperlink-source: True
source-repository-package

12
docs/Code.lhs

@ -370,12 +370,12 @@ thus specializes its interface.}\label{fig:overview}
%include ../iohk-monitoring/src/Cardano/BM/Backend/Switchboard.lhs
%include ../iohk-monitoring/src/Cardano/BM/Backend/Log.lhs
%include ../iohk-monitoring/src/Cardano/BM/Backend/LogBuffer.lhs
%include ../iohk-monitoring/src/Cardano/BM/Backend/EKGView.lhs
%include ../iohk-monitoring/src/Cardano/BM/Backend/Editor.lhs
%include ../iohk-monitoring/src/Cardano/BM/Backend/Graylog.lhs
%include ../iohk-monitoring/src/Cardano/BM/Backend/Aggregation.lhs
%include ../iohk-monitoring/src/Cardano/BM/Backend/Monitoring.lhs
%include ../iohk-monitoring/src/Cardano/BM/Backend/Prometheus.lhs
%include ../plugins/backend-ekg/src/Cardano/BM/Backend/EKGView.lhs
%include ../plugins/backend-editor/src/Cardano/BM/Backend/Editor.lhs
%include ../plugins/backend-graylog/src/Cardano/BM/Backend/Graylog.lhs
%include ../plugins/backend-aggregation/src/Cardano/BM/Backend/Aggregation.lhs
%include ../plugins/backend-monitoring/src/Cardano/BM/Backend/Monitoring.lhs
%include ../plugins/backend-prometheus/src/Cardano/BM/Backend/Prometheus.lhs
%include ../iohk-monitoring/src/Cardano/BM/Backend/ExternalAbstraction.lhs
%include ../iohk-monitoring/src/Cardano/BM/Backend/TraceAcceptor.lhs
%include ../iohk-monitoring/src/Cardano/BM/Backend/TraceForwarder.lhs

15
docs/Makefile

@ -2,6 +2,7 @@ DOC = IOHK-Monitoring
SRCDIR1 = ../iohk-monitoring/src
SRCDIR2 = ../contra-tracer/src
SRCDIR3 = ../plugins
SOURCES = Code.lhs \
$(SRCDIR1)/Cardano/BM/Configuration.lhs \
$(SRCDIR1)/Cardano/BM/Configuration/Model.lhs \
@ -27,14 +28,14 @@ SOURCES = Code.lhs \
$(SRCDIR1)/Cardano/BM/Data/Tracer.lhs \
$(SRCDIR1)/Cardano/BM/Observer/Monadic.lhs \
$(SRCDIR1)/Cardano/BM/Observer/STM.lhs \
$(SRCDIR1)/Cardano/BM/Backend/Aggregation.lhs \
$(SRCDIR1)/Cardano/BM/Backend/Editor.lhs \
$(SRCDIR1)/Cardano/BM/Backend/EKGView.lhs \
$(SRCDIR1)/Cardano/BM/Backend/Graylog.lhs \
$(SRCDIR3)/backend-aggregation/src/Cardano/BM/Backend/Aggregation.lhs \
$(SRCDIR3)/backend-editor/src/Cardano/BM/Backend/Editor.lhs \
$(SRCDIR3)/backend-ekg/src/Cardano/BM/Backend/EKGView.lhs \
$(SRCDIR3)/backend-graylog/src/Cardano/BM/Backend/Graylog.lhs \
$(SRCDIR1)/Cardano/BM/Backend/Log.lhs \
$(SRCDIR1)/Cardano/BM/Backend/LogBuffer.lhs \
$(SRCDIR1)/Cardano/BM/Backend/Monitoring.lhs \
$(SRCDIR1)/Cardano/BM/Backend/Prometheus.lhs \
$(SRCDIR3)/backend-monitoring/src/Cardano/BM/Backend/Monitoring.lhs \
$(SRCDIR3)/backend-prometheus/src/Cardano/BM/Backend/Prometheus.lhs \
$(SRCDIR1)/Cardano/BM/Backend/Switchboard.lhs \
$(SRCDIR1)/Cardano/BM/Backend/TraceAcceptor.lhs \
$(SRCDIR1)/Cardano/BM/Backend/TraceForwarder.lhs \
@ -55,7 +56,7 @@ TESTS = $(TSTDIR1)/Test.lhs \
$(TSTDIR1)/Cardano/BM/Test/Tracer.lhs \
$(TSTDIR1)/Cardano/BM/Arbitrary/Aggregated.lhs \
EXAMPLES = ../iohk-monitoring/examples/complex/Main.lhs ../iohk-monitoring/examples/simple/Main.lhs
EXAMPLES = ../examples/complex/Main.lhs ../examples/simple/Main.lhs
TeXs = aggregation.tex configuration.tex monitoring.tex mu-benchmarks.tex output-selection.tex requirements.tex traces.tex

202
examples/LICENSE

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

2
examples/Setup.hs

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

42
iohk-monitoring/examples/complex/Main.lhs → examples/complex/Main.lhs

@ -35,7 +35,10 @@ import qualified Data.HashMap.Strict as HM
import Data.Text (Text, pack)
import System.Random
import Cardano.BM.Configuration (Configuration)
import Cardano.BM.Backend.Aggregation
import Cardano.BM.Backend.Editor
import Cardano.BM.Backend.EKGView
import Cardano.BM.Backend.Monitoring
import qualified Cardano.BM.Configuration.Model as CM
import Cardano.BM.Data.Aggregated (Measurable (..))
import Cardano.BM.Data.AggregatedKind
@ -51,6 +54,7 @@ import Cardano.BM.Data.Observable
import Cardano.BM.Observer.Monadic (bracketObserveIO)
import qualified Cardano.BM.Observer.STM as STM
#endif
import Cardano.BM.Plugin
import Cardano.BM.Setup
import Cardano.BM.Trace
@ -66,15 +70,7 @@ prepare_configuration = do
c <- CM.empty
CM.setMinSeverity c Warning
CM.setSetupBackends c [ KatipBK
#ifdef ENABLE_AGGREGATION
, AggregationBK
#endif
#ifdef ENABLE_EKG
, EKGViewBK
#endif
#ifdef ENABLE_GUI
, EditorBK
#endif
, MonitoringBK
, TraceForwarderBK
]
@ -161,19 +157,16 @@ prepare_configuration = do
(Just $ ObservableTraceSelf [GhcRtsStats,MemoryStats])
#endif
#ifdef ENABLE_AGGREGATION
CM.setBackends c "complex.message" (Just [AggregationBK, KatipBK, TraceForwarderBK])
CM.setBackends c "complex.random" (Just [KatipBK, EKGViewBK])
CM.setBackends c "complex.random.ewma" (Just [KatipBK])
CM.setBackends c "complex.observeIO" (Just [AggregationBK, MonitoringBK])
CM.setSubTrace c "#messagecounters.aggregation" $ Just NoTrace
#endif
forM_ [(1::Int)..10] $ \x -> do
#ifdef ENABLE_AGGREGATION
CM.setBackends c
("complex.observeSTM." <> (pack $ show x))
(Just [AggregationBK])
#endif
CM.setBackends c
("#aggregation.complex.observeSTM." <> (pack $ show x))
(Just [KatipBK])
@ -181,26 +174,19 @@ prepare_configuration = do
CM.setAggregatedKind c "complex.random.rr" (Just StatsAK)
CM.setAggregatedKind c "complex.random.ewma.rr" (Just (EwmaAK 0.42))
#ifdef ENABLE_GUI
CM.setBackends c "#aggregation.complex.random" (Just [EditorBK])
CM.setBackends c "#aggregation.complex.random.ewma" (Just [EditorBK])
CM.setBackends c "#messagecounters.switchboard" (Just [EditorBK, KatipBK])
#endif
#ifdef ENABLE_EKG
CM.setSubTrace c "#messagecounters.monitoring" $ (Just Neutral)
CM.setBackends c "#aggregation.complex.message" (Just [EKGViewBK, MonitoringBK])
CM.setBackends c "#aggregation.complex.monitoring" (Just [MonitoringBK])
CM.setBackends c "#aggregation.complex.observeIO" (Just [EKGViewBK])
CM.setEKGport c 12790
CM.setLogOutput c "iohk-monitoring/log-pipe"
#ifdef ENABLE_PROMETHEUS
CM.setPrometheusPort c 12800
#endif
#endif
#ifdef ENABLE_GUI
CM.setGUIport c 13790
#endif
CM.setMonitors c $ HM.fromList
[ ( "complex.monitoring"
, ( Just (Compare "monitMe" (GE, (OpMeasurable 10)))
@ -375,13 +361,21 @@ main = do
c <- prepare_configuration
-- create initial top-level Trace
(tr :: Trace IO Text, _sb) <- setupTrace_ c "complex"
(tr :: Trace IO Text, sb) <- setupTrace_ c "complex"
-- load plugins
Cardano.BM.Backend.Editor.plugin c tr sb
>>= loadPlugin sb
Cardano.BM.Backend.EKGView.plugin c tr sb
>>= loadPlugin sb
Cardano.BM.Backend.Aggregation.plugin c tr sb
>>= loadPlugin sb
Cardano.BM.Backend.Monitoring.plugin c tr sb
>>= loadPlugin sb
logNotice tr "starting program; hit CTRL-C to terminate"
-- user can watch the progress only if EKG is enabled.
#ifdef ENABLE_EKG
logInfo tr "watch its progress on http://localhost:12789"
#endif
#ifdef RUN_ProcBufferDump
procDump <- dumpBuffer sb tr

79
examples/lobemo-examples.cabal

@ -0,0 +1,79 @@
cabal-version: 2.0
name: lobemo-examples
version: 0.1.0.0
synopsis: examples of logging, benchmarking, and monitoring
-- description:
homepage: https://github.com/input-output-hk/iohk-monitoring-framework
-- bug-reports:
license: Apache-2.0
license-file: LICENSE
author: Alexander Diemand
maintainer: operations@iohk.io
copyright: 2019 IOHK
category: Benchmarking
build-type: Simple
extra-source-files:
executable example-simple
main-is: Main.lhs
-- other-modules:
default-extensions: OverloadedStrings
other-extensions: CPP, FlexibleInstances, MultiParamTypeClasses, ScopedTypeVariables
ghc-options: -threaded -Wall -O2 "-with-rtsopts=-T"
build-depends: base ^>=4.12.0.0
hs-source-dirs: simple
default-language: Haskell2010
build-depends: base,
aeson,
iohk-monitoring,
lobemo-backend-editor,
lobemo-scribe-systemd,
async,
bytestring,
mtl
if os(windows)
build-depends: Win32
else
build-depends: unix
executable example-complex
hs-source-dirs: complex
main-is: Main.lhs
default-language: Haskell2010
default-extensions: OverloadedStrings
ghc-options: -threaded -Wall -O2 "-with-rtsopts=-T"
other-modules:
build-depends: base,
iohk-monitoring,
lobemo-backend-aggregation,
lobemo-backend-editor,
lobemo-backend-ekg,
lobemo-backend-monitoring,
async,
bytestring,
mtl,
random,
text,
unordered-containers
if os(windows)
build-depends: Win32
else
build-depends: unix
if os(linux)
build-depends: download
executable example-performance
hs-source-dirs: performance
main-is: Main.lhs
default-language: Haskell2010
default-extensions: OverloadedStrings
ghc-options: -threaded -Wall -O2 -with-rtsopts=-T
other-modules:
build-depends: base,
iohk-monitoring,
async,
criterion,
text,
unordered-containers

2
iohk-monitoring/examples/performance/Main.lhs → examples/performance/Main.lhs

@ -52,7 +52,7 @@ prepare_configuration = do
\begin{code}
monitoringThr :: Trace IO Text -> Int -> IO (Async.Async ())
monitoringThr trace objNumber = do
trace' <- appendName "monitoring" trace
let trace' = appendName "monitoring" trace
obj <- (,) <$> (mkLOMeta Warning Public) <*> pure (LogValue "monitMe" (PureD 123.45))
proc <- Async.async (loop trace' obj)
return proc

0
iohk-monitoring/examples/performance/README.md → examples/performance/README.md

24
iohk-monitoring/examples/simple/Main.lhs → examples/simple/Main.lhs

@ -16,14 +16,16 @@ import Control.Concurrent (threadDelay)
import Control.Concurrent.MVar (MVar, newMVar, modifyMVar_, withMVar)
import Data.Aeson (FromJSON)
import Cardano.BM.Backend.Switchboard (addExternalBackend)
import Cardano.BM.Backend.Switchboard (addUserDefinedBackend)
import Cardano.BM.Data.Backend
import qualified Cardano.BM.Configuration.Model as CM
import Cardano.BM.Configuration.Static (defaultConfigStdout)
#ifdef LINUX
import Cardano.BM.Scribe.Systemd (plugin)
import Cardano.BM.Data.Output (ScribeDefinition (..),
ScribePrivacy (..), ScribeKind (..), ScribeFormat (..))
#endif
import Cardano.BM.Plugin (loadPlugin)
import Cardano.BM.Setup (setupTrace_)
import Cardano.BM.Trace (Trace, appendName, logDebug, logError,
logInfo, logNotice, logWarning)
@ -39,9 +41,9 @@ data MyBackendInternal a = MyBackendInternal {
}
instance (FromJSON a) => IsBackend MyBackend a where
typeof _ = UserDefinedBK "MyBackend"
bekind _ = UserDefinedBK "MyBackend"
realize _ = MyBackend <$> newMVar (MyBackendInternal 0)
unrealize be = putStrLn $ "unrealize " <> show (typeof be)
unrealize be = putStrLn $ "unrealize " <> show (bekind be)
instance IsEffectuator MyBackend a where
effectuate be _item = do
@ -76,21 +78,19 @@ main = do
, scPrivacy = ScPublic
, scRotation = Nothing
}
, ScribeDefinition {
scName = "systemd"
, scFormat = ScText
, scKind = JournalSK
, scPrivacy = ScPublic
, scRotation = Nothing
}
]
CM.setScribes c "simple.systemd" (Just ["JournalSK::systemd"])
CM.setScribes c "simple.systemd" (Just ["JournalSK"])
#endif
CM.setScribes c "simple.json" (Just ["StdoutSK::json"])
(tr :: Trace IO String, sb) <- setupTrace_ c "simple"
be :: MyBackend String <- realize c
let mybe = MkBackend { bEffectuate = effectuate be, bUnrealize = unrealize be }
addExternalBackend sb mybe "MyBackend"
addUserDefinedBackend sb mybe "MyBackend"
#ifdef LINUX
Cardano.BM.Scribe.Systemd.plugin c tr sb
>>= loadPlugin sb
#endif
let trText = appendName "text" tr
trJson = appendName "json" tr
#ifdef LINUX

2
hie.yaml

@ -0,0 +1,2 @@
cradle: {cabal: {component: "lib:iohk-monitoring"}}

210
iohk-monitoring/iohk-monitoring.cabal

@ -1,5 +1,5 @@
name: iohk-monitoring
version: 0.1.10.0
version: 0.1.10.1
synopsis: logging, benchmarking and monitoring framework
-- description:
license: Apache-2.0
@ -12,51 +12,11 @@ build-type: Simple
extra-source-files: README.md
cabal-version: >=1.10
flag disable-aggregation
description: Turn off complete aggregation subsystem.
default: False
manual: True
flag disable-ekg
description: Turn off EKG.
default: False
manual: True
flag disable-graylog
description: Turn off Graylog.
default: False
manual: True
flag disable-prometheus
description: Turn off Prometheus.
default: False
manual: True
flag disable-gui
description: Turn off configuration editor GUI.
default: False
manual: True
flag disable-monitoring
description: Turn off monitoring subsystem.
default: False
manual: True
flag disable-observables
description: Turn off observables, observers.
default: False
manual: True
flag disable-systemd
description: Turn off systemd journal scribe.
default: False
manual: True
flag disable-examples
description: Turn off building of examples.
default: False
manual: True
flag performance-test-queue
description: Set the huge size for backends' queues.
default: False
@ -98,33 +58,16 @@ library
Cardano.BM.Backend.Switchboard
Cardano.BM.Backend.TraceAcceptor
Cardano.BM.Backend.TraceForwarder
Cardano.BM.Plugin
Cardano.BM.Rotator
Cardano.BM.Setup
Cardano.BM.Trace
Cardano.BM.Tracer
if !flag(disable-aggregation)
exposed-modules: Cardano.BM.Backend.Aggregation
if !flag(disable-ekg)
exposed-modules: Cardano.BM.Backend.EKGView
if !flag(disable-graylog)
exposed-modules: Cardano.BM.Backend.Graylog
if !flag(disable-ekg) && !flag(disable-prometheus)
exposed-modules: Cardano.BM.Backend.Prometheus
if !flag(disable-gui)
exposed-modules: Cardano.BM.Backend.Editor
if !flag(disable-observables)
exposed-modules: Cardano.BM.Observer.Monadic
Cardano.BM.Observer.STM
if !flag(disable-monitoring)
exposed-modules: Cardano.BM.Backend.Monitoring
if os(linux)
exposed-modules: Cardano.BM.Counters.Linux
else
@ -137,7 +80,7 @@ library
other-extensions: OverloadedStrings
build-depends: base >= 4.11,
contra-tracer,
aeson,
aeson >= 1.4.2,
array,
async,
async-timer,
@ -165,45 +108,12 @@ library
unordered-containers,
vector,
yaml, libyaml
if !flag(disable-ekg)
build-depends: ekg,
ekg-core
if !flag(disable-ekg) && !flag(disable-prometheus)
build-depends: ekg-prometheus-adapter,
prometheus,
warp
if !flag(disable-graylog)
build-depends: network
if !flag(disable-gui)
build-depends: threepenny-gui
if os(windows)
build-depends: Win32
else
build-depends: unix
if os(linux) && !flag(disable-systemd)
cpp-options: -DENABLE_SYSTEMD
build-depends: hsyslog,
libsystemd-journal
if !flag(disable-aggregation)
cpp-options: -DENABLE_AGGREGATION
if !flag(disable-ekg)
cpp-options: -DENABLE_EKG
if !flag(disable-graylog)
cpp-options: -DENABLE_GRAYLOG
if !flag(disable-ekg) && !flag(disable-prometheus)
cpp-options: -DENABLE_PROMETHEUS
if !flag(disable-gui)
cpp-options: -DENABLE_GUI
if !flag(disable-monitoring)
cpp-options: -DENABLE_MONITORING
if !flag(disable-observables)
cpp-options: -DENABLE_OBSERVABLES
@ -221,25 +131,20 @@ test-suite tests
Cardano.BM.Test.STM
Cardano.BM.Test.Configuration
Cardano.BM.Test.LogItem
Cardano.BM.Test.Mock
Cardano.BM.Test.Rotator
Cardano.BM.Test.Routing
Cardano.BM.Test.Structured
Cardano.BM.Test.Tracer
if !flag(disable-aggregation)
other-modules: Cardano.BM.Test.Aggregated
Cardano.BM.Test.Aggregated
Cardano.BM.Arbitrary.Aggregated
if !flag(disable-monitoring)
other-modules: Cardano.BM.Test.Monitoring
default-language: Haskell2010
default-extensions: OverloadedStrings
build-depends: base,
contra-tracer,
iohk-monitoring,
aeson,
aeson >= 1.4.2,
array,
async,
bytestring,
@ -268,107 +173,6 @@ test-suite tests
yaml, libyaml
ghc-options: -Wall -Werror
if !flag(disable-aggregation)
cpp-options: -DENABLE_AGGREGATION
if !flag(disable-ekg)
cpp-options: -DENABLE_EKG
if !flag(disable-graylog)
cpp-options: -DENABLE_GRAYLOG
if !flag(disable-ekg) && !flag(disable-prometheus)
cpp-options: -DENABLE_PROMETHEUS
if !flag(disable-gui)
cpp-options: -DENABLE_GUI
if !flag(disable-monitoring)
cpp-options: -DENABLE_MONITORING
if !flag(disable-observables)
cpp-options: -DENABLE_OBSERVABLES
executable example-simple
hs-source-dirs: examples/simple
main-is: Main.lhs
default-language: Haskell2010
default-extensions: OverloadedStrings
ghc-options: -threaded -Wall -O2 "-with-rtsopts=-T"
other-modules:
build-depends: base,
aeson,
iohk-monitoring,
async,
bytestring,
mtl
if os(windows)
build-depends: Win32
else
build-depends: unix
if flag(disable-examples)
buildable: False
executable example-complex
hs-source-dirs: examples/complex
main-is: Main.lhs
default-language: Haskell2010
default-extensions: OverloadedStrings
ghc-options: -threaded -Wall -O2 "-with-rtsopts=-T"
other-modules:
build-depends: base,
iohk-monitoring,
async,
bytestring,
mtl,
random,
text,
unordered-containers
if os(windows)
build-depends: Win32
else
build-depends: unix
if os(linux)
build-depends: download
if !flag(disable-aggregation)
cpp-options: -DENABLE_AGGREGATION
if !flag(disable-ekg)
cpp-options: -DENABLE_EKG
if !flag(disable-graylog)
cpp-options: -DENABLE_GRAYLOG
if !flag(disable-ekg) && !flag(disable-prometheus)
cpp-options: -DENABLE_PROMETHEUS
if !flag(disable-gui)
cpp-options: -DENABLE_GUI
if !flag(disable-monitoring)
cpp-options: -DENABLE_MONITORING
if !flag(disable-observables)
cpp-options: -DENABLE_OBSERVABLES
if flag(disable-examples)
buildable: False
executable example-performance
hs-source-dirs: examples/performance
main-is: Main.lhs
default-language: Haskell2010
default-extensions: OverloadedStrings
ghc-options: -threaded -Wall -O2 -with-rtsopts=-T
other-modules:
build-depends: base,
iohk-monitoring,
async,
criterion,
text,
unordered-containers
if flag(disable-examples) || !flag(performance-test-queue)
buildable: False

175
iohk-monitoring/src/Cardano/BM/Backend/Log.lhs

@ -23,6 +23,10 @@ module Cardano.BM.Backend.Log
, effectuate
, realize
, unrealize
, registerScribe
, sev2klog
-- * re-exports
, K.Scribe
) where
import Control.AutoUpdate (UpdateSettings (..), defaultUpdateSettings,
@ -56,26 +60,11 @@ import System.Directory (createDirectoryIfMissing)
import System.FilePath (takeDirectory)
import System.IO (BufferMode (LineBuffering), Handle, hClose,
hSetBuffering, stderr, stdout, openFile, IOMode (WriteMode))
#ifdef ENABLE_SYSTEMD
import Data.Aeson (encode)
import qualified Data.ByteString.Lazy as BL (toStrict)
import qualified Data.Text.Encoding as T (encodeUtf8)
import Language.Haskell.TH.Syntax (Loc(Loc, loc_filename, loc_start))
import Systemd.Journal (JournalFields, codeFile, codeLine, message,
mkJournalField, priority, sendJournalFields,
syslogFacility, syslogIdentifier)
import qualified Systemd.Journal as J
import System.Posix.Syslog (Facility)
#endif
import Paths_iohk_monitoring (version)
import qualified Katip as K
import qualified Katip.Core as KC
import Katip.Scribes.Handle (brackets)
#ifdef ENABLE_SYSTEMD
import Katip.Format.Time (formatAsIso8601)
#endif
import qualified Cardano.BM.Configuration as Config
import Cardano.BM.Configuration.Model (getScribes, getSetupScribes)
@ -175,42 +164,12 @@ instance ToJSON a => IsEffectuator Log a where
\subsubsection{Log implements backend functions}\index{Log!instance of IsBackend}
\begin{code}
instance (ToJSON a, FromJSON a) => IsBackend Log a where
typeof _ = KatipBK
bekind _ = KatipBK
realize config = do
let updateEnv :: K.LogEnv -> IO UTCTime -> K.LogEnv
updateEnv le timer =
le { K._logEnvTimer = timer, K._logEnvHost = "hostname" }
register :: [ScribeDefinition] -> K.LogEnv -> IO K.LogEnv
register [] le = return le
register (defsc : dscs) le = do
let kind = scKind defsc
sctype = scFormat defsc
name = scName defsc
rotParams = scRotation defsc
name' = pack (show kind) <> "::" <> name
scr <- createScribe kind sctype name rotParams
register dscs =<< K.registerScribe name' scr scribeSettings le
scribeSettings :: KC.ScribeSettings
scribeSettings =
let bufferSize = 5000 -- size of the queue (in log items)
in
KC.ScribeSettings bufferSize
createScribe FileSK ScText name rotParams = mkTextFileScribe
rotParams
(FileDescription $ unpack name)
False
createScribe FileSK ScJson name rotParams = mkJsonFileScribe
rotParams
(FileDescription $ unpack name)
False
#if defined(ENABLE_SYSTEMD)
createScribe JournalSK _ _ _ = mkJournalScribe
#endif
createScribe StdoutSK sctype _ _ = mkStdoutScribe sctype
createScribe StderrSK sctype _ _ = mkStderrScribe sctype
createScribe DevNullSK _ _ _ = mkDevNullScribe
cfoKey <- Config.getOptionOrDefault config (pack "cfokey") (pack "<unknown>")
le0 <- K.initLogEnv
(K.Namespace ["iohk"])
@ -219,7 +178,7 @@ instance (ToJSON a, FromJSON a) => IsBackend Log a where
timer <- mkAutoUpdate defaultUpdateSettings { updateAction = getCurrentTime, updateFreq = 10000 }
let le1 = updateEnv le0 timer
scribes <- getSetupScribes config
le <- register scribes le1
le <- registerScribes scribes le1
messageCounters <- resetCounters <$> getCurrentTime
@ -233,6 +192,50 @@ instance (ToJSON a, FromJSON a) => IsBackend Log a where
\end{code}
\subsubsection{Create and register \emph{katip} scribes}
\begin{code}
registerScribe :: Log a -> K.Scribe -> ScribeId -> IO ()
registerScribe katip scr name =
modifyMVar_ (getK katip) $ \k -> do
newenv <- K.registerScribe name scr scribeSettings (kLogEnv k)
return $ k { kLogEnv = newenv }
scribeSettings :: KC.ScribeSettings
scribeSettings =
let bufferSize = 5000 -- size of the queue (in log items)
in
KC.ScribeSettings bufferSize
registerScribes :: [ScribeDefinition] -> K.LogEnv -> IO K.LogEnv
registerScribes [] le = return le
registerScribes (defsc : dscs) le = do
let kind = scKind defsc
sctype = scFormat defsc
name = scName defsc
rotParams = scRotation defsc
name' = pack (show kind) <> "::" <> name
scr <- createScribe kind sctype name rotParams
registerScribes dscs =<< K.registerScribe name' scr scribeSettings le
where
createScribe FileSK ScText name rotParams = mkTextFileScribe
rotParams
(FileDescription $ unpack name)
False
createScribe FileSK ScJson name rotParams = mkJsonFileScribe
rotParams
(FileDescription $ unpack name)
False
-- createScribe JournalSK _ _ _ = mkJournalScribe
createScribe StdoutSK sctype _ _ = mkStdoutScribe sctype
createScribe StderrSK sctype _ _ = mkStderrScribe sctype
createScribe DevNullSK _ _ _ = mkDevNullScribe
createScribe UserDefinedSK ty nm rot = createScribe FileSK ty nm rot
\end{code}
\begin{spec}
example :: IO ()
example = do
@ -278,7 +281,7 @@ passN :: ToJSON a => ScribeId -> Log a -> LogObject a -> IO ()
passN backend katip (LogObject loname lometa loitem) = do
env <- kLogEnv <$> readMVar (getK katip)
forM_ (Map.toList $ K._logEnvScribes env) $
\(scName, (KC.ScribeHandle _ shChan)) ->
\(scName, (KC.ScribeHandle _ shChan)) -> do
-- check start of name to match |ScribeKind|
if backend `isPrefixOf` scName
then do
@ -497,7 +500,7 @@ mkFileScribe (Just rotParams) fdesc formatter colorize = do
mkFileScribe Nothing fdesc formatter colorize = do
let prefixDir = prefixPath fdesc
(createDirectoryIfMissing True prefixDir)
`catchIO` (prtoutException ("cannot log prefix directory: " ++ prefixDir))
`catchIO` (prtoutException ("cannot create prefix directory: " ++ prefixDir))
let fpath = filePath fdesc
h <- catchIO (openFile fpath WriteMode) $
\e -> do
@ -573,77 +576,3 @@ prefixPath :: FileDescription -> FilePath
prefixPath = takeDirectory . filePath
\end{code}
\begin{code}
#ifdef ENABLE_SYSTEMD
mkJournalScribe :: IO K.Scribe
mkJournalScribe = return $ journalScribe Nothing (sev2klog Debug) K.V3
-- taken from https://github.com/haskell-service/katip-libsystemd-journal
journalScribe :: Maybe Facility
-> K.Severity
-> K.Verbosity
-> K.Scribe
journalScribe facility severity verbosity = K.Scribe liPush scribeFinalizer
where
liPush :: K.LogItem a => K.Item a -> IO ()
liPush i = when (K.permitItem severity i) $
sendJournalFields $ itemToJournalFields facility verbosity i
scribeFinalizer :: IO ()
scribeFinalizer = pure ()
\end{code}
Converts a |Katip Item| into a libsystemd-journal |JournalFields| map.
\begin{code}
itemToJournalFields :: K.LogItem a
=> Maybe Facility
-> K.Verbosity
-> K.Item a
-> JournalFields
itemToJournalFields facility verbosity item = mconcat [ defaultFields item
, maybe HM.empty facilityFields facility
, maybe HM.empty locFields (K._itemLoc item)
]
where
defaultFields kItem =
mconcat [ message (TL.toStrict $ toLazyText $ KC.unLogStr (KC._itemMessage kItem))
, priority (mapSeverity (KC._itemSeverity kItem))
, syslogIdentifier (unNS (KC._itemApp kItem))
, HM.fromList [ (environment, T.encodeUtf8 $ KC.getEnvironment (KC._itemEnv kItem))
, (namespace, T.encodeUtf8 $ unNS (KC._itemNamespace kItem))
, (payload, BL.toStrict $ encode $ KC.payloadObject verbosity (KC._itemPayload kItem))
, (thread, T.encodeUtf8 $ KC.getThreadIdText (KC._itemThread kItem))
, (time, T.encodeUtf8 $ formatAsIso8601 (KC._itemTime kItem))
]
]
facilityFields = syslogFacility
locFields Loc{..} = mconcat [ codeFile loc_filename
, codeLine (fst loc_start)
]
environment = mkJournalField "environment"
namespace = mkJournalField "namespace"
payload = mkJournalField "payload"
thread = mkJournalField "thread"
time = mkJournalField "time"
unNS ns = case K.unNamespace ns of
[] -> T.empty
[p] -> p
parts -> T.intercalate "." parts
mapSeverity s = case s of
K.DebugS -> J.Debug
K.InfoS -> J.Info
K.NoticeS -> J.Notice
K.WarningS -> J.Warning
K.ErrorS -> J.Error
K.CriticalS -> J.Critical
K.AlertS -> J.Alert
K.EmergencyS -> J.Emergency
#endif
\end{code}

2
iohk-monitoring/src/Cardano/BM/Backend/LogBuffer.lhs

@ -78,7 +78,7 @@ instance IsEffectuator LogBuffer a where
|LogBuffer| is an |IsBackend|
\begin{code}
instance FromJSON a => IsBackend LogBuffer a where
typeof _ = LogBufferBK
bekind _ = LogBufferBK
realize _ = do
let emptyBuffer = LogBufferInternal HM.empty

200
iohk-monitoring/src/Cardano/BM/Backend/Switchboard.lhs

@ -18,31 +18,31 @@
module Cardano.BM.Backend.Switchboard
(
Switchboard
, MockSwitchboard (..)
, mainTraceConditionally
, traceMock
, readLogBuffer
, effectuate
, realize
, unrealize
, waitForTermination
-- * integrate external backend
, addUserDefinedBackend
, addExternalBackend
, addExternalScribe
) where
import qualified Control.Concurrent.Async as Async
import Control.Concurrent.MVar (MVar, newEmptyMVar, newMVar,
modifyMVar_, putMVar, readMVar, tryReadMVar, tryTakeMVar,
withMVar)
import Control.Concurrent.STM (TVar, atomically, modifyTVar, retry)
import Control.Concurrent.STM (atomically, retry)
import qualified Control.Concurrent.STM.TBQueue as TBQ
import Control.Exception.Safe (throwM)
import Control.Monad (forM_, when, void)
import Data.Aeson (FromJSON, ToJSON)
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import qualified Data.Text.IO as TIO
import Data.Time.Clock (getCurrentTime)
import qualified Katip as K
import System.IO (stderr)
import Cardano.BM.Configuration (Configuration)
@ -55,7 +55,7 @@ import Cardano.BM.Data.MessageCounter (resetCounters, sendAndResetAfte
updateMessageCounters)
import Cardano.BM.Data.Severity
import Cardano.BM.Data.SubTrace (SubTrace (..))
import Cardano.BM.Data.Tracer (Tracer (..), traceWith)
import Cardano.BM.Data.Tracer (Tracer (..))
import qualified Cardano.BM.Backend.TraceAcceptor
import qualified Cardano.BM.Backend.Log
import qualified Cardano.BM.Backend.LogBuffer
@ -67,26 +67,6 @@ import Cardano.BM.Backend.ExternalAbstraction (UnixNamedPipe)
import Cardano.BM.Backend.ExternalAbstraction (NoPipe)
#endif
#ifdef ENABLE_AGGREGATION
import qualified Cardano.BM.Backend.Aggregation
#endif
#ifdef ENABLE_EKG
import qualified Cardano.BM.Backend.EKGView
#endif
#ifdef ENABLE_GRAYLOG
import qualified Cardano.BM.Backend.Graylog
#endif
#ifdef ENABLE_MONITORING
import qualified Cardano.BM.Backend.Monitoring
#endif
#ifdef ENABLE_GUI
import qualified Cardano.BM.Backend.Editor
#endif
\end{code}
%endif
@ -104,6 +84,7 @@ data SwitchboardInternal a = SwitchboardInternal
{ sbQueue :: TBQ.TBQueue (LogObject a)
, sbDispatch :: Async.Async ()
, sbLogBuffer :: Cardano.BM.Backend.LogBuffer.LogBuffer a
, sbLogBE :: Cardano.BM.Backend.Log.Log a
, sbBackends :: NamedBackends a
}
@ -167,15 +148,13 @@ instance IsEffectuator Switchboard a where
|Switchboard| is an |IsBackend|
\begin{code}
instance (FromJSON a, ToJSON a) => IsBackend Switchboard a where
typeof _ = SwitchboardBK
bekind _ = SwitchboardBK
realize cfg = do
-- we setup |LogBuffer| explicitly so we can access it as a |Backend| and as |LogBuffer|
logbuf :: Cardano.BM.Backend.LogBuffer.LogBuffer a <- Cardano.BM.Backend.LogBuffer.realize cfg
let spawnDispatcher
:: Switchboard a
-> TBQ.TBQueue (LogObject a)
-> IO (Async.Async ())
katipBE :: Cardano.BM.Backend.Log.Log a <- Cardano.BM.Backend.Log.realize cfg
let spawnDispatcher :: Switchboard a -> TBQ.TBQueue (LogObject a) -> IO (Async.Async ())
spawnDispatcher switchboard queue = do
now <- getCurrentTime
let messageCounters = resetCounters now
@ -189,7 +168,7 @@ instance (FromJSON a, ToJSON a) => IsBackend Switchboard a where
when passSevFilter $ do
nocapacity <- atomically $ TBQ.isFullTBQueue q
if nocapacity
then putStrLn "Error: Switchboard's queue full, dropping log items!"
then TIO.hPutStrLn stderr "Error: Switchboard's queue full, dropping log items!"
else atomically $ TBQ.writeTBQueue q obj
Nothing -> pure ()
_timer <- Async.async $ sendAndResetAfter
@ -207,7 +186,7 @@ instance (FromJSON a, ToJSON a) => IsBackend Switchboard a where
selectedBackends <- getBackends cfg name
let selBEs = befilter selectedBackends
withMVar (getSB switchboard) $ \sb ->
forM_ (sbBackends sb) $ \(bek, be) ->
forM_ (sbBackends sb) $ \(bek, be) -> do
when (bek `elem` selBEs) (bEffectuate be nli)
qProc counters = do
@ -274,8 +253,12 @@ instance (FromJSON a, ToJSON a) => IsBackend Switchboard a where
{ bEffectuate = Cardano.BM.Backend.LogBuffer.effectuate logbuf
, bUnrealize = Cardano.BM.Backend.LogBuffer.unrealize logbuf
})
bs2 <- return (KatipBK, MkBackend
{ bEffectuate = Cardano.BM.Backend.Log.effectuate katipBE
, bUnrealize = Cardano.BM.Backend.Log.unrealize katipBE
})
let bs = bs1 : bs0
let bs = bs2 : bs1 : bs0
dispatcher <- spawnDispatcher sb q
-- link the given Async to the current thread, such that if the Async
-- raises an exception, that exception will be re-thrown in the current
@ -285,6 +268,7 @@ instance (FromJSON a, ToJSON a) => IsBackend Switchboard a where
sbQueue = q,
sbDispatch = dispatcher,
sbLogBuffer = logbuf,
sbLogBE = katipBE,
sbBackends = bs }
return sb
@ -306,14 +290,32 @@ instance (FromJSON a, ToJSON a) => IsBackend Switchboard a where
\end{code}
\subsubsection{Integrate with external backend}\label{code:addBackend}\index{addBackend}
\subsubsection{Integrate with external backend}\label{code:addUserDefinedBackend}\index{addUserDefinedBackend}
\begin{code}
addExternalBackend :: Switchboard a -> Backend a -> Text -> IO ()
addExternalBackend switchboard be name =
addUserDefinedBackend :: Switchboard a -> Backend a -> Text -> IO ()
addUserDefinedBackend switchboard be name =
modifyMVar_ (getSB switchboard) $ \sb ->
return $ sb { sbBackends = (UserDefinedBK name, be) : sbBackends sb }
\end{code}
\subsubsection{Integrate with external backend}\label{code:addExternalBackend}\index{addExternalBackend}
\begin{code}
addExternalBackend :: Switchboard a -> Backend a -> BackendKind -> IO ()
addExternalBackend switchboard be bk = do
modifyMVar_ (getSB switchboard) $ \sb ->
return $ sb { sbBackends = (bk, be) : sbBackends sb }
\end{code}
\subsubsection{Integrate with external \emph{katip} scribe}\label{code:addExternalScribe}\index{addExternalScribe}
\begin{code}
addExternalScribe :: Switchboard a -> K.Scribe -> Text -> IO ()
addExternalScribe switchboard sc name =
withMVar (getSB switchboard) $ \sb ->
Cardano.BM.Backend.Log.registerScribe (sbLogBE sb) sc name
\end{code}
\subsubsection{Waiting for the switchboard to terminate}\label{code:waitForTermination}\index{waitForTermination}
\begin{code}
waitForTermination :: Switchboard a -> IO ()
@ -333,7 +335,8 @@ readLogBuffer switchboard = do
\end{code}
\subsubsection{Realizing the backends according to configuration}\label{code:setupBackends}\index{Switchboard!setupBackends}
\subsubsection{Realizing the backends according to configuration}
\label{code:setupBackends}\index{Switchboard!setupBackends}
\begin{code}
setupBackends :: (FromJSON a, ToJSON a)
=> [BackendKind]
@ -351,94 +354,15 @@ setupBackends bes c sb = setupBackendsAcc bes []
setupBackend' :: (FromJSON a , ToJSON a) => BackendKind -> Configuration -> Switchboard a -> IO (Maybe (Backend a))
setupBackend' SwitchboardBK _ _ = fail "cannot instantiate a further Switchboard"
setupBackend' (UserDefinedBK _) _ _ = fail "cannot instantiate an user-defined backend"
#ifdef ENABLE_MONITORING
setupBackend' MonitoringBK c sb = do
let basetrace = mainTraceConditionally c sb
be :: Cardano.BM.Backend.Monitoring.Monitor a <- Cardano.BM.Backend.Monitoring.realizefrom c basetrace sb
return $ Just MkBackend
{ bEffectuate = Cardano.BM.Backend.Monitoring.effectuate be
, bUnrealize = Cardano.BM.Backend.Monitoring.unrealize be
}
#else
setupBackend' MonitoringBK _ _ = do
TIO.hPutStrLn stderr "disabled! will not setup backend 'Monitoring'"
return Nothing
#endif
#ifdef ENABLE_EKG
setupBackend' EKGViewBK c sb = do
let basetrace = mainTraceConditionally c sb
be :: Cardano.BM.Backend.EKGView.EKGView a <- Cardano.BM.Backend.EKGView.realizefrom c basetrace sb
return $ Just MkBackend
{ bEffectuate = Cardano.BM.Backend.EKGView.effectuate be
, bUnrealize = Cardano.BM.Backend.EKGView.unrealize be
}
#else
setupBackend' EKGViewBK _ _ = do
TIO.hPutStrLn stderr "disabled! will not setup backend 'EKGView'"
return Nothing
#endif
#ifdef ENABLE_AGGREGATION
setupBackend' AggregationBK c sb = do
let basetrace = mainTraceConditionally c sb
be :: Cardano.BM.Backend.Aggregation.Aggregation a <- Cardano.BM.Backend.Aggregation.realizefrom c basetrace sb
return $ Just MkBackend
{ bEffectuate = Cardano.BM.Backend.Aggregation.effectuate be
, bUnrealize = Cardano.BM.Backend.Aggregation.unrealize be
}
#else
setupBackend' AggregationBK _ _ = do
TIO.hPutStrLn stderr "disabled! will not setup backend 'Aggregation'"
return Nothing
#endif
#ifdef ENABLE_GUI
setupBackend' EditorBK c sb = do
port <- Config.getGUIport c
if port > 0
then do
let trace = mainTraceConditionally c sb
be :: Cardano.BM.Backend.Editor.Editor a <- Cardano.BM.Backend.Editor.realizefrom c trace sb
return $ Just MkBackend
{ bEffectuate = Cardano.BM.Backend.Editor.effectuate be
, bUnrealize = Cardano.BM.Backend.Editor.unrealize be
}
else
return Nothing
#else
setupBackend' EditorBK _ _ = do
TIO.hPutStrLn stderr "disabled! will not setup backend 'Editor'"
return Nothing
#endif
#ifdef ENABLE_GRAYLOG
setupBackend' GraylogBK c sb = do
port <- Config.getGraylogPort c
if port > 0
then do
let trace = mainTraceConditionally c sb
be :: Cardano.BM.Backend.Graylog.Graylog a <- Cardano.BM.Backend.Graylog.realizefrom c trace sb
return $ Just MkBackend
{ bEffectuate = Cardano.BM.Backend.Graylog.effectuate be
, bUnrealize = Cardano.BM.Backend.Graylog.unrealize be
}
else
return Nothing
#else
setupBackend' GraylogBK _ _ = do
TIO.hPutStrLn stderr "disabled! will not setup backend 'Graylog'"
return Nothing
#endif
setupBackend' KatipBK c _ = do
be :: Cardano.BM.Backend.Log.Log a <- Cardano.BM.Backend.Log.realize c
return $ Just MkBackend
{ bEffectuate = Cardano.BM.Backend.Log.effectuate be
, bUnrealize = Cardano.BM.Backend.Log.unrealize be
}
setupBackend' MonitoringBK _ _ = return Nothing
setupBackend' AggregationBK _ _ = return Nothing
setupBackend' EditorBK _ _ = return Nothing
setupBackend' GraylogBK _ _ = return Nothing
setupBackend' EKGViewBK _ _ = return Nothing
setupBackend' KatipBK _ _ = return Nothing
setupBackend' LogBufferBK _ _ = return Nothing
setupBackend' (TraceAcceptorBK pipePath) c sb = do
let basetrace = mainTraceConditionally c sb
be :: Cardano.BM.Backend.TraceAcceptor.TraceAcceptor PipeType a
<- Cardano.BM.Backend.TraceAcceptor.realizefrom basetrace pipePath
return $ Just MkBackend
@ -461,35 +385,3 @@ type PipeType =
#endif
\end{code}
\subsubsection{MockSwitchboard}\label{code:MockSwitchboard}\index{MockSwitchboard}
|MockSwitchboard| is useful for tests since it keeps the |LogObject|s
to be output in a list.
\begin{code}
newtype MockSwitchboard a = MockSB (TVar [LogObject a])
instance IsEffectuator MockSwitchboard a where
effectuate (MockSB tvar) item = atomically $ modifyTVar tvar ((:) item)
handleOverflow _ = pure ()
\end{code}
\subsubsection{traceMock}\label{code:traceMock}\index{traceMock}
A |Tracer| which forwards |LogObject|s to |MockSwitchboard| simulating
functionality of |mainTraceConditionally|.
\begin{code}
traceMock :: MockSwitchboard a -> Config.Configuration -> Tracer IO (LogObject a)
traceMock ms config =
Tracer $ \item@(LogObject loggername _ _) -> do
traceWith mainTrace item