Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change adaptive sample groups to use Globs #1053

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions core/kamon-core/src/main/scala/kamon/trace/AdaptiveSampler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ package kamon
package trace

import java.util.concurrent.ThreadLocalRandom

import com.typesafe.config.Config
import kamon.jsr166.LongAdder
import kamon.trace.AdaptiveSampler.{Allocation, OperationSampler, Settings}
import kamon.trace.Trace.SamplingDecision
import kamon.util.EWMA
import kamon.util.{EWMA, Filter}

import scala.collection.JavaConverters.collectionAsScalaIterableConverter
import scala.collection.concurrent.TrieMap
Expand Down Expand Up @@ -67,7 +66,7 @@ class AdaptiveSampler extends Sampler {

private def buildOperationSampler(operationName: String): AdaptiveSampler.OperationSampler = synchronized {
_settings.groups
.find(g => g.operations.contains(operationName))
.find(g => g.operations.exists(_.accept(operationName)))
.map(group => {
group.rules.sample
.map(fixedSamplingDecision => new OperationSampler.Constant(operationName, fixedSamplingDecision))
Expand Down Expand Up @@ -244,7 +243,7 @@ object AdaptiveSampler {
*/
case class Group (
name: String,
operations: Seq[String],
operations: Seq[Filter],
rules: Rules
)

Expand Down Expand Up @@ -275,7 +274,7 @@ object AdaptiveSampler {

Settings.Group(
name = groupName,
operations = groupConfig.getStringList("operations").asScala.toSeq,
operations = groupConfig.getStringList("operations").asScala.toSeq.map(Filter.fromGlob),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't like this, for two reasons:

  1. We should allow people to use regular expressions, if they want to
  2. This is not backwards compatible! We know some people have already set it up to raw strings.

What I suggest we do is:

  1. Copy logic from
    def fromGlob(glob: String): Filter =
  2. Change it so that the default is not glob, but it's exact match (a new type of filter, I guess, Filter.StringMatch or something)
  3. Immediately announce exact match as deprecated
  4. Move to default-to-glob in the next minor version (2.3.0, I guess)

Thoughts, @SimunKaracic , @ivantopo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming you mean this under 1.

private def readMatcher(pattern: String): Filter.Matcher = {

That all sounds like a great idea

rules = readRules(groupConfig.getConfig("rules"))
)
}.toSeq
Expand All @@ -290,8 +289,9 @@ object AdaptiveSampler {
maximumThroughput = ifExists(config, "maximum-throughput", _.getDouble)
)

private def toSamplingDecision(text: String): SamplingDecision =
private def toSamplingDecision(text: String): SamplingDecision = {
if (text.equalsIgnoreCase("always")) SamplingDecision.Sample else SamplingDecision.DoNotSample
}

private def ifExists[T](config: Config, path: String, extract: Config => String => T): Option[T] =
if (config.hasPath(path)) Option(extract(config)(path)) else None
Expand Down Expand Up @@ -397,4 +397,4 @@ object AdaptiveSampler {
s"Constant{operation=$operationName, probability=${_probability}"
}
}
}
}
10 changes: 9 additions & 1 deletion core/kamon-core/src/main/scala/kamon/trace/Span.scala
Original file line number Diff line number Diff line change
Expand Up @@ -656,10 +656,17 @@ object Span {
}
}


private def convertSamplingDecisionToTag: String = {
if (isSampled) {
"sampled"
} else {
"not-sampled"
}
}
private def createMetricTags(): TagSet = {
_metricTags.add(TagKeys.OperationName, _operationName)
_metricTags.add(TagKeys.Error, _hasError)
_metricTags.add(TagKeys.SampleDecision, convertSamplingDecisionToTag)

if(kind != Span.Kind.Unknown)
_metricTags.add(TagKeys.SpanKind, kind.toString)
Expand Down Expand Up @@ -793,6 +800,7 @@ object Span {
val ParentOperationName = "parentOperation"
val SpanKind = "span.kind"
val UpstreamName = "upstream.name"
val SampleDecision = "span.sample-decision"
}

object MarkKeys {
Expand Down