Skip to content

Commit

Permalink
Warning cleanup (#600)
Browse files Browse the repository at this point in the history
* Remove Unicode arrows (deprecated in Scala 2.13)

Reference:
scala/scala#7540

* Linter: Fix unused config parameter

SuperSafe: Remove usage of .equals
Scalafix: remove unused imports & private hex function

There is no need to guard against LHS null in Scala equality and isInstanceOf

* Remove some hidden typos

* Bump legacy Scala to 2.12.8

* Enable TLS security in README, bump shields to Scala 2.13
  • Loading branch information
Marko Elezović authored and ivantopo committed Aug 9, 2019
1 parent a587c9e commit 2a9c979
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 56 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Kamon<img align="right" src="https://rawgit.com/kamon-io/Kamon/master/kamon-logo.svg" height="150px" style="padding-left: 20px"/>
[![Build Status](https://travis-ci.org/kamon-io/Kamon.svg?branch=master)](https://travis-ci.org/kamon-io/Kamon)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/kamon-io/Kamon?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.kamon/kamon-core_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.kamon/kamon-core_2.12)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.kamon/kamon-core_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.kamon/kamon-core_2.13)

Kamon is a set of tools for instrumenting applications running on the JVM. The best way to get started is to go to our
official [Get Started Page](https://kamon.io/get-started/) and start instrumenting your applications right away! There
Expand All @@ -12,7 +12,7 @@ you will also find guides and reference documentation for the core APIs, instrum

This software is licensed under the Apache 2 license, quoted below.

Copyright © 2013-2019 the kamon project <http://kamon.io>
Copyright © 2013-2019 the kamon project <https://kamon.io/>

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
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ lazy val commonSettings = Seq(
startYear := Some(2013),
concurrentRestrictions in Global += Tags.limit(Tags.Test, 1),
scalaVersion := "2.13.0",
crossScalaVersions := Seq("2.11.12", "2.12.7", "2.13.0"),
crossScalaVersions := Seq("2.11.12", "2.12.8", "2.13.0"),
scalacOptions ++= Seq(
"-deprecation",
"-encoding", "UTF-8",
Expand Down
2 changes: 1 addition & 1 deletion kamon-core/src/main/scala/kamon/ContextPropagation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ trait ContextPropagation { self: Configuration =>
_defaultBinaryPropagation

private def init(config: Config): Unit = synchronized {
_propagationComponents = ContextPropagation.Channels.from(self.config)
_propagationComponents = ContextPropagation.Channels.from(config)
_defaultHttpPropagation = _propagationComponents.httpChannels(ContextPropagation.DefaultHttpChannel)
_defaultBinaryPropagation = _propagationComponents.binaryChannels(ContextPropagation.DefaultBinaryChannel)
}
Expand Down
2 changes: 1 addition & 1 deletion kamon-core/src/main/scala/kamon/ContextStorage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ object ContextStorage {
* instrumentation follows them around.
*/
private val _contextStorage: Storage = {
if("true".equals(System.getProperty("kamon.context.debug")))
if(sys.props("kamon.context.debug") == "true")
Storage.Debug()
else
Storage.ThreadLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory

import scala.reflect.ClassTag
import scala.util.control.NonFatal
import scala.util.{Failure, Success, Try}
import scala.util.Try


/**
Expand Down
14 changes: 5 additions & 9 deletions kamon-core/src/main/scala/kamon/context/HttpPropagation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import org.slf4j.LoggerFactory

import scala.reflect.ClassTag
import scala.util.control.NonFatal
import scala.util.{Failure, Success}

/**
* Context propagation that uses HTTP headers as the transport medium. HTTP propagation mechanisms read any number of
Expand Down Expand Up @@ -169,33 +168,30 @@ object HttpPropagation {

private val _longTypePrefix = "l:"
private val _booleanTypePrefix = "b:"
private val _booleanTrue = "true"
private val _booleanFalse = "false"

/**
* Tries to infer and parse a value into one of the supported tag types: String, Long or Boolean by looking for the
* type indicator prefix on the tag value. If the inference fails it will default to treat the value as a String.
*/
private def parseTagValue(value: String): Any = {
if (value.isEmpty || value.length < 2) // Empty and short values definitely do not have type indicators.
if (value.length < 2) // Empty and short values definitely do not have type indicators.
value
else {
if(value.startsWith(_longTypePrefix)) {
// Try to parse the content as a Long value.
val remaining = value.substring(2)
try {
java.lang.Long.parseLong(remaining)
remaining.toLong
} catch {
case _: Throwable => remaining
case _: java.lang.NumberFormatException => remaining
}

} else if(value.startsWith(_booleanTypePrefix)) {

// Try to parse the content as a Boolean value.
val remaining = value.substring(2)
if(remaining.equals(_booleanTrue))
if(remaining == "true")
true
else if(remaining.equals(_booleanFalse))
else if(remaining == "false")
false
else
remaining
Expand Down
7 changes: 3 additions & 4 deletions kamon-core/src/main/scala/kamon/metric/Histogram.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
package kamon.metric

import java.nio.ByteBuffer
import java.time.Duration

import kamon.metric.Metric.{BaseMetric, BaseMetricAutoUpdate}
import kamon.tag.TagSet
import org.HdrHistogram.{BaseAtomicHdrHistogram, BaseLocalHdrHistogram, HdrHistogramInternalState, ZigZag}
import org.HdrHistogram.{BaseAtomicHdrHistogram, HdrHistogramInternalState, ZigZag}
import org.slf4j.LoggerFactory


Expand Down Expand Up @@ -71,7 +70,7 @@ object Histogram {
_logger.warn (
s"Failed to record value [$value] on [${metric.name},${tags}] because the value is outside of the " +
s"configured range. The recorded value was adjusted to the highest trackable value [$highestTrackableValue]. " +
s"You might need to change your dynamic range configuration for this metric"
"You might need to change your dynamic range configuration for this metric"
)
}

Expand All @@ -89,7 +88,7 @@ object Histogram {
_logger.warn (
s"Failed to record value [$value] on [${metric.name},${tags}] because the value is outside of the " +
s"configured range. The recorded value was adjusted to the highest trackable value [$highestTrackableValue]. " +
s"You might need to change your dynamic range configuration for this metric"
"You might need to change your dynamic range configuration for this metric"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object MeasurementUnit {
value
} else if(from == to)
value
else (from.magnitude.scaleFactor / to.magnitude.scaleFactor) * value.toDouble
else (from.magnitude.scaleFactor / to.magnitude.scaleFactor) * value
}

/**
Expand Down
8 changes: 4 additions & 4 deletions kamon-core/src/main/scala/kamon/metric/MetricRegistry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,19 @@ class MetricRegistry(config: Config, scheduler: ScheduledExecutorService, clock:
sys.error(s"Cannot redefine metric [$name] as a [${instrumentType.name}], it was already registered as a [${metric.getClass.getName}]")

private def checkDescription(name: String, description: String, providedDescription: Option[String]): Unit =
if(providedDescription.filter(d => d != description).nonEmpty)
if(providedDescription.exists(d => d != description))
_logger.warn(s"Ignoring new description [${providedDescription.getOrElse("")}] for metric [${name}]")

private def checkUnit(name: String, unit: MeasurementUnit, providedUnit: Option[MeasurementUnit]): Unit =
if(providedUnit.filter(u => u != unit).nonEmpty)
if(providedUnit.exists(u => u != unit))
_logger.warn(s"Ignoring new unit [${providedUnit.getOrElse("")}] for metric [${name}]")

private def checkAutoUpdate(name: String, autoUpdateInterval: Duration, providedAutoUpdateInterval: Option[Duration]): Unit =
if(providedAutoUpdateInterval.filter(u => u != autoUpdateInterval).nonEmpty)
if(providedAutoUpdateInterval.exists(u => u != autoUpdateInterval))
_logger.warn(s"Ignoring new auto-update interval [${providedAutoUpdateInterval.getOrElse("")}] for metric [${name}]")

private def checkDynamicRange(name: String, dynamicRange: DynamicRange, providedDynamicRange: Option[DynamicRange]): Unit =
if(providedDynamicRange.filter(dr => dr != dynamicRange).nonEmpty)
if(providedDynamicRange.exists(dr => dr != dynamicRange))
_logger.warn(s"Ignoring new dynamic range [${providedDynamicRange.getOrElse("")}] for metric [${name}]")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ object PeriodSnapshot {
}

private def isSameDurationAsTickInterval(): Boolean = {
Kamon.config().getDuration("kamon.metric.tick-interval").equals(period)
Kamon.config().getDuration("kamon.metric.tick-interval") == period
}

private def buildPeriodSnapshot(from: Instant, to: Instant, resetState: Boolean): PeriodSnapshot = {
Expand Down
2 changes: 1 addition & 1 deletion kamon-core/src/main/scala/kamon/metric/RangeSampler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ object RangeSampler {
case _: ArrayIndexOutOfBoundsException =>
_logger.warn (
s"Failed to record value on [${metric.name},${tags}] because the value is outside of the " +
s"configured range. You might need to change your dynamic range configuration for this metric"
"configured range. You might need to change your dynamic range configuration for this metric"
)
}

Expand Down
2 changes: 1 addition & 1 deletion kamon-core/src/main/scala/kamon/metric/Timer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ object Timer {
_logger.warn (
s"Failed to record value [$nanos] on [${metric.name},${tags}] because the value is outside of the " +
s"configured range. The recorded value was adjusted to the highest trackable value [$highestTrackableValue]. " +
s"You might need to change your dynamic range configuration for this metric"
"You might need to change your dynamic range configuration for this metric"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ModuleRegistry(configuration: Configuration, clock: Clock, metricRegistry:
}

// Remove all modules that no longer exist in the configuration.
val missingModules = automaticallyRegisteredModules.filterKeys(moduleName => configuredModules.find(_.name == moduleName).isEmpty)
val missingModules = automaticallyRegisteredModules.filterKeys(moduleName => !configuredModules.exists(_.name == moduleName))
missingModules.foreach {
case (_, entry) => stopModule(entry)
}
Expand Down
10 changes: 5 additions & 5 deletions kamon-core/src/main/scala/kamon/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ package object kamon {
*/
implicit class AtomicGetOrElseUpdateOnTrieMap[K, V](val trieMap: TrieMap[K, V]) extends AnyVal {

def atomicGetOrElseUpdate(key: K, op: V): V =
atomicGetOrElseUpdate(key, op, { _: V () }, { _: V () })
def atomicGetOrElseUpdate(key: K, op: => V): V =
atomicGetOrElseUpdate(key, op, { _: V => () }, { _: V => () })

def atomicGetOrElseUpdate(key: K, op: V, cleanup: V Unit, init: V => Unit): V =
def atomicGetOrElseUpdate(key: K, op: => V, cleanup: V => Unit, init: V => Unit): V =
trieMap.get(key) match {
case Some(v) v
case None
case Some(v) => v
case None =>
val d = op
trieMap.putIfAbsent(key, d) match {
case Some(oldValue) =>
Expand Down
6 changes: 3 additions & 3 deletions kamon-core/src/main/scala/kamon/tag/Lookups.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ object Lookups {
private val _plainString = (a: String) => a
private val _stringOption = (a: String) => Option(a)
private val _stringOptional = (a: String) => Optional.of(a)
private val _stringSafetyCheck = (a: Any) => a != null && a.isInstanceOf[String]
private val _stringSafetyCheck = (a: Any) => a.isInstanceOf[String]

private val _plainLong = (a: java.lang.Long) => a
private val _longOption = (a: Long) => Option(a)
private val _longOptional = (a: Long) => Optional.of(a)
private val _longSafetyCheck = (a: Any) => a != null && a.isInstanceOf[Long]
private val _longSafetyCheck = (a: Any) => a.isInstanceOf[Long]

private val _plainBoolean = (a: java.lang.Boolean) => a
private val _booleanOption = (a: Boolean) => Option(a)
private val _booleanOptional = (a: Boolean) => Optional.of(a)
private val _booleanSafetyCheck = (a: Any) => a != null && a.isInstanceOf[Boolean]
private val _booleanSafetyCheck = (a: Any) => a.isInstanceOf[Boolean]

}
4 changes: 2 additions & 2 deletions kamon-core/src/main/scala/kamon/util/Clock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ object Clock {
_systemClock.getZone()

override def nanosSince(instant: Instant): Long = {
return nanosBetween(instant, this.instant())
nanosBetween(instant, this.instant())
}
}

Expand All @@ -116,7 +116,7 @@ object Clock {
def nanosBetween(left: Instant, right: Instant): Long = {
val secsDiff = Math.subtractExact(right.getEpochSecond, left.getEpochSecond)
val totalNanos = Math.multiplyExact(secsDiff, _nanosInSecond)
return Math.addExact(totalNanos, right.getNano - left.getNano)
Math.addExact(totalNanos, right.getNano - left.getNano)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion kamon-core/src/main/scala/kamon/util/DynamicAccess.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DynamicAccess(val classLoader: ClassLoader) {
val obj = constructor.newInstance(values: _*)
val t = implicitly[ClassTag[T]].runtimeClass
if (t.isInstance(obj)) obj.asInstanceOf[T] else throw new ClassCastException(clazz.getName + " is not a subtype of " + t)
} catch { case i: InvocationTargetException if i.getTargetException ne null throw i.getTargetException }
} catch { case i: InvocationTargetException if i.getTargetException ne null => throw i.getTargetException }

/**
* Tries to create an instance of the provided fully-qualified class name, passing the provided arguments to the
Expand Down
4 changes: 2 additions & 2 deletions kamon-core/src/main/scala/kamon/util/Filter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ object Filter {
private val _pathRegex = pattern.r

override def accept(value: String): Boolean = value match {
case _pathRegex(_*) true
case _ false
case _pathRegex(_*) => true
case _ => false
}
}

Expand Down
14 changes: 0 additions & 14 deletions kamon-core/src/main/scala/kamon/util/HexCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,6 @@ object HexCodec {
result
}

/**
* Returns 16 or 32 character hex string depending on if {@code high} is zero.
*/
private def toLowerHex(high: Long, low: Long): String = {
val result = new Array[Char](if (high != 0) 32 else 16)
var pos = 0
if (high != 0) {
writeHexLong(result, pos, high)
pos += 16
}
writeHexLong(result, pos, low)
new String(result)
}

/**
* Inspired by {@code okio.Buffer.writeLong}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object MetricInspection {
def instruments[Inst <: Instrument[Inst, Sett], Sett <: Metric.Settings](metric: Metric[Inst, Sett], tags: TagSet): Map[TagSet, Inst] = {
def hasAllRequestedTags(instrumentTags: TagSet): Boolean = {
val instrumentPairs = instrumentTags.iterator().map(t => (t.key -> Tag.unwrapValue(t))).toMap
tags.iterator().forall(t => instrumentPairs.get(t.key).filter(sv => sv == Tag.unwrapValue(t)).nonEmpty)
tags.iterator().forall(t => instrumentPairs.get(t.key).exists(sv => sv == Tag.unwrapValue(t)))
}

instrumentsMap(metric)
Expand Down

0 comments on commit 2a9c979

Please sign in to comment.