aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/main/scala/kamon/status/Status.scala
blob: 5c6d7cb0a94168313bc7cffc231a18c2cb494357 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package kamon.status

import com.typesafe.config.Config
import kamon.metric.InstrumentFactory.InstrumentType
import kamon.metric.{MeasurementUnit, MetricRegistry}
import kamon.{Configuration, Environment, Kamon}
import kamon.module.ModuleRegistry
import kamon.module.Module.{Kind => ModuleKind}
import java.util.{Collections, List => JavaList, Map => JavaMap}

/**
  * Exposes Kamon components' status information. This is meant to be used for informational and debugging purposes and
  * by no means should replace the use of reporters to extract information from Kamon.
  */
class Status(_moduleRegistry: ModuleRegistry, _metricRegistry: MetricRegistry, configuration: Configuration) {

  /**
    * Settings currently used by Kamon.
    */
  def settings(): Status.Settings =
    Status.Settings(BuildInfo.version, Kamon.environment, configuration.config())

  /**
    * Status of the module registry. Describes what modules have been detected and registered, either from the classpath
    * or programmatically and their current status.
    */
  def moduleRegistry(): Status.ModuleRegistry =
    _moduleRegistry.status()

  /**
    * Status of the metric registry. Describes all metrics currently tracked by Kamon.
    */
  def metricRegistry(): Status.MetricRegistry =
    _metricRegistry.status()


  /**
    * Status of instrumentation modules that have been detected and/or loaded into the current JVM. Read the
    * [[Status.Instrumentation]] companion object's docs for more information.
    */
  def instrumentation(): Status.Instrumentation = {
    import Status.Instrumentation._

    Status.Instrumentation(
      isActive(),
      modules(),
      errors()
    )
  }
}



object Status {

  case class Settings(
    version: String,
    environment: Environment,
    config: Config
  )


  case class ModuleRegistry(
    modules: Seq[Module]
  )

  case class Module(
    name: String,
    description: String,
    clazz: String,
    kind: ModuleKind,
    programmaticallyRegistered: Boolean,
    enabled: Boolean,
    started: Boolean
  )

  case class MetricRegistry(
    metrics: Seq[Metric]
  )

  case class Metric(
    name: String,
    tags: Map[String, String],
    unit: MeasurementUnit,
    instrumentType: InstrumentType
  )


  /**
    * Status of the instrumentation modules. This data is completely untyped and not expected to be used anywhere
    * outside Kamon.
    */
  private[kamon] case class Instrumentation(
    active: Boolean,
    modules: JavaMap[String, String],
    errors: JavaMap[String, JavaList[Throwable]]
  )


  /**
    * This object works as a bridge between Kamon and Kanela to gather information about instrumentation modules. When
    * instrumentation is enabled, it should replace the implementation of the members of this object and return proper
    * information.
    *
    * This data is only exposed directly to the status page API because it lacks any sort of type safety. We might
    * change this in the future and provide proper types for all instrumentation modules' info.
    */
  private[kamon] object Instrumentation {

    /**
      * Whether instrumentation is active or not. When Kanela is present it will replace this method to return true.
      */
    def isActive(): java.lang.Boolean =
      false

    /**
      * List all instrumentation modules known and their current status. The result map contains the module name as keys
      * and a JSON representation of the module status as values. The expected structure in the JSON representations is
      * as follows:
      *
      *   {
      *     'description': 'A explicative module description',
      *     'isEnabled': true | false,
      *     'isActive': true | false
      *   }
      *
      *  The "isEnabled" flag tells whether the module is able to instrument classes or not. By default, all modules are
      *  able to instrument classes but some modules might be shipped in a disabled state or forced to be disabled via
      *  configuration.
      *
      *  The "isActive" flag tells whether the modules has already applied instrumentation to any of its target classes.
      *
      */
    def modules(): JavaMap[String, String] =
      Collections.emptyMap()


    /**
      * List all errors that might have happened during the instrumentation initialization. The resulting map contains
      * a list of modules and any exceptions thrown by them during initialization. If not exceptions are thrown the map
      * will always be empty.
      */
    def errors(): JavaMap[String, JavaList[Throwable]] =
      Collections.emptyMap()
  }
}