From 2cc7eeee6fe31a4dfd479f3c0abf1085c7bbf879 Mon Sep 17 00:00:00 2001 From: Diego Date: Sat, 7 Feb 2015 14:26:26 -0300 Subject: ! kamon-annotation: defined instruments @Trace @Segment @Gauge @Timed @Counted @Histogram and full implemetation --- .../main/scala/kamon/annotation/Annotation.scala | 34 ++++ .../kamon/annotation/el/ELProcessorFactory.scala | 40 +++++ .../kamon/annotation/el/EnhancedELProcessor.scala | 60 +++++++ .../AnnotationInstrumentation.scala | 81 ++++++++++ .../BaseAnnotationInstrumentation.scala | 178 +++++++++++++++++++++ .../StaticAnnotationInstrumentation.scala | 101 ++++++++++++ 6 files changed, 494 insertions(+) create mode 100644 kamon-annotation/src/main/scala/kamon/annotation/Annotation.scala create mode 100644 kamon-annotation/src/main/scala/kamon/annotation/el/ELProcessorFactory.scala create mode 100644 kamon-annotation/src/main/scala/kamon/annotation/el/EnhancedELProcessor.scala create mode 100644 kamon-annotation/src/main/scala/kamon/annotation/instrumentation/AnnotationInstrumentation.scala create mode 100644 kamon-annotation/src/main/scala/kamon/annotation/instrumentation/BaseAnnotationInstrumentation.scala create mode 100644 kamon-annotation/src/main/scala/kamon/annotation/instrumentation/StaticAnnotationInstrumentation.scala (limited to 'kamon-annotation/src/main/scala') diff --git a/kamon-annotation/src/main/scala/kamon/annotation/Annotation.scala b/kamon-annotation/src/main/scala/kamon/annotation/Annotation.scala new file mode 100644 index 00000000..6ddf57cf --- /dev/null +++ b/kamon-annotation/src/main/scala/kamon/annotation/Annotation.scala @@ -0,0 +1,34 @@ +/* ========================================================================================= + * Copyright © 2013-2015 the kamon project + * + * 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. + * ========================================================================================= + */ + +package kamon.annotation + +import akka.actor.{ ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider } +import akka.event.Logging +import kamon.Kamon + +object Annotation extends ExtensionId[AnnotationExtension] with ExtensionIdProvider { + override def lookup(): ExtensionId[_ <: Extension] = Annotation + override def createExtension(system: ExtendedActorSystem): AnnotationExtension = new AnnotationExtension(system) +} + +class AnnotationExtension(system: ExtendedActorSystem) extends Kamon.Extension { + val log = Logging(system, classOf[AnnotationExtension]) + log.info(s"Starting the Kamon(Annotation) extension") + + val config = system.settings.config.getConfig("kamon.annotation") + val arraySize = config.getInt("instruments-array-size") +} + diff --git a/kamon-annotation/src/main/scala/kamon/annotation/el/ELProcessorFactory.scala b/kamon-annotation/src/main/scala/kamon/annotation/el/ELProcessorFactory.scala new file mode 100644 index 00000000..e80c61d8 --- /dev/null +++ b/kamon-annotation/src/main/scala/kamon/annotation/el/ELProcessorFactory.scala @@ -0,0 +1,40 @@ +/* + * ========================================================================================= + * Copyright © 2013-2015 the kamon project + * + * 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. + * ========================================================================================= + */ + +package kamon.annotation.el + +import javax.el.ELProcessor +import kamon.annotation.el.resolver.PrivateFieldELResolver + +object ELProcessorFactory { + def withClass(clazz: Class[_]): ELProcessor = { + val processor = create() + processor.getELManager.importClass(clazz.getName) + processor + } + + def withObject(obj: AnyRef): ELProcessor = { + val processor = withClass(obj.getClass) + processor.defineBean("this", obj) + processor + } + + private def create(): ELProcessor = { + val processor = new ELProcessor() + processor.getELManager.addELResolver(new PrivateFieldELResolver()) + processor + } +} diff --git a/kamon-annotation/src/main/scala/kamon/annotation/el/EnhancedELProcessor.scala b/kamon-annotation/src/main/scala/kamon/annotation/el/EnhancedELProcessor.scala new file mode 100644 index 00000000..f407930b --- /dev/null +++ b/kamon-annotation/src/main/scala/kamon/annotation/el/EnhancedELProcessor.scala @@ -0,0 +1,60 @@ +/* + * ========================================================================================= + * Copyright © 2013-2015 the kamon project + * + * 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. + * ========================================================================================= + */ + +package kamon.annotation.el + +import javax.el.ELProcessor + +import kamon.Kamon +import kamon.annotation.Annotation + +import scala.util.{ Failure, Success, Try } + +/** + * Pimp ELProcessor injecting some useful methods. + */ +object EnhancedELProcessor { + private val Pattern = """[#|$]\{(.*)\}""".r + + implicit class Syntax(val processor: ELProcessor) extends AnyVal { + import scala.collection.JavaConverters._ + + def evalToString(expression: String): String = extract(expression).map { str ⇒ + eval[String](str) match { + case Success(value) ⇒ value + case Failure(cause) ⇒ + Kamon(Annotation).log.error(s"${cause.getMessage} -> we will complete the operation with 'unknown' string") + "unknown" + } + } getOrElse expression + + def evalToMap(expression: String): Map[String, String] = extract(expression).map { str ⇒ + eval[Map[String, String]](s"{$str}") match { + case Success(value) ⇒ value.asInstanceOf[java.util.HashMap[String, String]].asScala.toMap + case Failure(cause) ⇒ + Kamon(Annotation).log.error(s"${cause.getMessage} -> we will complete the operation with an empty map") + Map.empty[String, String] + } + } getOrElse Map.empty[String, String] + + private def eval[A](str: String): Try[A] = Try(processor.eval(str).asInstanceOf[A]) + + private def extract(expression: String): Option[String] = expression match { + case Pattern(ex) ⇒ Some(ex) + case _ ⇒ None + } + } +} diff --git a/kamon-annotation/src/main/scala/kamon/annotation/instrumentation/AnnotationInstrumentation.scala b/kamon-annotation/src/main/scala/kamon/annotation/instrumentation/AnnotationInstrumentation.scala new file mode 100644 index 00000000..381aeb72 --- /dev/null +++ b/kamon-annotation/src/main/scala/kamon/annotation/instrumentation/AnnotationInstrumentation.scala @@ -0,0 +1,81 @@ +/* + * ========================================================================================= + * Copyright © 2013-2015 the kamon project + * + * 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. + * ========================================================================================= + */ + +package kamon.annotation.instrumentation + +import kamon.Kamon +import kamon.annotation._ +import kamon.metric.instrument +import kamon.metric.instrument.{ MinMaxCounter, Counter } +import org.aspectj.lang.annotation._ +import org.aspectj.lang.{ JoinPoint, ProceedingJoinPoint } +import java.util.concurrent.atomic.AtomicReferenceArray + +@Aspect +class AnnotationInstrumentation extends BaseAnnotationInstrumentation { + + @After("execution((@kamon.annotation.EnableKamon AnnotationInstruments+).new(..)) && this(obj)") + def creation(jps: JoinPoint.StaticPart, obj: AnnotationInstruments): Unit = { + val size = Kamon(Annotation).arraySize + obj.traces = new AtomicReferenceArray[TraceContextInfo](size) + obj.segments = new AtomicReferenceArray[SegmentInfo](size) + obj.counters = new AtomicReferenceArray[Counter](size) + obj.minMaxCounters = new AtomicReferenceArray[MinMaxCounter](size) + obj.histograms = new AtomicReferenceArray[instrument.Histogram](size) + } + + @Around("execution(@kamon.annotation.Trace !static * (@kamon.annotation.EnableKamon AnnotationInstruments+).*(..)) && this(obj)") + def trace(pjp: ProceedingJoinPoint, obj: AnnotationInstruments): AnyRef = { + var traceInfo = obj.traces.get(pjp.getStaticPart.getId) + if (traceInfo == null) traceInfo = registerTrace(pjp.getStaticPart, obj.traces, StringEvaluator(obj), TagsEvaluator(obj)) + processTrace(traceInfo, pjp) + } + + @Around("execution(@kamon.annotation.Segment !static * (@kamon.annotation.EnableKamon AnnotationInstruments+).*(..)) && this(obj)") + def segment(pjp: ProceedingJoinPoint, obj: AnnotationInstruments): AnyRef = { + var segmentInfo = obj.segments.get(pjp.getStaticPart.getId) + if (segmentInfo == null) segmentInfo = registerSegment(pjp.getStaticPart, obj.segments, StringEvaluator(obj), TagsEvaluator(obj)) + processSegment(segmentInfo, pjp) + } + + @Around("execution(@kamon.annotation.Time !static * (@kamon.annotation.EnableKamon AnnotationInstruments+).*(..)) && this(obj)") + def time(pjp: ProceedingJoinPoint, obj: AnnotationInstruments): AnyRef = { + var histogram = obj.histograms.get(pjp.getStaticPart.getId) + if (histogram == null) histogram = registerTime(pjp.getStaticPart, obj.histograms, StringEvaluator(obj), TagsEvaluator(obj)) + processTime(histogram, pjp) + } + + @Around("execution(@kamon.annotation.Count !static * (@kamon.annotation.EnableKamon AnnotationInstruments+).*(..)) && this(obj)") + def count(pjp: ProceedingJoinPoint, obj: AnnotationInstruments): AnyRef = { + var counter = obj.counters.get(pjp.getStaticPart.getId) + if (counter == null) counter = registerCounter(pjp.getStaticPart, obj.counters, StringEvaluator(obj), TagsEvaluator(obj)) + processCount(counter, pjp) + } + + @Around("execution(@kamon.annotation.MinMaxCount !static * (@kamon.annotation.EnableKamon AnnotationInstruments+).*(..)) && this(obj)") + def minMax(pjp: ProceedingJoinPoint, obj: AnnotationInstruments): AnyRef = { + var minMax = obj.minMaxCounters.get(pjp.getStaticPart.getId) + if (minMax == null) minMax = registerMinMaxCounter(pjp.getStaticPart, obj.minMaxCounters, StringEvaluator(obj), TagsEvaluator(obj)) + processMinMax(minMax, pjp) + } + + @AfterReturning(pointcut = "execution(@kamon.annotation.Histogram !static (int || long || double || float) (@kamon.annotation.EnableKamon AnnotationInstruments+).*(..)) && this(obj)", returning = "result") + def histogram(jps: JoinPoint.StaticPart, obj: AnnotationInstruments, result: AnyRef): Unit = { + var histogram = obj.histograms.get(jps.getId) + if (histogram == null) histogram = registerHistogram(jps, obj.histograms, StringEvaluator(obj), TagsEvaluator(obj)) + processHistogram(histogram, result, jps) + } +} diff --git a/kamon-annotation/src/main/scala/kamon/annotation/instrumentation/BaseAnnotationInstrumentation.scala b/kamon-annotation/src/main/scala/kamon/annotation/instrumentation/BaseAnnotationInstrumentation.scala new file mode 100644 index 00000000..57e8c4d7 --- /dev/null +++ b/kamon-annotation/src/main/scala/kamon/annotation/instrumentation/BaseAnnotationInstrumentation.scala @@ -0,0 +1,178 @@ +/* + * ========================================================================================= + * Copyright © 2013-2015 the kamon project + * + * 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. + * ========================================================================================= + */ + +package kamon.annotation.instrumentation + +import java.util.concurrent.atomic.AtomicReferenceArray +import javax.el.ELProcessor + +import kamon.Kamon +import kamon.annotation.el.{ EnhancedELProcessor, ELProcessorFactory } +import kamon.annotation.{ Histogram, _ } +import kamon.metric.instrument.Histogram.DynamicRange +import kamon.metric.instrument.{ Counter, MinMaxCounter } +import kamon.metric._ +import kamon.trace.Tracer +import kamon.util.Latency +import org.aspectj.lang.{ JoinPoint, ProceedingJoinPoint } +import org.aspectj.lang.annotation.{ Aspect, DeclareMixin } +import org.aspectj.lang.reflect.MethodSignature +import EnhancedELProcessor.Syntax + +class BaseAnnotationInstrumentation { + + @inline final def registerTime(jps: JoinPoint.StaticPart, histograms: AtomicReferenceArray[instrument.Histogram], evalString: StringEvaluator, evalTags: TagsEvaluator): instrument.Histogram = { + val method = jps.getSignature.asInstanceOf[MethodSignature].getMethod + val time = method.getAnnotation(classOf[Time]) + val name = evalString(time.name()) + val tags = evalTags(time.tags()) + val currentHistogram = Kamon.simpleMetrics.histogram(HistogramKey(name, tags)) + histograms.set(jps.getId, currentHistogram) + currentHistogram + } + + @inline final def registerHistogram(jps: JoinPoint.StaticPart, histograms: AtomicReferenceArray[instrument.Histogram], evalString: StringEvaluator, evalTags: TagsEvaluator): instrument.Histogram = { + val method = jps.getSignature.asInstanceOf[MethodSignature].getMethod + val histogram = method.getAnnotation(classOf[Histogram]) + val name = evalString(histogram.name()) + val tags = evalTags(histogram.tags()) + val dynamicRange = DynamicRange(histogram.lowestDiscernibleValue(), histogram.highestTrackableValue(), histogram.precision()) + val currentHistogram = Kamon.simpleMetrics.histogram(HistogramKey(name, tags), dynamicRange) + histograms.set(jps.getId, currentHistogram) + currentHistogram + } + + @inline final def registerMinMaxCounter(jps: JoinPoint.StaticPart, minMaxCounters: AtomicReferenceArray[MinMaxCounter], evalString: StringEvaluator, evalTags: TagsEvaluator): instrument.MinMaxCounter = { + val method = jps.getSignature.asInstanceOf[MethodSignature].getMethod + val minMaxCount = method.getAnnotation(classOf[MinMaxCount]) + val name = evalString(minMaxCount.name()) + val tags = evalTags(minMaxCount.tags()) + val minMaxCounter = Kamon.simpleMetrics.minMaxCounter(MinMaxCounterKey(name, tags)) + minMaxCounters.set(jps.getId, minMaxCounter) + minMaxCounter + } + + @inline final def registerCounter(jps: JoinPoint.StaticPart, counters: AtomicReferenceArray[Counter], evalString: StringEvaluator, evalTags: TagsEvaluator): instrument.Counter = { + val method = jps.getSignature.asInstanceOf[MethodSignature].getMethod + val count = method.getAnnotation(classOf[Count]) + val name = evalString(count.name()) + val tags = evalTags(count.tags()) + val counter = Kamon.simpleMetrics.counter(CounterKey(name, tags)) + counters.set(jps.getId, counter) + counter + } + + @inline final def registerTrace(jps: JoinPoint.StaticPart, traces: AtomicReferenceArray[TraceContextInfo], evalString: StringEvaluator, evalTags: TagsEvaluator): TraceContextInfo = { + val method = jps.getSignature.asInstanceOf[MethodSignature].getMethod + val trace = method.getAnnotation(classOf[Trace]) + val name = evalString(trace.value()) + val tags = evalTags(trace.tags()) + val traceContextInfo = TraceContextInfo(name, tags) + traces.set(jps.getId, traceContextInfo) + traceContextInfo + } + + @inline final def registerSegment(jps: JoinPoint.StaticPart, segments: AtomicReferenceArray[SegmentInfo], evalString: StringEvaluator, evalTags: TagsEvaluator): SegmentInfo = { + val method = jps.getSignature.asInstanceOf[MethodSignature].getMethod + val segment = method.getAnnotation(classOf[Segment]) + val name = evalString(segment.name()) + val category = evalString(segment.category()) + val library = evalString(segment.library()) + val tags = evalTags(segment.tags()) + val segmentInfo = SegmentInfo(name, category, library, tags) + segments.set(jps.getId, segmentInfo) + segmentInfo + } + + @inline final def processTrace(traceInfo: TraceContextInfo, pjp: ProceedingJoinPoint): AnyRef = { + Tracer.withContext(Kamon.tracer.newContext(traceInfo.name)) { + traceInfo.tags.foreach { case (key, value) ⇒ Tracer.currentContext.addMetadata(key, value) } + val result = pjp.proceed() + Tracer.currentContext.finish() + result + } + } + + @inline final def processSegment(segmentInfo: SegmentInfo, pjp: ProceedingJoinPoint): AnyRef = { + Tracer.currentContext.collect { ctx ⇒ + val currentSegment = ctx.startSegment(segmentInfo.name, segmentInfo.category, segmentInfo.library) + segmentInfo.tags.foreach { case (key, value) ⇒ currentSegment.addMetadata(key, value) } + val result = pjp.proceed() + currentSegment.finish() + result + } getOrElse pjp.proceed() + } + + @inline final def processTime(histogram: instrument.Histogram, pjp: ProceedingJoinPoint): AnyRef = { + Latency.measure(histogram)(pjp.proceed) + } + + @inline final def processHistogram(histogram: instrument.Histogram, result: AnyRef, jps: JoinPoint.StaticPart): Unit = { + histogram.record(result.asInstanceOf[Number].longValue()) + } + + final def processCount(counter: instrument.Counter, pjp: ProceedingJoinPoint): AnyRef = { + try pjp.proceed() finally counter.increment() + } + + final def processMinMax(minMaxCounter: instrument.MinMaxCounter, pjp: ProceedingJoinPoint): AnyRef = { + minMaxCounter.increment() + try pjp.proceed() finally minMaxCounter.decrement() + } + + private[annotation] def declaringType(signature: org.aspectj.lang.Signature) = signature.getDeclaringType +} + +@Aspect +class ClassToAnnotationInstrumentsMixin { + @DeclareMixin("(@kamon.annotation.EnableKamon *)") + def mixinClassToAnnotationInstruments: AnnotationInstruments = new AnnotationInstruments {} +} + +trait AnnotationInstruments { + var traces: AtomicReferenceArray[TraceContextInfo] = _ + var segments: AtomicReferenceArray[SegmentInfo] = _ + var histograms: AtomicReferenceArray[instrument.Histogram] = _ + var counters: AtomicReferenceArray[Counter] = _ + var minMaxCounters: AtomicReferenceArray[MinMaxCounter] = _ +} + +case class SegmentInfo(name: String, category: String, library: String, tags: Map[String, String]) +case class TraceContextInfo(name: String, tags: Map[String, String]) + +abstract class StringEvaluator(val processor: ELProcessor) extends (String ⇒ String) + +object StringEvaluator { + def apply(obj: AnyRef) = new StringEvaluator(ELProcessorFactory.withObject(obj)) { + def apply(str: String) = processor.evalToString(str) + } + + def apply(clazz: Class[_]) = new StringEvaluator(ELProcessorFactory.withClass(clazz)) { + def apply(str: String) = processor.evalToString(str) + } +} + +abstract class TagsEvaluator(val processor: ELProcessor) extends (String ⇒ Map[String, String]) + +object TagsEvaluator { + def apply(obj: AnyRef) = new TagsEvaluator(ELProcessorFactory.withObject(obj)) { + def apply(str: String) = processor.evalToMap(str) + } + + def apply(clazz: Class[_]) = new TagsEvaluator(ELProcessorFactory.withClass(clazz)) { + def apply(str: String) = processor.evalToMap(str) + } +} \ No newline at end of file diff --git a/kamon-annotation/src/main/scala/kamon/annotation/instrumentation/StaticAnnotationInstrumentation.scala b/kamon-annotation/src/main/scala/kamon/annotation/instrumentation/StaticAnnotationInstrumentation.scala new file mode 100644 index 00000000..f5677377 --- /dev/null +++ b/kamon-annotation/src/main/scala/kamon/annotation/instrumentation/StaticAnnotationInstrumentation.scala @@ -0,0 +1,101 @@ +/* + * ========================================================================================= + * Copyright © 2013-2015 the kamon project + * + * 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. + * ========================================================================================= + */ + +package kamon.annotation.instrumentation + +import java.util.concurrent.atomic.AtomicReferenceArray + +import kamon.Kamon +import kamon.annotation.Annotation +import kamon.metric.instrument +import kamon.metric.instrument.{ Counter, MinMaxCounter } +import org.aspectj.lang.annotation.{ After, AfterReturning, Around, Aspect } +import org.aspectj.lang.{ JoinPoint, ProceedingJoinPoint } + +@Aspect("pertypewithin(kamon.annotation.instrumentation.AnnotationInstruments+ && !kamon.annotation.instrumentation.*)") +class StaticAnnotationInstrumentation extends BaseAnnotationInstrumentation with AnnotationInstruments { + + println("statics") + @After("staticinitialization(*) && !within(kamon.annotation.instrumentation.*)") + def creation(jps: JoinPoint.StaticPart): Unit = { + val size = Kamon(Annotation).arraySize + traces = new AtomicReferenceArray[TraceContextInfo](size) + segments = new AtomicReferenceArray[SegmentInfo](size) + counters = new AtomicReferenceArray[Counter](size) + minMaxCounters = new AtomicReferenceArray[MinMaxCounter](size) + histograms = new AtomicReferenceArray[instrument.Histogram](size) + } + + @Around("execution(@kamon.annotation.Trace static * (@kamon.annotation.EnableKamon *).*(..))") + def trace(pjp: ProceedingJoinPoint): AnyRef = { + var traceInfo = traces.get(pjp.getStaticPart.getId) + if (traceInfo == null) { + val clazz = declaringType(pjp.getSignature) + traceInfo = registerTrace(pjp.getStaticPart, traces, StringEvaluator(clazz), TagsEvaluator(clazz)) + } + processTrace(traceInfo, pjp) + } + + @Around("execution(@kamon.annotation.Segment static * (@kamon.annotation.EnableKamon *).*(..))") + def segment(pjp: ProceedingJoinPoint): AnyRef = { + var segmentInfo = segments.get(pjp.getStaticPart.getId) + if (segmentInfo == null) { + val clazz = declaringType(pjp.getSignature) + segmentInfo = registerSegment(pjp.getStaticPart, segments, StringEvaluator(clazz), TagsEvaluator(clazz)) + } + processSegment(segmentInfo, pjp) + } + + @Around("execution(@kamon.annotation.Time static * (@kamon.annotation.EnableKamon *).*(..))") + def time(pjp: ProceedingJoinPoint): AnyRef = { + var histogram = histograms.get(pjp.getStaticPart.getId) + if (histogram == null) { + val clazz = declaringType(pjp.getSignature) + histogram = registerTime(pjp.getStaticPart, histograms, StringEvaluator(clazz), TagsEvaluator(clazz)) + } + processTime(histogram, pjp) + } + + @Around("execution(@kamon.annotation.Count static * (@kamon.annotation.EnableKamon *).*(..))") + def count(pjp: ProceedingJoinPoint): AnyRef = { + var counter = counters.get(pjp.getStaticPart.getId) + if (counter == null) { + val clazz = declaringType(pjp.getSignature) + counter = registerCounter(pjp.getStaticPart, counters, StringEvaluator(clazz), TagsEvaluator(clazz)) + } + processCount(counter, pjp) + } + + @Around("execution(@kamon.annotation.MinMaxCount static * (@kamon.annotation.EnableKamon *).*(..))") + def minMax(pjp: ProceedingJoinPoint): AnyRef = { + var minMax = minMaxCounters.get(pjp.getStaticPart.getId) + if (minMax == null) { + val clazz = declaringType(pjp.getSignature) + minMax = registerMinMaxCounter(pjp.getStaticPart, minMaxCounters, StringEvaluator(clazz), TagsEvaluator(clazz)) + } + processMinMax(minMax, pjp) + } + + @AfterReturning(pointcut = "execution(@kamon.annotation.Histogram static (int || long || double || float) (@kamon.annotation.EnableKamon *).*(..))", returning = "result") + def histogram(jps: JoinPoint.StaticPart, result: AnyRef): Unit = { + var histogram = histograms.get(jps.getId) + if (histogram == null) { + val clazz = declaringType(jps.getSignature) + histogram = registerHistogram(jps, histograms, StringEvaluator(clazz), TagsEvaluator(clazz)) + } + processHistogram(histogram, result, jps) + } +} -- cgit v1.2.3