Skip to content

Commit

Permalink
Add test for new account allow/block case
Browse files Browse the repository at this point in the history
  • Loading branch information
mpalriwal-Netflix committed Oct 31, 2024
1 parent ba0c43c commit 25af790
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 9 deletions.
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 @@ -19,6 +19,7 @@ atlas {
"ut1",
"ut5",
"ut-ec2",
"ut-node",
"ut-asg",
"ut-timeout",
"ut-offset",
Expand Down
20 changes: 20 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,26 @@ atlas {
]
}

ut-node = {
namespace = "AWS/UT1"
period = 1m

accounts = [
"12345"
]

dimensions = [
"InstanceId"
]

metrics = [
{
name = "Ec2InstanceIdMetric"
alias = "aws.ec2.ec2InstanceIdMetric"
conversion = "sum,rate"
}
]
}
ut-ec2 = {
namespace = "AWS/UT1"
period = 5m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class BaseCloudWatchMetricsProcessorSuite extends FunSuite with TestKitBase with
val config = ConfigFactory.load()
val tagger = new NetflixTagger(config.getConfig("atlas.cloudwatch.tagger"))
val rules: CloudWatchRules = new CloudWatchRules(config)
val category = MetricCategory("AWS/DynamoDB", 60, -1, List("MyTag"), List.empty, null)
val category5m = MetricCategory("AWS/DynamoDB", 300, -1, List("MyTag"), List.empty, null)
val category = MetricCategory("AWS/DynamoDB", 60, -1, List("MyTag"), null, List.empty, null)
val category5m = MetricCategory("AWS/DynamoDB", 300, -1, List("MyTag"), null, List.empty, null)

val cwDP = newCacheEntry(
makeFirehoseMetric(Array(39.0, 1.0, 7.0, 19), ts(-2.minutes)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,62 @@ class CWMPProcessSuite extends BaseCloudWatchMetricsProcessorSuite {
assertCounters(0, publishEmpty = 1, scraped = 1)
}

test("processDatapoints account blocked") {
processor.processDatapoints(
List(
makeFirehoseMetric(
"AWS/UT1",
"Ec2InstanceIdMetric",
List(Dimension.builder().name("InstanceId").value("123").build()),
Array(1.0, 1.0, 1.0, 1),
"Count"
)
),
ts
)
assertPublished(List.empty)
assertCounters(
1,
filtered = Map("namespace" -> (0, "AWS/UT1"), "account" -> (1, "Ec2InstanceIdMetric"))
)
}

test("processDatapoints account allowed") {
processor.processDatapoints(
List(
makeFirehoseMetric(
"AWS/UT1",
"Ec2InstanceIdMetric",
List(
Dimension.builder().name("InstanceId").value("abc").build(),
Dimension.builder().name("nf.account").value("12345").build()
),
Array(1.0, 1.0, 1.0, 1),
"Count"
)
),
ts
)
assertPublished(
List(
com.netflix.atlas.core.model.Datapoint(
Map(
"name" -> "aws.ec2.ec2InstanceIdMetric",
"nf.region" -> "us-west-2",
"nf.app" -> "cloudwatch",
"atlas.dstype" -> "rate",
"nf.cluster" -> "cloudwatch",
"nf.node" -> "abc",
"nf.account" -> "12345"
),
ts,
0.016666666666666666
)
)
)
assertCounters(1)
}

test("processDatapoints No namespace config") {
processor.processDatapoints(
List(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CWMPPublishPointSuite extends BaseCloudWatchMetricsProcessorSuite {
val cache = ce(
List(cwv(-5.minutes, -4.minutes, false))
)
val category = MetricCategory("AWS/DynamoDB", 60, 4, List("MyTag"), List.empty, null)
val category = MetricCategory("AWS/DynamoDB", 60, 4, List("MyTag"), null, List.empty, null)
assertPublishPoint(processor.getPublishPoint(cache, nts, category), 0, cache, true)
assertMetrics(
grace = 4.minutes.toMillis,
Expand Down Expand Up @@ -439,6 +439,7 @@ class CWMPPublishPointSuite extends BaseCloudWatchMetricsProcessorSuite {
60,
-1,
List("MyTag"),
null,
List(MetricDefinition("SumRate", "sum.rate", null, true, Map.empty)),
null
)
Expand All @@ -457,6 +458,7 @@ class CWMPPublishPointSuite extends BaseCloudWatchMetricsProcessorSuite {
60,
-1,
List("MyTag"),
null,
List(MetricDefinition("SumRate", "sum.rate", null, true, Map.empty)),
null
)
Expand All @@ -475,6 +477,7 @@ class CWMPPublishPointSuite extends BaseCloudWatchMetricsProcessorSuite {
60,
-1,
List("MyTag"),
null,
List(MetricDefinition("SumRate", "sum.rate", null, true, Map.empty)),
null
)
Expand All @@ -493,6 +496,7 @@ class CWMPPublishPointSuite extends BaseCloudWatchMetricsProcessorSuite {
60,
-1,
List("MyTag"),
null,
List(MetricDefinition("SumRate", "sum.rate", null, true, Map.empty)),
null
)
Expand All @@ -513,6 +517,7 @@ class CWMPPublishPointSuite extends BaseCloudWatchMetricsProcessorSuite {
60,
-1,
List("MyTag"),
null,
List(MetricDefinition("SumRate", "sum.rate", null, true, Map.empty)),
null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ConversionsSuite extends FunSuite {
test("rate") {
val cnv = Conversions.fromName("sum,rate")
val meta = MetricMetadata(
MetricCategory("NFLX/Test", 300, -1, Nil, Nil, Some(Query.True)),
MetricCategory("NFLX/Test", 300, -1, Nil, null, Nil, Some(Query.True)),
MetricDefinition("test", "test-alias", cnv, false, Map.empty),
Nil
)
Expand All @@ -90,7 +90,7 @@ class ConversionsSuite extends FunSuite {
test("rate already") {
val cnv = Conversions.fromName("sum,rate")
val meta = MetricMetadata(
MetricCategory("NFLX/Test", 300, -1, Nil, Nil, Some(Query.True)),
MetricCategory("NFLX/Test", 300, -1, Nil, null, Nil, Some(Query.True)),
MetricDefinition("test", "test-alias", cnv, false, Map.empty),
Nil
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MetricDataSuite extends FunSuite {
60,
-1,
List("dimension"),
null,
List(definition),
Some(Query.True)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import java.time.Instant
class MetricDefinitionSuite extends FunSuite {

private val meta = MetricMetadata(
MetricCategory("AWS/ELB", 60, -1, Nil, Nil, Some(Query.True)),
MetricCategory("AWS/ELB", 60, -1, Nil, null, Nil, Some(Query.True)),
null,
Nil
)
Expand Down Expand Up @@ -248,7 +248,7 @@ class MetricDefinitionSuite extends FunSuite {
.build()

val metadata = MetricMetadata(
MetricCategory("AWS/RDS", 60, -1, Nil, Nil, Some(Query.True)),
MetricCategory("AWS/RDS", 60, -1, Nil, null, Nil, Some(Query.True)),
definition,
Nil
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RedisClusterCloudWatchMetricsProcessorSuite extends FunSuite with TestKitB
val rules: CloudWatchRules = new CloudWatchRules(config)

val category =
MetricCategory("AWS/UTRedis", 60, -1, List("node", "key"), List.empty, null)
MetricCategory("AWS/UTRedis", 60, -1, List("node", "key"), null, List.empty, null)

val firehoseMetric = makeFirehoseMetric(
"AWS/UTRedis",
Expand Down Expand Up @@ -971,7 +971,7 @@ class RedisClusterCloudWatchMetricsProcessorSuite extends FunSuite with TestKitB

def makePayload(node: String, key: Long): Array[Byte] = {
val category =
MetricCategory("AWS/UTRedis", 60, -1, List("node", "key"), List.empty, null)
MetricCategory("AWS/UTRedis", 60, -1, List("node", "key"), null, List.empty, null)
val cwDP = newCacheEntry(
makeFirehoseMetric(
"AWS/UTRedis",
Expand Down

0 comments on commit 25af790

Please sign in to comment.