Skip to content

Commit

Permalink
finagle-stats: Track metrics name collisions
Browse files Browse the repository at this point in the history
Problem

Metrics recorded in a scope Seq("foo", "bar") can collide with Seq("foo/bar") when exporting
the metrics to JSON, where one is arbitrarily picked. This hides metrics bugs in application code.

Solution

Add a default-off flag to throw an exception when colliding stats are created in the common cases,
and a lint rule that catches most cases (histogram names can be tricky).

Result

Bugs in application metrics are much easier to find for users.

Note: I assumed performance is important in the metrics implementation, so I avoided
using an extra map to detect duplicate names in favor of using the existing map.
All of this could be simplified if we used a second map,
or if the canonical names were the formatted strings.

JIRA Issues: CSL-6578

Differential Revision: https://phabricator.twitter.biz/D183494
  • Loading branch information
Michael Solomon authored and jenkins committed Jun 22, 2018
1 parent 3cd9945 commit 5dfe6b9
Showing 1 changed file with 11 additions and 0 deletions.
@@ -0,0 +1,11 @@
package com.twitter.finagle.stats

import com.twitter.util.lint.Rule

/**
* A [[StatsReceiver]] that provides a linting rule to track metrics that have different underlying
* names, yet are exported under the same name.
*/
trait CollisionTrackingStatsReceiver {
def metricsCollisionsLinterRule: Rule
}

0 comments on commit 5dfe6b9

Please sign in to comment.