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

Fix tagger for nf.asg to cluster/app conversion #599

Merged
merged 1 commit into from
Oct 29, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@ class NetflixTagger(config: Config) extends DefaultTagger(config) {

override def apply(dimensions: List[Dimension]): Map[String, String] = {
val baseTags = super.apply(dimensions)
val extractedTags = keys.flatMap { k =>
val resultTags = scala.collection.mutable.Map[String, String]()

keys.foreach { k =>
baseTags.get(k) match {
case Some(v) =>
val name = Names.parseName(v)
List(
resultTags ++= List(
opt("nf.app", name.getApp),
opt("nf.cluster", name.getCluster),
opt("nf.stack", name.getStack)
)
).flatten
case None =>
// If baseTags.get(k) is empty, add default values
List(
Some("nf.app" -> "cloudwatch"),
Some("nf.cluster" -> "cloudwatch")
)
// Only add default values if the keys are not already set
if (!resultTags.contains("nf.app")) resultTags("nf.app") = "cloudwatch"
if (!resultTags.contains("nf.cluster")) resultTags("nf.cluster") = "cloudwatch"
}
}
extractedTags.flatten.toMap ++ baseTags

// Merge resultTags with baseTags, giving priority to resultTags
resultTags.toMap ++ baseTags
}
}
1 change: 1 addition & 0 deletions atlas-cloudwatch/src/test/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ atlas {
categories = ${?atlas.cloudwatch.categories} [
"ut1",
"ut5",
"ut-ec2",
"ut-asg",
"ut-timeout",
"ut-offset",
Expand Down
16 changes: 16 additions & 0 deletions atlas-cloudwatch/src/test/resources/test-rules.conf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ atlas {
]
}

ut-ec2 = {
namespace = "AWS/UT1"
period = 5m

dimensions = [
"AutoScalingGroupName"
]

metrics = [
{
name = "EBSReadBytes"
alias = "aws.ec2.ebs.ebsReadBytes"
conversion = "sum,rate"
}
]
}
ut-asg = {
namespace = "AWS/UT1"
period = 1m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,39 @@ class CWMPProcessSuite extends BaseCloudWatchMetricsProcessorSuite {
assertCounters(1)
}

test("processDatapoints ec2 bytes") {
val dp = makeFirehoseMetric(
"AWS/UT1",
"EBSReadBytes",
List(
Dimension.builder().name("AutoScalingGroupName").value("someApp-someStack-v001").build()
),
Array(1, 1, 1, 1),
"Bytes",
ts(-5.minute)
)
processor.processDatapoints(List(dp), ts(-5.minute))

assertPublished(
List(
com.netflix.atlas.core.model.Datapoint(
Map(
"name" -> "aws.ec2.ebs.ebsReadBytes",
"nf.region" -> "us-west-2",
"atlas.dstype" -> "rate",
"nf.stack" -> "someStack",
"nf.app" -> "someApp",
"nf.asg" -> "someApp-someStack-v001",
"nf.cluster" -> "someApp-someStack"
),
ts,
0.0033333333333333335
)
)
)
assertCounters(1)
}

test("processDatapoints matched percent") {
processor.processDatapoints(
List(
Expand Down
Loading