You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2019/11/08 07:49:32 UTC

[GitHub] [openwhisk] markusthoemmes commented on a change in pull request #4715: Extension points for kamon metric key generator and reporter

markusthoemmes commented on a change in pull request #4715: Extension points for kamon metric key generator and reporter
URL: https://github.com/apache/openwhisk/pull/4715#discussion_r344015191
 
 

 ##########
 File path: tests/src/test/scala/org/apache/openwhisk/common/AppConfigForCommonTests.scala
 ##########
 @@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openwhisk.common
+import com.typesafe.config.ConfigFactory
+import kamon.Kamon
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers}
+import common.WhiskProperties
+import scala.io.Source
+
+// Tests the logic of definitions in application.conf for common.
+
+trait Helpers {
+
+  def getKeyGenerator = {
+    val statsDConfig = Kamon.config.getConfig("kamon.statsd")
+    statsDConfig.getString("metric-key-generator")
+  }
+
+  def getReporters = {
+    val kamonConfig = Kamon.config.getConfig("kamon")
+    kamonConfig.getStringList("reporters").toArray
+  }
+
+  def configKamon(generator: Option[String], reporter: Option[String]) = {
+    // read application.conf for common
+    val buffer = Source
+      .fromFile(WhiskProperties.getFileRelativeToWhiskHome("common/scala/src/main/resources/application.conf"))
+    var content = buffer.getLines.mkString("\n")
+    // simulate substitution of environment variables in application.conf
+    for (subst <- Seq(("KAMON_STATSD_METRIC_KEY_GENERATOR", generator), ("METRICS_KAMON_REPORTER", reporter))) {
+      content = subst match {
+        case (name, Some(value)) =>
+          // substitute ${name} and ${?name} occurrences with the value
+          val pattern = ("\\$\\{\\??" + name + "\\}").r
 
 Review comment:
   Why even pattern match? These should be exact matches so a simpler `replace("${?" + name + "}", value` should work here? Note that it's still a global replace.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services