Skip to content

Deduplicate Metric Definitions #44

@koduruprasanth

Description

@koduruprasanth

The metric definitions are duplicated as many times as the metric is added in the JSON structure. Ideally the metrics definition need to be defined only once per metric. In the below example the metric definition for Items is added 4 times to the Metrics array.

Sample Kotlin Code

    @JvmStatic
    fun main(args: Array<String>) {
        val metrics = MetricsLogger()
        metrics.putDimensions(DimensionSet.of("Service", "Aggregator"))
        metrics.putMetric("ProcessingLatency", 100.0, Unit.MILLISECONDS)
        metrics.putMetric("Items", 1.0, Unit.COUNT)
        metrics.putMetric("Items", 1.0, Unit.COUNT)
        metrics.putMetric("Items", 1.0, Unit.COUNT)
        metrics.putMetric("Items", 1.0, Unit.COUNT)
        metrics.putProperty("RequestId", "422b1569-16f6-4a03-b8f0-fe3fd9b100f8")
        metrics.flush()
    }

Output JSON

{
   "_aws":{
      "Timestamp":1601181946745,
      "CloudWatchMetrics":[
         {
            "Namespace":"aws-embedded-metrics",
            "Metrics":[
               {
                  "Name":"ProcessingLatency",
                  "Unit":"Milliseconds"
               },
               {
                  "Name":"Items",
                  "Unit":"Count"
               },
               {
                  "Name":"Items",
                  "Unit":"Count"
               },
               {
                  "Name":"Items",
                  "Unit":"Count"
               },
               {
                  "Name":"Items",
                  "Unit":"Count"
               }
            ],
            "Dimensions":[
               [
                  "LogGroup",
                  "ServiceName",
                  "ServiceType",
                  "Service"
               ]
            ]
         }
      ]
   },
   "RequestId":"422b1569-16f6-4a03-b8f0-fe3fd9b100f8",
   "ProcessingLatency":100.0,
   "LogGroup":"Unknown-metrics",
   "ServiceName":"Unknown",
   "ServiceType":"Unknown",
   "Service":"Aggregator",
   "Items":[
      1.0,
      1.0,
      1.0,
      1.0
   ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions