Actor stats not being sent to StatsD from Kamon - akka-http

I'm trying to use Kamon with StatsD backend for Akka monitoring/telemetry. I currently only have one actor and I'm sending an ask which replies to the caller. I can see my custom counter data in Graphana and Graphite as well as JVM and OS stats, but no actor stats from Akka. My project is setup just like this intro but I have added the Kamon stuff and my own HttpService. What am I missing?
Here's my config:
kamon {
trace.level = simple-trace
metric {
tick-interval = 1 second
filters {
akka-actor.includes = [ "**" ]
akka-router.includes = [ "**" ]
akka-dispatcher.includes = [ "**" ]
trace.includes = [ "**" ]
trace-segment.includes = [ "**" ]
histogram.includes = [ "**" ]
min-max-counter.includes = [ "**" ]
gauge.includes = [ "**" ]
counters.includes = [ "**" ]
# For web projects
http-server.includes = [ "**" ]
akka-actor.excludes = [ "**" ]
akka-router.excludes = [ "**" ]
akka-dispatcher.excludes = [ "**" ]
counters.excludes = [ "" ]
trace-segment.excludes = [ "" ]
histogram.excludes = [ "" ]
min-max-counter.excludes = [ "" ]
gauge.excludes = [ "" ]
http-server.excludes = [ "" ]
}
}
akka {
ask-pattern-timeout-warning = "lightweight"
}
statsd {
hostname = "localhost" //Graphite Host
port = "8125"
flush-interval = 1 second
max-packet-size = 1024 bytes
subscriptions {
histogram = ["**"]
min-max-counter = ["**"]
gauge = ["**"]
counter = ["**"]
trace = ["**"]
trace-segment = ["**"]
system-metric = ["**"]
akka-actor = ["**"]
akka-dispatcher = ["**"]
http-server = ["**"]
}
report-system-metrics = true
simple-metric-key-generator {
application = "data-id-generator"
}
}
system-metrics {
#sigar is enabled by default
sigar-enabled = false
#jmx related metrics are enabled by default
jmx-enabled = true
}
}
Here's my service:
import akka.event.Logging
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import akka.pattern.ask
import akka.util.{ByteString, Timeout}
import com.incontact.data.GeneratorActor.GenerateId
import com.incontact.data.IdGenerator.{GeneratorError, IdResult}
import com.incontact.http.HttpService
import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import spray.json._
import kamon.Kamon
import scala.concurrent.duration._
trait IdService extends HttpService with SprayJsonSupport with DefaultJsonProtocol {
private lazy val log = Logging(system, classOf[IdService])
implicit val timeout: Timeout = 1.second
//implicit val errorFormat = jsonFormat2(GeneratorError)
abstract override def route: Route = {
log.info("creating generator actor")
val generator = system.actorOf(GeneratorActor.props, "generator")
val counter = Kamon.metrics.counter("generate-long-id")
path("") {
get {
counter.increment()
log.info("IdService sending single request to actor")
onSuccess((generator ? GenerateId).mapTo[IdResult]) {
case Right(id) => complete(ByteString(s"${id}\n"))
case Left(e:GeneratorError) => failWith(e.Error)
}
}
}
} ~ super.route
}
Main.scala (startup)
import akka.event.Logging
import com.incontact.data.IdService
import com.incontact.http.HttpServer
import kamon.Kamon
import scala.io.StdIn
import scala.util.Success
object Main extends App
with HttpServer
with IdService {
Kamon.start()
private lazy val log = Logging(system, getClass)
bindingFuture.andThen {
case Success(binding) =>
// this really doesn't support any production behavior since [ENTER] won't be used to shut down the docker container
log.info("Press ENTER to exit")
StdIn.readLine()
log.info("Shutting down...")
Kamon.shutdown()
system.terminate()
}
}
build.sbt
scalaVersion := "2.11.8"
val akkaVersion = "2.4.14"
val kamonVersion = "0.6.3"
libraryDependencies ++= Seq(
// remove multiple-dependency warnings
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scala-lang.modules" %% "scala-xml" % "1.0.5",
// application dependencies
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-http" % "10.0.0",
"com.typesafe.akka" %% "akka-http-spray-json" % "10.0.0",
"com.amazonaws" % "aws-java-sdk-dynamodb" % "1.11.63",
// kamon dependencies
"io.kamon" %% "kamon-core" % kamonVersion,
"io.kamon" %% "kamon-statsd" % kamonVersion,
"io.kamon" %% "kamon-system-metrics" % kamonVersion,
"org.aspectj" % "aspectjweaver" % "1.8.6",
// test dependencies
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test",
"org.scalatest" %% "scalatest" % "3.0.1" % "test",
"com.typesafe.akka" %% "akka-http-testkit" % "10.0.0" % "test",
"org.pegdown" % "pegdown" % "1.1.0" % "test"
)
project/plugins.sbt
addSbtPlugin("io.kamon" % "aspectj-runner" % "0.1.3")
launch from command-line:
$ sbt aspectj-runner:run

It looks like you're excluding all the actors/dispatcher/router metrics in your config. This should rule all metrics out (even if you're also including them all).
akka-actor.excludes = [ "**" ]
akka-router.excludes = [ "**" ]
akka-dispatcher.excludes = [ "**" ]
Try and change it to
akka-actor.excludes = [ ]
akka-router.excludes = [ ]
akka-dispatcher.excludes = [ ]

Related

Karate Framework; Reuse array of the values to paste the values into another json with N nested elements

Hi Team!
Here is my question - how to reuse the array of the values from json1 and paste the values one by one into a json2; and create JSON with 1 parent and nested elements
json1;
[
"EAID_6F41E794_9FE8_447a_9AA2_BD5CA941B0A8",
"EAID_7144A90E_3566_43e1_A071_9D9977B99E8A",
"EAID_14F85DAB_7BF7_4ad1_8DBF_F2ABEBE7E35A",
"EAID_DEDC0908_FDE9_4384_8DED_B9FF30760C6C",
"EAID_6F41E794_9FE8_447a_9AA2_BD5CA941B0A8",
"EAID_14F85DAB_7BF7_4ad1_8DBF_F2ABEBE7E35A",
"EAID_6F41E794_9FE8_447a_9AA2_BD5CA941B0A8",
"EAID_7144A90E_3566_43e1_A071_9D9977B99E8A",
"_19_0_3_8aa01e4_1610562779046_96927_69106",
"_19_0_3_8aa01e4_1610562779046_96927_69106"
]
{
"orders": [
{
"values": [
"EAID_6F41E794_9FE8_447a_9AA2_BD5CA941B0A8"
]
},
{
"values": [
"EAID_7144A90E_3566_43e1_A071_9D9977B99E8A"
]
}
]
}
Here you go:
* def fun = function(x){ return { values: [ x ] } }
* def result = karate.map(json1, fun)
* def json2 = { orders: '#(result)' }
* print json2
Please refer the docs: https://github.com/karatelabs/karate#json-transforms
Just for fun, here's an alternate more concise solution:
* def fun = x => ({ values: [ x ] })
* def json2 = ({ orders: json1.map(fun) })
* print json2
Simpler version:

What is the correct syntax for multiple conditions in a Terraform `aws_iam_policy_document` data block

How can this S3 bucket IAM policy, which has multiple conditions, be re-written as aws_iam_policy_document data block, please?
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control",
"aws:SourceAccount": "xxxxxxxxxxxx"
},
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:::my-tf-test-bucket"
}
}
With the aws_iam_policy_document condition data block syntax 1:
condition {
test = "StringEquals"
values = []
variable = ""
}
The aws_iam_policy_document supports nested condition directives. The following Terraform configuration should help:
data "aws_iam_policy_document" "iam_policy_document" {
condition {
test = "StringEquals"
values = [
"bucket-owner-full-control"
]
variable = "s3:x-amz-acl"
}
condition {
test = "StringEquals"
values = [
"xxxxxxxxxxxx"
]
variable = "aws:SourceAccount"
}
condition {
test = "ArnLike"
values = [
"arn:aws:s3:::my-tf-test-bucket"
]
variable = "aws:SourceArn"
}
}

How to build a multiple IF conditional in Mule 4 and DW 2.0?

I need to create a function with conditions like this pseudo-code:
var consent = []
function buildConsent() {
if (condition1) {
consent += values1
}
if (condition2) {
consent += values2
}
if (condition3) {
consent += values3
}
}
This is how I am doing it on Mule4 and DW 2.0:
%dw 2.0
var consent = []
var factIntake = vars.facts
fun buildConsent() =
if (factIntake.miscFactItems[?($.value1 == true)] != null) {
consent + {
"Consent_Type": "some1",
"Consent_Given_By": "some2"
}
}
if (factIntake.miscFactItems[?($.value2 == true)] != null) {
consent + {
"Consent_Type": "some3",
"Consent_Given_By": "some4"
}
}
output application/json
--
{
"Consent_Data": buildConsent()
}
But I am getting the following error from the IDE (AnypointStudio 7):
Invalid input '+', expected Namespace or
Attribute<'#('(Name:Value)+')'> (line 11, column 11):
Where line 11, column 11 is the first appearance of consent +. If I try to debug the project all I got in the console is:
Message : Error while parsing script: %dw 2.0
Here is an example of input/output for you to better understand what I am trying to achieve:
// Input
{
"miscFactItems": [{
"factId": "designeeFirstName",
"factValue": "test test",
"factValueType": "System.String"
}, {
"factId": "designeeLastName",
"factValue": "test test",
"factValueType": "System.String"
},{
"factId": "value1",
"factValue": true,
"factValueType": "System.Boolean"
}, {
"factId": "value2",
"factValue": true,
"factValueType": "System.Boolean"
}, {
"factId": "value3",
"factValue": true,
"factValueType": "System.Boolean"
}
]
}
// Output
consent = [{
"Consent_Type": "type1",
"Consent_Given_By": miscFactItems.designeeFirstName
}, {
"Consent_Type": "type2",
"Consent_Given_By": miscFactItems.designeeFirstName
}, {
"Consent_Type": "type3",
"Consent_Given_By": miscFactItems.designeeFirstName
}
]
What I am missing here? How do I add the three conditions to my function and append the values to the consent var?
In DataWeave variables are immutable, so you can't accumulate things in the same variable, you need to create new variables.
So it would look something like this:
%dw 2.0
output application/json
var consent1 = if (condition1) [{"Consent_Type": "some1", "Consent_Given_By": "some2"}] else []
var consent2 = if (condition2) [{"Consent_Type": "some3", "Consent_Given_By": "some4"}] else []
---
consent1 ++ consent2
Your requirement looks like a good use of reduce function. Based on the pseudo code you provided, you can do something like below
output application/json
var payload = [
{"name":"Ram", "email":"Ram#gmail.com", "state": "CA","age":21},
{"name":"Bob", "email":"bob32#gmail.com","state": "CA","age":30},
{"name":"john", "email":"bob32#gmail.com","state": "NY","age":43}
]
---
payload reduce ((item, consent = []) -> consent +
{
(state: item.state) if(item.state=='CA'),
(age: item.age) if(item.age >25)
}
)

Grouping/inheriting properties for tasks in Gradle

Is there a way to reuse property groups in Gradle?
Something that would look like:
def propGroup = [
options.fork = true
options.forkOptions.executable = ...
]
task compileThis(type:JavaCompile) {
options.fork = propGroup.options.fork
options.forkOptions.setExecutable(propGroup.options.forkOptions.executable)
destinationDir = file(xxx)
}
task compileThat(type:JavaCompile) {
options.fork = propGroup.options.fork
options.forkOptions.setExecutable(propGroup.options.forkOptions.executable)
destinationDir = file(yyy)
}
In Java that would be inheritance but you cannot inherit a task from a task in Gradle
It will work if propGroup would be defined as a map:
def propGroup = [
options: [
fork: true,
forkOptions: [
executable: true
]
]
]
Then executable could be e.g. referred as:
propGroup.options.forkOptions.executable

Match each item in Karate [duplicate]

This question already has an answer here:
Using match each contains for json array items assertion
(1 answer)
Closed 1 year ago.
I would like assert that the price gross is greater than equal to price_net. Can you please tell me how can I achieve this correctly ? This is what I have done atm.
Scenario: Testing
* def response =
"""
{
"prices": [
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" }
]
}
"""
* match each response.prices[*].price_gross == '#? _ >= 0 && _ >= response.prices[*].price_net'
I think the '*' inside the assertion statement is the problem. Because when I run this
* match response.prices[0].price_gross == '#? _ >= 0 && _ >= response.prices[0].price_net'
it works fine. Please suggest. Thanks in Advance.
Sample Code:
Feature: Validation
Scenario: Validation
* def diff =
"""
function (A, B) {
var C = [];
for(var i = 0; i < A.length; i++) {
C.push(parseFloat(A[i]) - parseFloat(B[i]));
}
return C;
}
"""
* def response =
"""
{
"prices": [
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" },
{ "price_net":"10.50", "price_gross":"12.25" }
]
}
"""
* json temp = response
* def pgarr = get temp.prices[*].price_gross
* def pnarr = get temp.prices[*].price_net
* def sub = diff(pgarr,pnarr)
* match each sub == '#? _ >= 0'