From 909df9c0504d331e0781903138c8e18532454bb8 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 20 Mar 2024 11:45:50 -0400 Subject: [PATCH 001/108] Changing Latency to nonzero value to get rid of InvalidMetrics --- test/app_signals/resources/metrics/client_producer.json | 6 +++--- test/app_signals/resources/metrics/server_consumer.json | 6 +++--- test/feature/mac/parameters.yml | 9 +++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 8a39c60d6..61cb1c812 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -184,9 +184,9 @@ ], "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, - "sum": 0, - "min": 0, - "max": 0 + "sum": 1, + "min": 1, + "max": 1 } ] } diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index 2d3cd0b79..eee7da3f6 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -202,9 +202,9 @@ ], "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, - "sum": 0, - "min": 0, - "max": 0 + "sum": 1, + "min": 1, + "max": 1 } ] } diff --git a/test/feature/mac/parameters.yml b/test/feature/mac/parameters.yml index 31a15abe7..ed05d5018 100644 --- a/test/feature/mac/parameters.yml +++ b/test/feature/mac/parameters.yml @@ -128,6 +128,15 @@ metric_validation: - metric_name: "mem_used_percent" metric_sample_count: 60 metric_dimension: [] + - metric_name: "Latency" + metric_sample_count: 60 + metric_dimension: [ ] + - metric_name: "Error" + metric_sample_count: 60 + metric_dimension: [ ] + - metric_name: "Fault" + metric_sample_count: 60 + metric_dimension: [ ] # Logs that the test needs to validate; moreover, the feature validation already has # InstanceID as a log group; therefore, does not need to pass it From 0a3103143eb6882b0f5b6b61db3cf95222d7a120 Mon Sep 17 00:00:00 2001 From: siprmp Date: Mon, 1 Apr 2024 16:04:21 -0400 Subject: [PATCH 002/108] testing some feature --- util/awsservice/constant.go | 50 ++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/util/awsservice/constant.go b/util/awsservice/constant.go index 1009a08e2..53da7d910 100644 --- a/util/awsservice/constant.go +++ b/util/awsservice/constant.go @@ -5,6 +5,7 @@ package awsservice import ( "context" + "fmt" "time" "github.com/aws/aws-sdk-go-v2/config" @@ -38,16 +39,41 @@ var ( ) var ( - ctx = context.Background() - awsCfg, _ = config.LoadDefaultConfig(ctx) - Ec2Client = ec2.NewFromConfig(awsCfg) - EcsClient = ecs.NewFromConfig(awsCfg) - SsmClient = ssm.NewFromConfig(awsCfg) - ImdsClient = imds.NewFromConfig(awsCfg) - CwmClient = cloudwatch.NewFromConfig(awsCfg) - CwlClient = cloudwatchlogs.NewFromConfig(awsCfg) - DynamodbClient = dynamodb.NewFromConfig(awsCfg) - S3Client = s3.NewFromConfig(awsCfg) - CloudformationClient = cloudformation.NewFromConfig(awsCfg) - XrayClient = xray.NewFromConfig(awsCfg) + ctx context.Context + + // AWS Clients + Ec2Client *ec2.Client + EcsClient *ecs.Client + SsmClient *ssm.Client + ImdsClient *imds.Client + CwmClient *cloudwatch.Client + CwlClient *cloudwatchlogs.Client + DynamodbClient *dynamodb.Client + S3Client *s3.Client + CloudformationClient *cloudformation.Client + XrayClient *xray.Client ) + +func init() { + ctx = context.Background() + var err error + awsCfg, err := config.LoadDefaultConfig(ctx, config.WithRegion("us-west-2")) + if err != nil { + // handle error + fmt.Println("There was an error trying to load default config: ", err) + return + } + fmt.Println("This is the aws region: ", awsCfg.Region) + + // Initialize AWS Clients with the configured awsCfg + Ec2Client = ec2.NewFromConfig(awsCfg) + EcsClient = ecs.NewFromConfig(awsCfg) + SsmClient = ssm.NewFromConfig(awsCfg) + ImdsClient = imds.NewFromConfig(awsCfg) + CwmClient = cloudwatch.NewFromConfig(awsCfg) + CwlClient = cloudwatchlogs.NewFromConfig(awsCfg) + DynamodbClient = dynamodb.NewFromConfig(awsCfg) + S3Client = s3.NewFromConfig(awsCfg) + CloudformationClient = cloudformation.NewFromConfig(awsCfg) + XrayClient = xray.NewFromConfig(awsCfg) +} From cdd6e50feaf6887c6eefd22991d80b4ae719f989 Mon Sep 17 00:00:00 2001 From: siprmp Date: Mon, 1 Apr 2024 16:23:57 -0400 Subject: [PATCH 003/108] printing out request of query --- validator/validators/basic/basic_validator.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 885b5a61c..e6355bd5c 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -4,6 +4,7 @@ package basic import ( + "encoding/json" "fmt" "log" "strings" @@ -197,5 +198,12 @@ func (s *BasicValidator) buildMetricQueries(metricName, metricNamespace string, Id: aws.String(strings.ToLower(metricName)), }, } + fmt.Println("Maybe better form of metric query") + jsonBytes, err := json.MarshalIndent(metricDataQueries, "", " ") + if err != nil { + // handle error + log.Fatal(err) + } + fmt.Println(string(jsonBytes)) return metricDataQueries } From f6b5fadfe84ab25d405f4ac3139270ebf33bc443 Mon Sep 17 00:00:00 2001 From: siprmp Date: Tue, 2 Apr 2024 11:58:01 -0400 Subject: [PATCH 004/108] changing namespace for appsignal metrics --- test/feature/mac/parameters.yml | 6 ++++++ util/common/metrics.go | 17 ++++++++++++++++- validator/validators/basic/basic_validator.go | 15 ++++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/test/feature/mac/parameters.yml b/test/feature/mac/parameters.yml index ed05d5018..5248096c6 100644 --- a/test/feature/mac/parameters.yml +++ b/test/feature/mac/parameters.yml @@ -137,6 +137,12 @@ metric_validation: - metric_name: "Fault" metric_sample_count: 60 metric_dimension: [ ] + - metric_name: "Latency" + metric_sample_count: 60 + metric_dimension: [ ] + - metric_name: "Error" + metric_sample_count: 60 + metric_dimension: [ ] # Logs that the test needs to validate; moreover, the feature validation already has # InstanceID as a log group; therefore, does not need to pass it diff --git a/util/common/metrics.go b/util/common/metrics.go index ddd93b492..aee1f058b 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -27,9 +27,10 @@ func StartSendingMetrics(receiver string, duration, sendingInterval time.Duratio err = SendCollectDMetrics(metricPerInterval, sendingInterval, duration) case "emf": err = SendEMFMetrics(metricPerInterval, metricLogGroup, metricNamespace, sendingInterval, duration) + case "app_signals": + err = SendAppSignalMetrics(metricPerInterval, []string{}, sendingInterval, duration) //does app signals have dimension for metric? default: } - }() return err @@ -130,6 +131,19 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } } +} +func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendingInterval, duration time.Duration) error { + + // The bash script to be executed asynchronously. + RunCommand("pwd") + cmd := `while true; export START_TIME=$(date +%s%N); do + cat ./resources/metrics/server_consumer.json | sed -e "s/START_TIME/$START_TIME/" > server_consumer.json; + curl -H 'Content-Type: application/json' -d @server_consumer.json -i http://127.0.0.1:4316/v1/metrics --verbose; + cat ./resources/metrics/client_producer.json | sed -e "s/START_TIME/$START_TIME/" > client_producer.json; + curl -H 'Content-Type: application/json' -d @client_producer.json -i http://127.0.0.1:4316/v1/metrics --verbose; + sleep 5; done` + return RunAsyncCommand(cmd) + } func SendStatsdMetrics(metricPerInterval int, metricDimension []string, sendingInterval, duration time.Duration) error { @@ -210,4 +224,5 @@ func SendEMFMetrics(metricPerInterval int, metricLogGroup, metricNamespace strin return nil } } + } diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index e6355bd5c..a7939ba42 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -81,10 +81,19 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Value: aws.String(dimension.Value), }) } - err := s.ValidateMetric(metric.MetricName, metricNamespace, metricDimensions, metric.MetricValue, metric.MetricSampleCount, startTime, endTime) - if err != nil { - multiErr = multierr.Append(multiErr, err) + //quick testing method for app signals + if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { + err := s.ValidateMetric(metric.MetricName, "AppSignals", metricDimensions, metric.MetricValue, metric.MetricSampleCount, startTime, endTime) + if err != nil { + multiErr = multierr.Append(multiErr, err) + } + } else { + err := s.ValidateMetric(metric.MetricName, metricNamespace, metricDimensions, metric.MetricValue, metric.MetricSampleCount, startTime, endTime) + if err != nil { + multiErr = multierr.Append(multiErr, err) + } } + } for _, logValidation := range logValidations { From 78ee16be0e84e62836cae04475a88fbf8d1b80c2 Mon Sep 17 00:00:00 2001 From: siprmp Date: Tue, 2 Apr 2024 12:54:38 -0400 Subject: [PATCH 005/108] adding app_signals to the namespace --- test/feature/mac/parameters.yml | 2 +- validator/models/validation_config.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/feature/mac/parameters.yml b/test/feature/mac/parameters.yml index 5248096c6..c52078bf3 100644 --- a/test/feature/mac/parameters.yml +++ b/test/feature/mac/parameters.yml @@ -1,5 +1,5 @@ # Receivers that agent needs to tests -receivers: ["system","statsd","emf"] +receivers: ["system","statsd","emf","app_signals"] #Test case name test_case: "macos_feature" diff --git a/validator/models/validation_config.go b/validator/models/validation_config.go index 6d29ee2c7..6e281dccf 100644 --- a/validator/models/validation_config.go +++ b/validator/models/validation_config.go @@ -15,7 +15,7 @@ import ( "gopkg.in/yaml.v3" ) -var supportedReceivers = []string{"logs", "statsd", "collectd", "system", "emf", "xray"} +var supportedReceivers = []string{"logs", "statsd", "collectd", "system", "emf", "xray", "app_signals"} type ValidateConfig interface { GetPluginsConfig() []string From d9f52f43afdf101e80bfc6155ce13ad5bd9614e7 Mon Sep 17 00:00:00 2001 From: siprmp Date: Tue, 2 Apr 2024 14:53:35 -0400 Subject: [PATCH 006/108] adding app_signals to agent config --- test/feature/mac/agent_config.json | 3 +++ validator/validators/basic/basic_validator.go | 1 + 2 files changed, 4 insertions(+) diff --git a/test/feature/mac/agent_config.json b/test/feature/mac/agent_config.json index 4bbff6336..29eab3efc 100644 --- a/test/feature/mac/agent_config.json +++ b/test/feature/mac/agent_config.json @@ -5,6 +5,8 @@ "metrics": { "namespace": "CloudWatchAgentMacFeature", "metrics_collected": { + "app_signals": {}, + "statsd": { "metrics_aggregation_interval": 60, "metrics_collection_interval": 60, @@ -96,6 +98,7 @@ } }, "metrics_collected": { + "app_signals": {}, "emf": { } }, "force_flush_interval": 5 diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index a7939ba42..3e3d7b2aa 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -81,6 +81,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Value: aws.String(dimension.Value), }) } + //quick testing method for app signals if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { err := s.ValidateMetric(metric.MetricName, "AppSignals", metricDimensions, metric.MetricValue, metric.MetricSampleCount, startTime, endTime) From 3abb62395f3710e3a5d3195971222022940a85ff Mon Sep 17 00:00:00 2001 From: siprmp Date: Tue, 2 Apr 2024 15:42:44 -0400 Subject: [PATCH 007/108] fixing agent config --- test/feature/mac/agent_config.json | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/feature/mac/agent_config.json b/test/feature/mac/agent_config.json index 29eab3efc..db2ddc2e0 100644 --- a/test/feature/mac/agent_config.json +++ b/test/feature/mac/agent_config.json @@ -2,11 +2,14 @@ "agent": { "debug": true }, + "traces": { + "traces_collected": { + "app_signals": {} + } + }, "metrics": { "namespace": "CloudWatchAgentMacFeature", "metrics_collected": { - "app_signals": {}, - "statsd": { "metrics_aggregation_interval": 60, "metrics_collection_interval": 60, @@ -14,7 +17,7 @@ }, "cpu": { "measurement": [ - "time_active", + "time_active", "time_guest" ], "metrics_collection_interval": 1 @@ -42,7 +45,7 @@ }, "mem": { "measurement": [ - "available_percent", + "available_percent", "used_percent" ], "metrics_collection_interval": 1 @@ -63,7 +66,7 @@ "en0" ], "measurement": [ - "bytes_sent", + "bytes_sent", "bytes_recv" ], "metrics_collection_interval": 1 From cf6e78f38c257846524b612cb95225d7eb556f58 Mon Sep 17 00:00:00 2001 From: siprmp Date: Tue, 2 Apr 2024 16:27:14 -0400 Subject: [PATCH 008/108] fixing agent json --- test/app_signals/resources/metrics/client_producer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 61cb1c812..fd0880075 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -54,7 +54,7 @@ { "key": "aws.local.service", "value": { - "stringValue": "service-name" + "stringValue": "alibaba-service" } }, { From e79eadcdf2adab1c0456b24677fc8ab74ef5dd95 Mon Sep 17 00:00:00 2001 From: siprmp Date: Tue, 2 Apr 2024 17:12:59 -0400 Subject: [PATCH 009/108] fixing agent json --- test/feature/mac/parameters.yml | 24 +++++++++++++++--------- util/common/metrics.go | 8 +++++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/test/feature/mac/parameters.yml b/test/feature/mac/parameters.yml index c52078bf3..8847988e1 100644 --- a/test/feature/mac/parameters.yml +++ b/test/feature/mac/parameters.yml @@ -128,21 +128,27 @@ metric_validation: - metric_name: "mem_used_percent" metric_sample_count: 60 metric_dimension: [] - - metric_name: "Latency" - metric_sample_count: 60 - metric_dimension: [ ] - - metric_name: "Error" - metric_sample_count: 60 - metric_dimension: [ ] - metric_name: "Fault" metric_sample_count: 60 - metric_dimension: [ ] + metric_dimension: + - name: "operation" + value: "operation" + - name: "service" + value: "service-name" - metric_name: "Latency" metric_sample_count: 60 - metric_dimension: [ ] + metric_dimension: + - name: "operation" + value: "operation" + - name: "service" + value: "drop-service-name-1" - metric_name: "Error" metric_sample_count: 60 - metric_dimension: [ ] + metric_dimension: + - name: "operation" + value: "operation" + - name: "service" + value: "service-name" # Logs that the test needs to validate; moreover, the feature validation already has # InstanceID as a log group; therefore, does not need to pass it diff --git a/util/common/metrics.go b/util/common/metrics.go index aee1f058b..41012adf9 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -136,11 +136,13 @@ func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendi // The bash script to be executed asynchronously. RunCommand("pwd") - cmd := `while true; export START_TIME=$(date +%s%N); do - cat ./resources/metrics/server_consumer.json | sed -e "s/START_TIME/$START_TIME/" > server_consumer.json; + cmd := `while true; export START_TIME=$(date +%s%N); do + cat ~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/server_consumer.json | sed -e "s/START_TIME/$START_TIME/" > server_consumer.json; curl -H 'Content-Type: application/json' -d @server_consumer.json -i http://127.0.0.1:4316/v1/metrics --verbose; - cat ./resources/metrics/client_producer.json | sed -e "s/START_TIME/$START_TIME/" > client_producer.json; + cat ~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/server_consumer.json + cat ~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json | sed -e "s/START_TIME/$START_TIME/" > client_producer.json; curl -H 'Content-Type: application/json' -d @client_producer.json -i http://127.0.0.1:4316/v1/metrics --verbose; + cat ~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json sleep 5; done` return RunAsyncCommand(cmd) From df610e7e50646f433a5dcd93e493d9cf414ec510 Mon Sep 17 00:00:00 2001 From: siprmp Date: Tue, 2 Apr 2024 18:13:46 -0400 Subject: [PATCH 010/108] log event --- test/feature/mac/parameters.yml | 18 +++--------------- util/common/metrics.go | 3 ++- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/test/feature/mac/parameters.yml b/test/feature/mac/parameters.yml index 8847988e1..81c43b86d 100644 --- a/test/feature/mac/parameters.yml +++ b/test/feature/mac/parameters.yml @@ -130,25 +130,13 @@ metric_validation: metric_dimension: [] - metric_name: "Fault" metric_sample_count: 60 - metric_dimension: - - name: "operation" - value: "operation" - - name: "service" - value: "service-name" + metric_dimension: [ ] - metric_name: "Latency" metric_sample_count: 60 - metric_dimension: - - name: "operation" - value: "operation" - - name: "service" - value: "drop-service-name-1" + metric_dimension: [ ] - metric_name: "Error" metric_sample_count: 60 - metric_dimension: - - name: "operation" - value: "operation" - - name: "service" - value: "service-name" + metric_dimension: [ ] # Logs that the test needs to validate; moreover, the feature validation already has # InstanceID as a log group; therefore, does not need to pass it diff --git a/util/common/metrics.go b/util/common/metrics.go index 41012adf9..b2a0e291f 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -133,7 +133,7 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendingInterval, duration time.Duration) error { - + fmt.Println() // The bash script to be executed asynchronously. RunCommand("pwd") cmd := `while true; export START_TIME=$(date +%s%N); do @@ -143,6 +143,7 @@ func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendi cat ~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json | sed -e "s/START_TIME/$START_TIME/" > client_producer.json; curl -H 'Content-Type: application/json' -d @client_producer.json -i http://127.0.0.1:4316/v1/metrics --verbose; cat ~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json + tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log sleep 5; done` return RunAsyncCommand(cmd) From 0bb2994361dba4c53d7518272533dce1af410691 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 00:47:26 -0400 Subject: [PATCH 011/108] adding log statements to test why macOs test is not working --- util/common/metrics.go | 63 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index b2a0e291f..99aaa24b0 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -4,10 +4,13 @@ package common import ( + "bufio" "context" "errors" "fmt" "net" + "os" + "path/filepath" "time" "collectd.org/api" @@ -133,7 +136,6 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendingInterval, duration time.Duration) error { - fmt.Println() // The bash script to be executed asynchronously. RunCommand("pwd") cmd := `while true; export START_TIME=$(date +%s%N); do @@ -145,7 +147,64 @@ func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendi cat ~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log sleep 5; done` - return RunAsyncCommand(cmd) + + holder := RunAsyncCommand(cmd) + fmt.Println("Attempting to read amazon cloudwatch agent logs") + logFilePath := "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log" + + // Open the file + file, err := os.Open(logFilePath) + if err != nil { + fmt.Println("Error opening file:", err) + return err + } + defer file.Close() + + // Create a new Scanner for the file + scanner := bufio.NewScanner(file) + + // Loop over all lines in the file + for scanner.Scan() { + // Print each line + fmt.Println(scanner.Text()) + } + + // Check for errors during Scan + if err := scanner.Err(); err != nil { + fmt.Println("Error reading file:", err) + } + homeDir, err := os.UserHomeDir() + if err != nil { + fmt.Println("Error getting home directory:", err) + return err + } + + // Construct the file path + jsonFilePath := filepath.Join(homeDir, "amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json") + fmt.Println("Attempting to read client_producer.json") + + // Open the JSON file + file, err = os.Open(jsonFilePath) + if err != nil { + fmt.Println("Error opening file:", err) + return err + } + defer file.Close() + + // Create a new Scanner for the file + scanner = bufio.NewScanner(file) + + // Loop over all lines in the file + for scanner.Scan() { + // Print each line + fmt.Println(scanner.Text()) + } + + // Check for errors during Scan + if err := scanner.Err(); err != nil { + fmt.Println("Error reading file:", err) + } + return holder } From e7a9ec0760fd71802b93ab58b4bef3b18939eb3d Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 08:43:36 -0400 Subject: [PATCH 012/108] fixing app signals validation --- validator/validators/basic/basic_validator.go | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 3e3d7b2aa..a037755ec 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -81,10 +81,37 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Value: aws.String(dimension.Value), }) } + environmentValue := "Generic" // Replace with actual value + operationValue := "replaced-operation" // Replace with actual value + serviceValue := "service-name" // Replace with actual value + // Creating the first group of dimensions + appSignalDimensions := []cwtypes.Dimension{ + { + Name: aws.String("HostedIn.Environment"), + Value: aws.String(environmentValue), + }, + { + Name: aws.String("Operation"), + Value: aws.String(operationValue), + }, + { + Name: aws.String("Service"), + Value: aws.String(serviceValue), + }, + { + Name: aws.String("HostedIn.Environment"), + Value: aws.String(environmentValue), + }, + { + Name: aws.String("Service"), + Value: aws.String(serviceValue), + }, + } //quick testing method for app signals if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { - err := s.ValidateMetric(metric.MetricName, "AppSignals", metricDimensions, metric.MetricValue, metric.MetricSampleCount, startTime, endTime) + + err := s.ValidateMetric(metric.MetricName, "AppSignals", appSignalDimensions, metric.MetricValue, 1, startTime, endTime) if err != nil { multiErr = multierr.Append(multiErr, err) } From 9a219532aaab3ed95ef413e55ad9ff7307ce554d Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 10:14:21 -0400 Subject: [PATCH 013/108] trying to fix query --- validator/validators/basic/basic_validator.go | 92 ++++++++++++++----- 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index a037755ec..5245d609e 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -4,9 +4,12 @@ package basic import ( + "bufio" "encoding/json" "fmt" "log" + "os" + "path/filepath" "strings" "time" @@ -81,33 +84,12 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Value: aws.String(dimension.Value), }) } - environmentValue := "Generic" // Replace with actual value - operationValue := "replaced-operation" // Replace with actual value - serviceValue := "service-name" // Replace with actual value + //environmentValue := "Generic" // Replace with actual value + //operationValue := "replaced-operation" // Replace with actual value + //serviceValue := "service-name" // Replace with actual value // Creating the first group of dimensions - appSignalDimensions := []cwtypes.Dimension{ - { - Name: aws.String("HostedIn.Environment"), - Value: aws.String(environmentValue), - }, - { - Name: aws.String("Operation"), - Value: aws.String(operationValue), - }, - { - Name: aws.String("Service"), - Value: aws.String(serviceValue), - }, - { - Name: aws.String("HostedIn.Environment"), - Value: aws.String(environmentValue), - }, - { - Name: aws.String("Service"), - Value: aws.String(serviceValue), - }, - } + appSignalDimensions := []cwtypes.Dimension{} //quick testing method for app signals if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { @@ -195,6 +177,61 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr } if len(metrics.MetricDataResults) == 0 || len(metrics.MetricDataResults[0].Values) == 0 { + fmt.Println("Attempting to read amazon cloudwatch agent logs after trying to validate getting metrics") + logFilePath := "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log" + + // Open the file + file, err := os.Open(logFilePath) + if err != nil { + fmt.Println("Error opening file:", err) + return err + } + defer file.Close() + + // Create a new Scanner for the file + scanner := bufio.NewScanner(file) + + // Loop over all lines in the file + for scanner.Scan() { + // Print each line + fmt.Println(scanner.Text()) + } + + // Check for errors during Scan + if err := scanner.Err(); err != nil { + fmt.Println("Error reading file:", err) + } + homeDir, err := os.UserHomeDir() + if err != nil { + fmt.Println("Error getting home directory:", err) + return err + } + + // Construct the file path + jsonFilePath := filepath.Join(homeDir, "amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json") + fmt.Println("Attempting to read client_producer.json") + + // Open the JSON file + file, err = os.Open(jsonFilePath) + if err != nil { + fmt.Println("Error opening file:", err) + return err + } + defer file.Close() + + // Create a new Scanner for the file + scanner = bufio.NewScanner(file) + + // Loop over all lines in the file + for scanner.Scan() { + // Print each line + fmt.Println(scanner.Text()) + } + + // Check for errors during Scan + if err := scanner.Err(); err != nil { + fmt.Println("Error reading file:", err) + } return fmt.Errorf("\n getting metric %s failed with the namespace %s and dimension %v", metricName, metricNamespace, util.LogCloudWatchDimension(metricDimensions)) } @@ -235,6 +272,11 @@ func (s *BasicValidator) buildMetricQueries(metricName, metricNamespace string, Id: aws.String(strings.ToLower(metricName)), }, } + if metricName == "Latency" || metricName == "Fault" || metricName == "Error" { + metricDataQueries[0].MetricStat.Unit = "Milliseconds" + *metricDataQueries[0].ReturnData = true + } + fmt.Println("Maybe better form of metric query") jsonBytes, err := json.MarshalIndent(metricDataQueries, "", " ") if err != nil { From f62b02ba85ddddca25665889f91b20f649ed0a3e Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 10:27:00 -0400 Subject: [PATCH 014/108] trying to fix query --- util/common/metrics.go | 113 +++++++++--------- validator/validators/basic/basic_validator.go | 113 +++++++++--------- 2 files changed, 110 insertions(+), 116 deletions(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index 99aaa24b0..53301f5e4 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -4,13 +4,10 @@ package common import ( - "bufio" "context" "errors" "fmt" "net" - "os" - "path/filepath" "time" "collectd.org/api" @@ -149,61 +146,61 @@ func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendi sleep 5; done` holder := RunAsyncCommand(cmd) - fmt.Println("Attempting to read amazon cloudwatch agent logs") - logFilePath := "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log" - - // Open the file - file, err := os.Open(logFilePath) - if err != nil { - fmt.Println("Error opening file:", err) - return err - } - defer file.Close() - - // Create a new Scanner for the file - scanner := bufio.NewScanner(file) - - // Loop over all lines in the file - for scanner.Scan() { - // Print each line - fmt.Println(scanner.Text()) - } - - // Check for errors during Scan - if err := scanner.Err(); err != nil { - fmt.Println("Error reading file:", err) - } - homeDir, err := os.UserHomeDir() - if err != nil { - fmt.Println("Error getting home directory:", err) - return err - } - - // Construct the file path - jsonFilePath := filepath.Join(homeDir, "amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json") - fmt.Println("Attempting to read client_producer.json") - - // Open the JSON file - file, err = os.Open(jsonFilePath) - if err != nil { - fmt.Println("Error opening file:", err) - return err - } - defer file.Close() - - // Create a new Scanner for the file - scanner = bufio.NewScanner(file) - - // Loop over all lines in the file - for scanner.Scan() { - // Print each line - fmt.Println(scanner.Text()) - } - - // Check for errors during Scan - if err := scanner.Err(); err != nil { - fmt.Println("Error reading file:", err) - } + //fmt.Println("Attempting to read amazon cloudwatch agent logs") + //logFilePath := "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log" + // + //// Open the file + //file, err := os.Open(logFilePath) + //if err != nil { + // fmt.Println("Error opening file:", err) + // return err + //} + //defer file.Close() + // + //// Create a new Scanner for the file + //scanner := bufio.NewScanner(file) + // + //// Loop over all lines in the file + //for scanner.Scan() { + // // Print each line + // fmt.Println(scanner.Text()) + //} + // + //// Check for errors during Scan + //if err := scanner.Err(); err != nil { + // fmt.Println("Error reading file:", err) + //} + //homeDir, err := os.UserHomeDir() + //if err != nil { + // fmt.Println("Error getting home directory:", err) + // return err + //} + // + //// Construct the file path + //jsonFilePath := filepath.Join(homeDir, "amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json") + //fmt.Println("Attempting to read client_producer.json") + // + //// Open the JSON file + //file, err = os.Open(jsonFilePath) + //if err != nil { + // fmt.Println("Error opening file:", err) + // return err + //} + //defer file.Close() + // + //// Create a new Scanner for the file + //scanner = bufio.NewScanner(file) + // + //// Loop over all lines in the file + //for scanner.Scan() { + // // Print each line + // fmt.Println(scanner.Text()) + //} + // + //// Check for errors during Scan + //if err := scanner.Err(); err != nil { + // fmt.Println("Error reading file:", err) + //} return holder } diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 5245d609e..fcbb1c046 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -4,12 +4,9 @@ package basic import ( - "bufio" "encoding/json" "fmt" "log" - "os" - "path/filepath" "strings" "time" @@ -177,61 +174,61 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr } if len(metrics.MetricDataResults) == 0 || len(metrics.MetricDataResults[0].Values) == 0 { - fmt.Println("Attempting to read amazon cloudwatch agent logs after trying to validate getting metrics") - logFilePath := "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log" - - // Open the file - file, err := os.Open(logFilePath) - if err != nil { - fmt.Println("Error opening file:", err) - return err - } - defer file.Close() - - // Create a new Scanner for the file - scanner := bufio.NewScanner(file) - - // Loop over all lines in the file - for scanner.Scan() { - // Print each line - fmt.Println(scanner.Text()) - } - - // Check for errors during Scan - if err := scanner.Err(); err != nil { - fmt.Println("Error reading file:", err) - } - homeDir, err := os.UserHomeDir() - if err != nil { - fmt.Println("Error getting home directory:", err) - return err - } - - // Construct the file path - jsonFilePath := filepath.Join(homeDir, "amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json") - fmt.Println("Attempting to read client_producer.json") - - // Open the JSON file - file, err = os.Open(jsonFilePath) - if err != nil { - fmt.Println("Error opening file:", err) - return err - } - defer file.Close() - - // Create a new Scanner for the file - scanner = bufio.NewScanner(file) - - // Loop over all lines in the file - for scanner.Scan() { - // Print each line - fmt.Println(scanner.Text()) - } - - // Check for errors during Scan - if err := scanner.Err(); err != nil { - fmt.Println("Error reading file:", err) - } + //fmt.Println("Attempting to read amazon cloudwatch agent logs after trying to validate getting metrics") + //logFilePath := "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log" + // + //// Open the file + //file, err := os.Open(logFilePath) + //if err != nil { + // fmt.Println("Error opening file:", err) + // return err + //} + //defer file.Close() + // + //// Create a new Scanner for the file + //scanner := bufio.NewScanner(file) + // + //// Loop over all lines in the file + //for scanner.Scan() { + // // Print each line + // fmt.Println(scanner.Text()) + //} + // + //// Check for errors during Scan + //if err := scanner.Err(); err != nil { + // fmt.Println("Error reading file:", err) + //} + //homeDir, err := os.UserHomeDir() + //if err != nil { + // fmt.Println("Error getting home directory:", err) + // return err + //} + // + //// Construct the file path + //jsonFilePath := filepath.Join(homeDir, "amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json") + //fmt.Println("Attempting to read client_producer.json") + // + //// Open the JSON file + //file, err = os.Open(jsonFilePath) + //if err != nil { + // fmt.Println("Error opening file:", err) + // return err + //} + //defer file.Close() + // + //// Create a new Scanner for the file + //scanner = bufio.NewScanner(file) + // + //// Loop over all lines in the file + //for scanner.Scan() { + // // Print each line + // fmt.Println(scanner.Text()) + //} + // + //// Check for errors during Scan + //if err := scanner.Err(); err != nil { + // fmt.Println("Error reading file:", err) + //} return fmt.Errorf("\n getting metric %s failed with the namespace %s and dimension %v", metricName, metricNamespace, util.LogCloudWatchDimension(metricDimensions)) } From 357038e6780d0d2a4096c19912e698a86b653983 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 10:39:24 -0400 Subject: [PATCH 015/108] trying to fix query --- validator/validators/basic/basic_validator.go | 10 +++++----- .../validators/feature/feature_validator.go | 2 +- validator/validators/validator.go | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index fcbb1c046..a7b9dd7dc 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -38,7 +38,7 @@ func NewBasicValidator(vConfig models.ValidateConfig) models.ValidatorFactory { func (s *BasicValidator) GenerateLoad() error { var ( - metricSendingInterval = time.Minute + metricSendingInterval = 10 * time.Second logGroup = awsservice.GetInstanceId() metricNamespace = s.vConfig.GetMetricNamespace() dataRate = s.vConfig.GetDataRate() @@ -269,10 +269,10 @@ func (s *BasicValidator) buildMetricQueries(metricName, metricNamespace string, Id: aws.String(strings.ToLower(metricName)), }, } - if metricName == "Latency" || metricName == "Fault" || metricName == "Error" { - metricDataQueries[0].MetricStat.Unit = "Milliseconds" - *metricDataQueries[0].ReturnData = true - } + //if metricName == "Latency" || metricName == "Fault" || metricName == "Error" { + // metricDataQueries[0].MetricStat.Unit = "Milliseconds" + // *metricDataQueries[0].ReturnData = true + //} fmt.Println("Maybe better form of metric query") jsonBytes, err := json.MarshalIndent(metricDataQueries, "", " ") diff --git a/validator/validators/feature/feature_validator.go b/validator/validators/feature/feature_validator.go index 5fc84d629..231b83ad3 100644 --- a/validator/validators/feature/feature_validator.go +++ b/validator/validators/feature/feature_validator.go @@ -31,7 +31,7 @@ func NewFeatureValidator(vConfig models.ValidateConfig) models.ValidatorFactory func (s *FeatureValidator) GenerateLoad() error { var ( multiErr error - metricSendingInterval = time.Minute + metricSendingInterval = 10 * time.Second logGroup = awsservice.GetInstanceId() metricNamespace = s.vConfig.GetMetricNamespace() dataRate = s.vConfig.GetDataRate() diff --git a/validator/validators/validator.go b/validator/validators/validator.go index e137c6b64..ff0f0b465 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -31,18 +31,18 @@ func NewValidator(vConfig models.ValidateConfig) (validator models.ValidatorFact func LaunchValidator(vConfig models.ValidateConfig) error { var ( - agentCollectionPeriod = vConfig.GetAgentCollectionPeriod() - startTimeValidation = time.Now().Truncate(time.Minute).Add(time.Minute) - endTimeValidation = startTimeValidation.Add(agentCollectionPeriod) - durationBeforeNextMinute = time.Until(startTimeValidation) + agentCollectionPeriod = vConfig.GetAgentCollectionPeriod() + startTimeValidation = time.Now().Truncate(time.Minute).Add(time.Minute) + endTimeValidation = startTimeValidation.Add(agentCollectionPeriod) + //durationBeforeNextMinute = time.Until(startTimeValidation) ) validator, err := NewValidator(vConfig) if err != nil { return err } - log.Printf("Start to sleep %f s for the metric to be available in the beginning of next minute ", durationBeforeNextMinute.Seconds()) - time.Sleep(durationBeforeNextMinute) + //log.Printf("Start to sleep %f s for the metric to be available in the beginning of next minute ", durationBeforeNextMinute.Seconds()) + //time.Sleep(durationBeforeNextMinute) log.Printf("Start to generate load in %f s for the agent to collect and send all the metrics to CloudWatch within the datapoint period ", agentCollectionPeriod.Seconds()) err = validator.GenerateLoad() @@ -52,8 +52,8 @@ func LaunchValidator(vConfig models.ValidateConfig) error { } time.Sleep(agentCollectionPeriod) - log.Printf("Start to sleep 120s for CloudWatch to process all the metrics") - time.Sleep(2 * time.Minute) + log.Printf("Start to sleep 20s for CloudWatch to process all the metrics") + time.Sleep(20 * time.Second) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From b426c98b690d54d0a6835b81222e50ae8ce76dc2 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 10:45:33 -0400 Subject: [PATCH 016/108] trying to fix query --- validator/validators/validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/validator.go b/validator/validators/validator.go index ff0f0b465..a0679995d 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -32,7 +32,7 @@ func NewValidator(vConfig models.ValidateConfig) (validator models.ValidatorFact func LaunchValidator(vConfig models.ValidateConfig) error { var ( agentCollectionPeriod = vConfig.GetAgentCollectionPeriod() - startTimeValidation = time.Now().Truncate(time.Minute).Add(time.Minute) + startTimeValidation = time.Now() endTimeValidation = startTimeValidation.Add(agentCollectionPeriod) //durationBeforeNextMinute = time.Until(startTimeValidation) ) From 6d836e481409ae01e5b1c07c48d29e62ef265215 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 10:52:45 -0400 Subject: [PATCH 017/108] trying to fix query --- validator/validators/stress/stress_validator.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/validator/validators/stress/stress_validator.go b/validator/validators/stress/stress_validator.go index 440e821fb..0dd7d1a68 100644 --- a/validator/validators/stress/stress_validator.go +++ b/validator/validators/stress/stress_validator.go @@ -406,8 +406,10 @@ func (s *StressValidator) ValidateStressMetric(metricName, metricNamespace strin // Validate if the metrics are not dropping any metrics and able to backfill within the same minute (e.g if the memory_rss metric is having collection_interval 1 // , it will need to have 60 sample counts - 1 datapoint / second) - if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount-5, metricSampleCount, int32(boundAndPeriod)); !ok { + if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, 10-5, 10, int32(boundAndPeriod)); !ok { return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount-5, metricSampleCount) + } else { + fmt.Println("Yayyyyyyy!!!!!!! sample count is good for :", metricName, metricSampleCount) } return nil From caec7ca1bdc22c3867267e3d026545390f2f1298 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 10:58:16 -0400 Subject: [PATCH 018/108] trying to fix query --- validator/validators/basic/basic_validator.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index a7b9dd7dc..170e8970d 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -160,6 +160,7 @@ func (s *BasicValidator) ValidateLogs(logStream, logLine, logLevel, logSource st } func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metricDimensions []cwtypes.Dimension, metricValue float64, metricSampleCount int, startTime, endTime time.Time) error { + metricSampleCount = 10 var ( boundAndPeriod = s.vConfig.GetAgentCollectionPeriod().Seconds() ) @@ -234,8 +235,10 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr // Validate if the metrics are not dropping any metrics and able to backfill within the same minute (e.g if the memory_rss metric is having collection_interval 1 // , it will need to have 60 sample counts - 1 datapoint / second) - if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount, metricSampleCount, int32(boundAndPeriod)); !ok { + if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount-5, metricSampleCount, int32(boundAndPeriod)); !ok { return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount, metricSampleCount) + } else { + fmt.Println("Yayyyyyyy!!!!!!! sample count is good for :", metricName, metricSampleCount) } // Validate if the corresponding metrics are within the acceptable range [acceptable value +- 10%] From 9babbad47c6f9cb6ba2b686fbceeccb2e2de2aa2 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 11:01:51 -0400 Subject: [PATCH 019/108] trying to fix query --- validator/validators/basic/basic_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 170e8970d..f63e12cb2 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -173,7 +173,7 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr if err != nil { return err } - + fmt.Printf("For metric: %v This is the metric data result: %v and the result values: %v", metricName, metrics.MetricDataResults, metrics.MetricDataResults[0].Values) if len(metrics.MetricDataResults) == 0 || len(metrics.MetricDataResults[0].Values) == 0 { //fmt.Println("Attempting to read amazon cloudwatch agent logs after trying to validate getting metrics") //logFilePath := "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log" From e36295be4503b21683388fbd37125565cf980247 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 11:21:17 -0400 Subject: [PATCH 020/108] trying to fix query --- validator/validators/basic/basic_validator.go | 2 +- validator/validators/stress/stress_validator.go | 2 +- validator/validators/validator.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index f63e12cb2..9c7f074ea 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -235,7 +235,7 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr // Validate if the metrics are not dropping any metrics and able to backfill within the same minute (e.g if the memory_rss metric is having collection_interval 1 // , it will need to have 60 sample counts - 1 datapoint / second) - if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount-5, metricSampleCount, int32(boundAndPeriod)); !ok { + if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount-5, metricSampleCount+10, int32(boundAndPeriod)); !ok { return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount, metricSampleCount) } else { fmt.Println("Yayyyyyyy!!!!!!! sample count is good for :", metricName, metricSampleCount) diff --git a/validator/validators/stress/stress_validator.go b/validator/validators/stress/stress_validator.go index 0dd7d1a68..2c42325ca 100644 --- a/validator/validators/stress/stress_validator.go +++ b/validator/validators/stress/stress_validator.go @@ -406,7 +406,7 @@ func (s *StressValidator) ValidateStressMetric(metricName, metricNamespace strin // Validate if the metrics are not dropping any metrics and able to backfill within the same minute (e.g if the memory_rss metric is having collection_interval 1 // , it will need to have 60 sample counts - 1 datapoint / second) - if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, 10-5, 10, int32(boundAndPeriod)); !ok { + if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, 5, 10, int32(boundAndPeriod)); !ok { return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount-5, metricSampleCount) } else { fmt.Println("Yayyyyyyy!!!!!!! sample count is good for :", metricName, metricSampleCount) diff --git a/validator/validators/validator.go b/validator/validators/validator.go index a0679995d..3e6cfb8b5 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -53,7 +53,7 @@ func LaunchValidator(vConfig models.ValidateConfig) error { time.Sleep(agentCollectionPeriod) log.Printf("Start to sleep 20s for CloudWatch to process all the metrics") - time.Sleep(20 * time.Second) + time.Sleep(10 * time.Second) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From 7633bdda6ba970a74cbaf7531b82501c0cdb86da Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 11:25:13 -0400 Subject: [PATCH 021/108] trying to fix query --- validator/validators/basic/basic_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 9c7f074ea..7d6f62c34 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -235,7 +235,7 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr // Validate if the metrics are not dropping any metrics and able to backfill within the same minute (e.g if the memory_rss metric is having collection_interval 1 // , it will need to have 60 sample counts - 1 datapoint / second) - if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount-5, metricSampleCount+10, int32(boundAndPeriod)); !ok { + if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, 1, metricSampleCount+10, int32(boundAndPeriod)); !ok { return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount, metricSampleCount) } else { fmt.Println("Yayyyyyyy!!!!!!! sample count is good for :", metricName, metricSampleCount) From f2c99fe52a9829b6a93009dfa257023c53a82cf7 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 12:12:25 -0400 Subject: [PATCH 022/108] trying to fix query --- test/feature/mac/parameters.yml | 23 +------------------ validator/validators/basic/basic_validator.go | 21 +++++++++++++---- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/test/feature/mac/parameters.yml b/test/feature/mac/parameters.yml index 81c43b86d..db97054b3 100644 --- a/test/feature/mac/parameters.yml +++ b/test/feature/mac/parameters.yml @@ -13,7 +13,7 @@ number_monitored_logs: 1 # Number of metrics to be sent or number of log lines being written each minute values_per_minute: "2" # Number of seconds the agent should run and collect the metrics. In this case, 1 minutes -agent_collection_period: 60 +agent_collection_period: 10 cloudwatch_agent_config: "" @@ -24,19 +24,7 @@ metric_namespace: "CloudWatchAgentMacFeature" metric_validation: # Validator generates metrics # https://github.com/aws/amazon-cloudwatch-agent-test/blob/4365fbdbf979756e7f6db7f795a8a84b2c4f57c1/internal/common/metrics.go#L130-L165 - - metric_name: "statsd_gauge_1" - metric_value: 1.0 - metric_sample_count: 1 - metric_dimension: - - name: "metric_type" - value: "gauge" - - metric_name: "statsd_counter_1" - metric_value: 1.0 - metric_sample_count: 1 - metric_dimension: - - name: "metric_type" - value: "counter" # Validator generates emf metrics # https://github.com/aws/amazon-cloudwatch-agent-test/blob/62930a4acf466934b3894658e2060dd5840c49c4/internal/common/metrics.go#L170-L211s @@ -128,15 +116,6 @@ metric_validation: - metric_name: "mem_used_percent" metric_sample_count: 60 metric_dimension: [] - - metric_name: "Fault" - metric_sample_count: 60 - metric_dimension: [ ] - - metric_name: "Latency" - metric_sample_count: 60 - metric_dimension: [ ] - - metric_name: "Error" - metric_sample_count: 60 - metric_dimension: [ ] # Logs that the test needs to validate; moreover, the feature validation already has # InstanceID as a log group; therefore, does not need to pass it diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 7d6f62c34..1d3eedaeb 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -81,12 +81,25 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Value: aws.String(dimension.Value), }) } - //environmentValue := "Generic" // Replace with actual value - //operationValue := "replaced-operation" // Replace with actual value - //serviceValue := "service-name" // Replace with actual value + environmentValue := "Generic" // Replace with actual value + operationValue := "replaced-operation" // Replace with actual value + serviceValue := "service-name" // Replace with actual value // Creating the first group of dimensions - appSignalDimensions := []cwtypes.Dimension{} + appSignalDimensions := []cwtypes.Dimension{ + { + Name: aws.String("HostedIn.Environment"), + Value: aws.String(environmentValue), + }, + { + Name: aws.String("Operation"), + Value: aws.String(operationValue), + }, + { + Name: aws.String("Service"), + Value: aws.String(serviceValue), + }, + } //quick testing method for app signals if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { From d91b8e6bf8159c5aff50c98e07285044edea3e98 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 12:20:42 -0400 Subject: [PATCH 023/108] trying to fix query --- validator/validators/basic/basic_validator.go | 4 ++-- validator/validators/validator.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 1d3eedaeb..c11f43503 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -249,9 +249,9 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr // Validate if the metrics are not dropping any metrics and able to backfill within the same minute (e.g if the memory_rss metric is having collection_interval 1 // , it will need to have 60 sample counts - 1 datapoint / second) if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, 1, metricSampleCount+10, int32(boundAndPeriod)); !ok { - return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount, metricSampleCount) + return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, 1, metricSampleCount) } else { - fmt.Println("Yayyyyyyy!!!!!!! sample count is good for :", metricName, metricSampleCount) + fmt.Println("Yayyyyyyy!!!!!!! sample count is good for :", metricName) } // Validate if the corresponding metrics are within the acceptable range [acceptable value +- 10%] diff --git a/validator/validators/validator.go b/validator/validators/validator.go index 3e6cfb8b5..ca1e68dde 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -32,8 +32,8 @@ func NewValidator(vConfig models.ValidateConfig) (validator models.ValidatorFact func LaunchValidator(vConfig models.ValidateConfig) error { var ( agentCollectionPeriod = vConfig.GetAgentCollectionPeriod() - startTimeValidation = time.Now() - endTimeValidation = startTimeValidation.Add(agentCollectionPeriod) + startTimeValidation = time.Now().Add(-1 * time.Minute) + endTimeValidation = startTimeValidation.Add(agentCollectionPeriod + 2*time.Minute) //durationBeforeNextMinute = time.Until(startTimeValidation) ) From c30881ec7e58b71755957fdb94a0d9268b1b76fa Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 12:30:21 -0400 Subject: [PATCH 024/108] trying to fix query --- validator/validators/basic/basic_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index c11f43503..233e51864 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -103,7 +103,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { //quick testing method for app signals if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { - err := s.ValidateMetric(metric.MetricName, "AppSignals", appSignalDimensions, metric.MetricValue, 1, startTime, endTime) + err := s.ValidateMetric(metric.MetricName, "default", appSignalDimensions, metric.MetricValue, 1, startTime, endTime) if err != nil { multiErr = multierr.Append(multiErr, err) } From 8200db6dd7e2dc259c370e25fd160b4d6ae2e205 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 12:35:42 -0400 Subject: [PATCH 025/108] trying to fix query --- util/common/metrics.go | 55 ++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index 53301f5e4..55ea0e34f 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -4,10 +4,15 @@ package common import ( + "bytes" "context" "errors" "fmt" + "io/ioutil" "net" + "net/http" + "os" + "strings" "time" "collectd.org/api" @@ -132,20 +137,44 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } } +func processFile(filePath string, startTime int64) { + data, err := ioutil.ReadFile(filePath) + if err != nil { + fmt.Println("Error reading file:", err) + return + } + + // Replace START_TIME with the current time + modifiedData := strings.ReplaceAll(string(data), "START_TIME", fmt.Sprintf("%d", startTime)) + + // Mimic `curl` command - sending HTTP POST request + url := "http://127.0.0.1:4316/v1/metrics" + _, err = http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) + if err != nil { + fmt.Println("Error sending request:", err) + } +} func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendingInterval, duration time.Duration) error { // The bash script to be executed asynchronously. - RunCommand("pwd") - cmd := `while true; export START_TIME=$(date +%s%N); do - cat ~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/server_consumer.json | sed -e "s/START_TIME/$START_TIME/" > server_consumer.json; - curl -H 'Content-Type: application/json' -d @server_consumer.json -i http://127.0.0.1:4316/v1/metrics --verbose; - cat ~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/server_consumer.json - cat ~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json | sed -e "s/START_TIME/$START_TIME/" > client_producer.json; - curl -H 'Content-Type: application/json' -d @client_producer.json -i http://127.0.0.1:4316/v1/metrics --verbose; - cat ~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json - tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log - sleep 5; done` - - holder := RunAsyncCommand(cmd) + dir, err := os.Getwd() + if err != nil { + fmt.Println("Error getting current directory:", err) + return err + } + fmt.Println("Current Directory:", dir) + + // Infinite loop to mimic `while true` + for { + // Get current time like `date +%s%N` + startTime := time.Now().UnixNano() + + // Mimic the `sed` command to replace START_TIME in JSON files + processFile("~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/server_consumer.json", startTime) + processFile("~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json", startTime) + + // Sleep for 5 seconds like `sleep 5` + time.Sleep(5 * time.Second) + } //fmt.Println("Attempting to read amazon cloudwatch agent logs") //logFilePath := "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log" // @@ -201,7 +230,7 @@ func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendi //if err := scanner.Err(); err != nil { // fmt.Println("Error reading file:", err) //} - return holder + return nil } From 31104b06b79a1373c984508cdcf66da2111a1c96 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 12:37:12 -0400 Subject: [PATCH 026/108] trying to fix query --- util/common/metrics.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index 55ea0e34f..674d1a978 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -8,7 +8,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "net" "net/http" "os" @@ -138,7 +137,7 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } func processFile(filePath string, startTime int64) { - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) // Using os.ReadFile here if err != nil { fmt.Println("Error reading file:", err) return From 269ab697f76698f4d9001c846d2c8bfe20c87b60 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 12:38:41 -0400 Subject: [PATCH 027/108] trying to fix query --- util/common/metrics.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index 674d1a978..76cc3b4c2 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -11,6 +11,8 @@ import ( "net" "net/http" "os" + "os/user" + "path/filepath" "strings" "time" @@ -137,7 +139,19 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } func processFile(filePath string, startTime int64) { - data, err := os.ReadFile(filePath) // Using os.ReadFile here + // Expand the '~' to the user's home directory + if strings.HasPrefix(filePath, "~/") { + usr, err := user.Current() + if err != nil { + fmt.Println("Error getting current user:", err) + return + } + homeDir := usr.HomeDir + filePath = filepath.Join(homeDir, filePath[2:]) + } + + // Read the file + data, err := os.ReadFile(filePath) if err != nil { fmt.Println("Error reading file:", err) return From 08d4245f6921deced8fd56a037701c50587b6024 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 12:40:02 -0400 Subject: [PATCH 028/108] trying to fix query --- util/common/metrics.go | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index 76cc3b4c2..db93968df 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -11,8 +11,6 @@ import ( "net" "net/http" "os" - "os/user" - "path/filepath" "strings" "time" @@ -139,19 +137,7 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } func processFile(filePath string, startTime int64) { - // Expand the '~' to the user's home directory - if strings.HasPrefix(filePath, "~/") { - usr, err := user.Current() - if err != nil { - fmt.Println("Error getting current user:", err) - return - } - homeDir := usr.HomeDir - filePath = filepath.Join(homeDir, filePath[2:]) - } - - // Read the file - data, err := os.ReadFile(filePath) + data, err := os.ReadFile(filePath) // Using os.ReadFile here if err != nil { fmt.Println("Error reading file:", err) return @@ -182,8 +168,8 @@ func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendi startTime := time.Now().UnixNano() // Mimic the `sed` command to replace START_TIME in JSON files - processFile("~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/server_consumer.json", startTime) - processFile("~/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json", startTime) + processFile("/Users/ec2-user/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/server_consumer.json", startTime) + processFile("/Users/ec2-user/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json", startTime) // Sleep for 5 seconds like `sleep 5` time.Sleep(5 * time.Second) From 036ee15329efa9494c62608715754181cf82f9c3 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 12:42:50 -0400 Subject: [PATCH 029/108] trying to fix query --- validator/validators/basic/basic_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 233e51864..c11f43503 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -103,7 +103,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { //quick testing method for app signals if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { - err := s.ValidateMetric(metric.MetricName, "default", appSignalDimensions, metric.MetricValue, 1, startTime, endTime) + err := s.ValidateMetric(metric.MetricName, "AppSignals", appSignalDimensions, metric.MetricValue, 1, startTime, endTime) if err != nil { multiErr = multierr.Append(multiErr, err) } From af13a4bd7a227c63c799d7f38c4ee65b2ce66f87 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 14:38:53 -0400 Subject: [PATCH 030/108] fixing dimensions of app signal --- test/feature/mac/agent_config.json | 3 ++- validator/validators/basic/basic_validator.go | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test/feature/mac/agent_config.json b/test/feature/mac/agent_config.json index db2ddc2e0..90aca38cc 100644 --- a/test/feature/mac/agent_config.json +++ b/test/feature/mac/agent_config.json @@ -106,4 +106,5 @@ }, "force_flush_interval": 5 } -} \ No newline at end of file +} + diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index c11f43503..2df0d9b94 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -81,9 +81,9 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Value: aws.String(dimension.Value), }) } - environmentValue := "Generic" // Replace with actual value - operationValue := "replaced-operation" // Replace with actual value - serviceValue := "service-name" // Replace with actual value + environmentValue := "Generic" // Replace with actual value + operationValue := "operation" // Replace with actual value + serviceValue := "service-name" // Replace with actual value // Creating the first group of dimensions appSignalDimensions := []cwtypes.Dimension{ From 80564a6b0be8fe84df0eddae528feb0e2193cf56 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 14:54:25 -0400 Subject: [PATCH 031/108] this should work... --- util/common/metrics.go | 56 +---------------- validator/validators/basic/basic_validator.go | 61 +------------------ .../validators/feature/feature_validator.go | 2 +- validator/validators/validator.go | 16 ++--- 4 files changed, 11 insertions(+), 124 deletions(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index db93968df..354129041 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -174,61 +174,7 @@ func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendi // Sleep for 5 seconds like `sleep 5` time.Sleep(5 * time.Second) } - //fmt.Println("Attempting to read amazon cloudwatch agent logs") - //logFilePath := "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log" - // - //// Open the file - //file, err := os.Open(logFilePath) - //if err != nil { - // fmt.Println("Error opening file:", err) - // return err - //} - //defer file.Close() - // - //// Create a new Scanner for the file - //scanner := bufio.NewScanner(file) - // - //// Loop over all lines in the file - //for scanner.Scan() { - // // Print each line - // fmt.Println(scanner.Text()) - //} - // - //// Check for errors during Scan - //if err := scanner.Err(); err != nil { - // fmt.Println("Error reading file:", err) - //} - //homeDir, err := os.UserHomeDir() - //if err != nil { - // fmt.Println("Error getting home directory:", err) - // return err - //} - // - //// Construct the file path - //jsonFilePath := filepath.Join(homeDir, "amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json") - //fmt.Println("Attempting to read client_producer.json") - // - //// Open the JSON file - //file, err = os.Open(jsonFilePath) - //if err != nil { - // fmt.Println("Error opening file:", err) - // return err - //} - //defer file.Close() - // - //// Create a new Scanner for the file - //scanner = bufio.NewScanner(file) - // - //// Loop over all lines in the file - //for scanner.Scan() { - // // Print each line - // fmt.Println(scanner.Text()) - //} - // - //// Check for errors during Scan - //if err := scanner.Err(); err != nil { - // fmt.Println("Error reading file:", err) - //} + return nil } diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 2df0d9b94..0d4592ec7 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -103,7 +103,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { //quick testing method for app signals if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { - err := s.ValidateMetric(metric.MetricName, "AppSignals", appSignalDimensions, metric.MetricValue, 1, startTime, endTime) + err := s.ValidateMetric(metric.MetricName, "AppSignals", appSignalDimensions, metric.MetricValue, metric.MetricSampleCount, startTime, endTime) if err != nil { multiErr = multierr.Append(multiErr, err) } @@ -188,61 +188,6 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr } fmt.Printf("For metric: %v This is the metric data result: %v and the result values: %v", metricName, metrics.MetricDataResults, metrics.MetricDataResults[0].Values) if len(metrics.MetricDataResults) == 0 || len(metrics.MetricDataResults[0].Values) == 0 { - //fmt.Println("Attempting to read amazon cloudwatch agent logs after trying to validate getting metrics") - //logFilePath := "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log" - // - //// Open the file - //file, err := os.Open(logFilePath) - //if err != nil { - // fmt.Println("Error opening file:", err) - // return err - //} - //defer file.Close() - // - //// Create a new Scanner for the file - //scanner := bufio.NewScanner(file) - // - //// Loop over all lines in the file - //for scanner.Scan() { - // // Print each line - // fmt.Println(scanner.Text()) - //} - // - //// Check for errors during Scan - //if err := scanner.Err(); err != nil { - // fmt.Println("Error reading file:", err) - //} - //homeDir, err := os.UserHomeDir() - //if err != nil { - // fmt.Println("Error getting home directory:", err) - // return err - //} - // - //// Construct the file path - //jsonFilePath := filepath.Join(homeDir, "amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json") - //fmt.Println("Attempting to read client_producer.json") - // - //// Open the JSON file - //file, err = os.Open(jsonFilePath) - //if err != nil { - // fmt.Println("Error opening file:", err) - // return err - //} - //defer file.Close() - // - //// Create a new Scanner for the file - //scanner = bufio.NewScanner(file) - // - //// Loop over all lines in the file - //for scanner.Scan() { - // // Print each line - // fmt.Println(scanner.Text()) - //} - // - //// Check for errors during Scan - //if err := scanner.Err(); err != nil { - // fmt.Println("Error reading file:", err) - //} return fmt.Errorf("\n getting metric %s failed with the namespace %s and dimension %v", metricName, metricNamespace, util.LogCloudWatchDimension(metricDimensions)) } @@ -285,10 +230,6 @@ func (s *BasicValidator) buildMetricQueries(metricName, metricNamespace string, Id: aws.String(strings.ToLower(metricName)), }, } - //if metricName == "Latency" || metricName == "Fault" || metricName == "Error" { - // metricDataQueries[0].MetricStat.Unit = "Milliseconds" - // *metricDataQueries[0].ReturnData = true - //} fmt.Println("Maybe better form of metric query") jsonBytes, err := json.MarshalIndent(metricDataQueries, "", " ") diff --git a/validator/validators/feature/feature_validator.go b/validator/validators/feature/feature_validator.go index 231b83ad3..5fc84d629 100644 --- a/validator/validators/feature/feature_validator.go +++ b/validator/validators/feature/feature_validator.go @@ -31,7 +31,7 @@ func NewFeatureValidator(vConfig models.ValidateConfig) models.ValidatorFactory func (s *FeatureValidator) GenerateLoad() error { var ( multiErr error - metricSendingInterval = 10 * time.Second + metricSendingInterval = time.Minute logGroup = awsservice.GetInstanceId() metricNamespace = s.vConfig.GetMetricNamespace() dataRate = s.vConfig.GetDataRate() diff --git a/validator/validators/validator.go b/validator/validators/validator.go index ca1e68dde..e137c6b64 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -31,18 +31,18 @@ func NewValidator(vConfig models.ValidateConfig) (validator models.ValidatorFact func LaunchValidator(vConfig models.ValidateConfig) error { var ( - agentCollectionPeriod = vConfig.GetAgentCollectionPeriod() - startTimeValidation = time.Now().Add(-1 * time.Minute) - endTimeValidation = startTimeValidation.Add(agentCollectionPeriod + 2*time.Minute) - //durationBeforeNextMinute = time.Until(startTimeValidation) + agentCollectionPeriod = vConfig.GetAgentCollectionPeriod() + startTimeValidation = time.Now().Truncate(time.Minute).Add(time.Minute) + endTimeValidation = startTimeValidation.Add(agentCollectionPeriod) + durationBeforeNextMinute = time.Until(startTimeValidation) ) validator, err := NewValidator(vConfig) if err != nil { return err } - //log.Printf("Start to sleep %f s for the metric to be available in the beginning of next minute ", durationBeforeNextMinute.Seconds()) - //time.Sleep(durationBeforeNextMinute) + log.Printf("Start to sleep %f s for the metric to be available in the beginning of next minute ", durationBeforeNextMinute.Seconds()) + time.Sleep(durationBeforeNextMinute) log.Printf("Start to generate load in %f s for the agent to collect and send all the metrics to CloudWatch within the datapoint period ", agentCollectionPeriod.Seconds()) err = validator.GenerateLoad() @@ -52,8 +52,8 @@ func LaunchValidator(vConfig models.ValidateConfig) error { } time.Sleep(agentCollectionPeriod) - log.Printf("Start to sleep 20s for CloudWatch to process all the metrics") - time.Sleep(10 * time.Second) + log.Printf("Start to sleep 120s for CloudWatch to process all the metrics") + time.Sleep(2 * time.Minute) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From f5a70cf0e37ff73aaa2beaf9d649ae0fe413f3aa Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 15:06:03 -0400 Subject: [PATCH 032/108] fixing sample count --- validator/validators/basic/basic_validator.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 0d4592ec7..8fc05c4ff 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -173,7 +173,6 @@ func (s *BasicValidator) ValidateLogs(logStream, logLine, logLevel, logSource st } func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metricDimensions []cwtypes.Dimension, metricValue float64, metricSampleCount int, startTime, endTime time.Time) error { - metricSampleCount = 10 var ( boundAndPeriod = s.vConfig.GetAgentCollectionPeriod().Seconds() ) @@ -193,7 +192,7 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr // Validate if the metrics are not dropping any metrics and able to backfill within the same minute (e.g if the memory_rss metric is having collection_interval 1 // , it will need to have 60 sample counts - 1 datapoint / second) - if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, 1, metricSampleCount+10, int32(boundAndPeriod)); !ok { + if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount, metricSampleCount, int32(boundAndPeriod)); !ok { return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, 1, metricSampleCount) } else { fmt.Println("Yayyyyyyy!!!!!!! sample count is good for :", metricName) From 89364c80579cefed737b36a23d3efd379255aca8 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 15:22:44 -0400 Subject: [PATCH 033/108] fixing inifinite loop on app sig --- util/common/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index 354129041..ea1877a63 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -163,7 +163,7 @@ func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendi fmt.Println("Current Directory:", dir) // Infinite loop to mimic `while true` - for { + for i := 0; i < int(duration/5); i++ { // Get current time like `date +%s%N` startTime := time.Now().UnixNano() From 4c618c568d40637775563c01419275e731f60c3e Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 16:44:55 -0400 Subject: [PATCH 034/108] fixing retry count --- util/common/metrics.go | 1 - validator/main.go | 2 ++ validator/models/validation_config.go | 2 ++ validator/validators/basic/basic_validator.go | 5 +++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index ea1877a63..890cda2e3 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -162,7 +162,6 @@ func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendi } fmt.Println("Current Directory:", dir) - // Infinite loop to mimic `while true` for i := 0; i < int(duration/5); i++ { // Get current time like `date +%s%N` startTime := time.Now().UnixNano() diff --git a/validator/main.go b/validator/main.go index 7395e5dab..bae8bdc92 100644 --- a/validator/main.go +++ b/validator/main.go @@ -6,6 +6,7 @@ package main import ( "flag" "fmt" + "github.com/aws/amazon-cloudwatch-agent-test/validator/validators/basic" "log" "os" "strings" @@ -79,6 +80,7 @@ func main() { func validate(vConfig models.ValidateConfig) error { var err error for i := 0; i < awsservice.StandardRetries; i++ { + basic.RetryCount = i + 1 err = validators.LaunchValidator(vConfig) if err == nil { diff --git a/validator/models/validation_config.go b/validator/models/validation_config.go index 6e281dccf..b2171705e 100644 --- a/validator/models/validation_config.go +++ b/validator/models/validation_config.go @@ -16,6 +16,7 @@ import ( ) var supportedReceivers = []string{"logs", "statsd", "collectd", "system", "emf", "xray", "app_signals"} +var retryCount = 0 type ValidateConfig interface { GetPluginsConfig() []string @@ -55,6 +56,7 @@ type validatorConfig struct { CommitHash string `yaml:"commit_hash"` CommitDate string `yaml:"commit_date"` + retryCount int } type MetricValidation struct { diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 8fc05c4ff..7ae3bd6e5 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -28,6 +28,7 @@ type BasicValidator struct { vConfig models.ValidateConfig } +var RetryCount = 1 var _ models.ValidatorFactory = (*BasicValidator)(nil) func NewBasicValidator(vConfig models.ValidateConfig) models.ValidatorFactory { @@ -192,6 +193,10 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr // Validate if the metrics are not dropping any metrics and able to backfill within the same minute (e.g if the memory_rss metric is having collection_interval 1 // , it will need to have 60 sample counts - 1 datapoint / second) + + if metricName == "Latency" || metricName == "Error" || metricName == "Fault" { + metricSampleCount = metricSampleCount * RetryCount + } if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount, metricSampleCount, int32(boundAndPeriod)); !ok { return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, 1, metricSampleCount) } else { From 1ffc98695183605073f9be449806760b980abc43 Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 17:06:07 -0400 Subject: [PATCH 035/108] fixing retry count --- validator/validators/basic/basic_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 7ae3bd6e5..6c79d332c 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -197,7 +197,7 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr if metricName == "Latency" || metricName == "Error" || metricName == "Fault" { metricSampleCount = metricSampleCount * RetryCount } - if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount, metricSampleCount, int32(boundAndPeriod)); !ok { + if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount-2, metricSampleCount, int32(boundAndPeriod)); !ok { return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, 1, metricSampleCount) } else { fmt.Println("Yayyyyyyy!!!!!!! sample count is good for :", metricName) From f593fd29c4837e8f88c7781092ffd7343a0d92da Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 17:56:22 -0400 Subject: [PATCH 036/108] adding windows component of the test --- util/common/metrics.go | 18 ++++++++++++++---- validator/validators/basic/basic_validator.go | 7 +++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index 890cda2e3..507506c2e 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -11,6 +11,8 @@ import ( "net" "net/http" "os" + "path/filepath" + "runtime" "strings" "time" @@ -162,15 +164,23 @@ func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendi } fmt.Println("Current Directory:", dir) + // Determine the base directory for the files based on the OS + var baseDir string + if runtime.GOOS == "windows" { + baseDir = "C:\\Users\\Administrator\\amazon-cloudwatch-agent-test\\test\\app_signals\\resources\\metrics" + } else { // assuming macOS or Unix-like system + baseDir = "/Users/ec2-user/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics" + } + for i := 0; i < int(duration/5); i++ { // Get current time like `date +%s%N` startTime := time.Now().UnixNano() - // Mimic the `sed` command to replace START_TIME in JSON files - processFile("/Users/ec2-user/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/server_consumer.json", startTime) - processFile("/Users/ec2-user/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics/client_producer.json", startTime) + // Process files with dynamic paths + processFile(filepath.Join(baseDir, "server_consumer.json"), startTime) + processFile(filepath.Join(baseDir, "client_producer.json"), startTime) - // Sleep for 5 seconds like `sleep 5` + // Sleep for 5 seconds time.Sleep(5 * time.Second) } diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 6c79d332c..a42d634a7 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -82,9 +82,9 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Value: aws.String(dimension.Value), }) } - environmentValue := "Generic" // Replace with actual value - operationValue := "operation" // Replace with actual value - serviceValue := "service-name" // Replace with actual value + environmentValue := "Generic" + operationValue := "operation" + serviceValue := "service-name" // Creating the first group of dimensions appSignalDimensions := []cwtypes.Dimension{ @@ -103,7 +103,6 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { } //quick testing method for app signals if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { - err := s.ValidateMetric(metric.MetricName, "AppSignals", appSignalDimensions, metric.MetricValue, metric.MetricSampleCount, startTime, endTime) if err != nil { multiErr = multierr.Append(multiErr, err) From 00aab07273185303a1b229dc6ba62b5fa554b39c Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 18:05:09 -0400 Subject: [PATCH 037/108] adding windows component of the test --- test/feature/mac/parameters.yml | 27 +++++++++++++++++++++++++ test/feature/windows/agent_config.json | 6 ++++++ test/feature/windows/parameters.yml | 28 ++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/test/feature/mac/parameters.yml b/test/feature/mac/parameters.yml index db97054b3..a348c0ea3 100644 --- a/test/feature/mac/parameters.yml +++ b/test/feature/mac/parameters.yml @@ -116,6 +116,33 @@ metric_validation: - metric_name: "mem_used_percent" metric_sample_count: 60 metric_dimension: [] + - metric_name: "Fault" + metric_sample_count: 12 + metric_dimension: + - name: "HostedIn.Environment" + value: "Generic" + - name: "Operation" + value: "operation" + - name: "Service" + value: "service-name" + - metric_name: "Latency" + metric_sample_count: 12 + metric_dimension: + - name: "HostedIn.Environment" + value: "Generic" + - name: "Operation" + value: "operation" + - name: "Service" + value: "service-name" + - metric_name: "Error" + metric_sample_count: 12 + metric_dimension: + - name: "HostedIn.Environment" + value: "Generic" + - name: "Operation" + value: "operation" + - name: "Service" + value: "service-name" # Logs that the test needs to validate; moreover, the feature validation already has # InstanceID as a log group; therefore, does not need to pass it diff --git a/test/feature/windows/agent_config.json b/test/feature/windows/agent_config.json index 8a605053a..5ddf146ce 100644 --- a/test/feature/windows/agent_config.json +++ b/test/feature/windows/agent_config.json @@ -2,6 +2,11 @@ "agent": { "debug": true }, + "traces": { + "traces_collected": { + "app_signals": {} + } + }, "metrics": { "namespace": "CloudWatchAgentWinFeature", "metrics_collected": { @@ -217,6 +222,7 @@ } }, "metrics_collected": { + "app_signals": {}, "emf": { }, "prometheus": { "prometheus_config_path": "C:/jmx_workload/prometheus.yaml", diff --git a/test/feature/windows/parameters.yml b/test/feature/windows/parameters.yml index 76f409a9f..116753eb1 100644 --- a/test/feature/windows/parameters.yml +++ b/test/feature/windows/parameters.yml @@ -198,6 +198,34 @@ metric_validation: metric_dimension: - name: "objectname" value: "TCPv6" + + - metric_name: "Fault" + metric_sample_count: 12 + metric_dimension: + - name: "HostedIn.Environment" + value: "Generic" + - name: "Operation" + value: "operation" + - name: "Service" + value: "service-name" + - metric_name: "Latency" + metric_sample_count: 12 + metric_dimension: + - name: "HostedIn.Environment" + value: "Generic" + - name: "Operation" + value: "operation" + - name: "Service" + value: "service-name" + - metric_name: "Error" + metric_sample_count: 12 + metric_dimension: + - name: "HostedIn.Environment" + value: "Generic" + - name: "Operation" + value: "operation" + - name: "Service" + value: "service-name" # Logs that the test needs to validate; moreover, the feature validation already has # InstanceID as a log group; therefore, does not need to pass it # https://github.com/aws/amazon-cloudwatch-agent-test/blob/96f576e865b55de5e2aa88e4cf80b79c4d3dad70/validator/validators/feature/feature_validator.go#L108-L111 From fa1062cd7e0ade63630a930ba1dccc000bd1c59f Mon Sep 17 00:00:00 2001 From: siprmp Date: Wed, 3 Apr 2024 18:13:53 -0400 Subject: [PATCH 038/108] fixing parameters.yml agent_collection_period --- test/feature/mac/parameters.yml | 32 +++++++++++++------ validator/validators/basic/basic_validator.go | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/test/feature/mac/parameters.yml b/test/feature/mac/parameters.yml index a348c0ea3..0b2393177 100644 --- a/test/feature/mac/parameters.yml +++ b/test/feature/mac/parameters.yml @@ -13,7 +13,7 @@ number_monitored_logs: 1 # Number of metrics to be sent or number of log lines being written each minute values_per_minute: "2" # Number of seconds the agent should run and collect the metrics. In this case, 1 minutes -agent_collection_period: 10 +agent_collection_period: 60 cloudwatch_agent_config: "" @@ -24,45 +24,57 @@ metric_namespace: "CloudWatchAgentMacFeature" metric_validation: # Validator generates metrics # https://github.com/aws/amazon-cloudwatch-agent-test/blob/4365fbdbf979756e7f6db7f795a8a84b2c4f57c1/internal/common/metrics.go#L130-L165 + - metric_name: "statsd_gauge_1" + metric_value: 1.0 + metric_sample_count: 1 + metric_dimension: + - name: "metric_type" + value: "gauge" + - metric_name: "statsd_counter_1" + metric_value: 1.0 + metric_sample_count: 1 + metric_dimension: + - name: "metric_type" + value: "counter" # Validator generates emf metrics # https://github.com/aws/amazon-cloudwatch-agent-test/blob/62930a4acf466934b3894658e2060dd5840c49c4/internal/common/metrics.go#L170-L211s - metric_name: "emf_time_1" metric_value: 1.0 metric_sample_count: 1 - + - metric_name: "emf_time_2" metric_value: 2.0 metric_sample_count: 1 - metric_name: "cpu_time_active" metric_sample_count: 60 - metric_dimension: + metric_dimension: - name: "cpu" value: "cpu-total" - metric_name: "cpu_time_guest" metric_sample_count: 60 - metric_dimension: + metric_dimension: - name: "cpu" value: "cpu-total" - metric_name: "net_bytes_sent" metric_sample_count: 60 - metric_dimension: + metric_dimension: - name: "interface" value: "en0" - metric_name: "net_bytes_recv" metric_sample_count: 60 - metric_dimension: + metric_dimension: - name: "interface" value: "en0" - metric_name: "disk_free" metric_sample_count: 60 - metric_dimension: + metric_dimension: - name: "fstype" value: "devfs" - name: "path" @@ -70,7 +82,7 @@ metric_validation: - metric_name: "disk_used_percent" metric_sample_count: 60 - metric_dimension: + metric_dimension: - name: "fstype" value: "devfs" - name: "path" @@ -78,7 +90,7 @@ metric_validation: - metric_name: "procstat_cpu_usage" metric_sample_count: 60 - metric_dimension: + metric_dimension: - name: "exe" value: "amazon-cloudwatch-agent" - name: "process_name" @@ -86,7 +98,7 @@ metric_validation: - metric_name: "procstat_memory_rss" metric_sample_count: 60 - metric_dimension: + metric_dimension: - name: "exe" value: "amazon-cloudwatch-agent" - name: "process_name" diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index a42d634a7..c9b3d1384 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -197,7 +197,7 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr metricSampleCount = metricSampleCount * RetryCount } if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount-2, metricSampleCount, int32(boundAndPeriod)); !ok { - return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, 1, metricSampleCount) + return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount-2, metricSampleCount) } else { fmt.Println("Yayyyyyyy!!!!!!! sample count is good for :", metricName) } From 73f6d1398f7b1e2ef721ecf1259bd13715e6179a Mon Sep 17 00:00:00 2001 From: siprmp Date: Thu, 4 Apr 2024 00:26:34 -0400 Subject: [PATCH 039/108] fixing sample count --- validator/validators/basic/basic_validator.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index c9b3d1384..30e839903 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -193,9 +193,6 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr // Validate if the metrics are not dropping any metrics and able to backfill within the same minute (e.g if the memory_rss metric is having collection_interval 1 // , it will need to have 60 sample counts - 1 datapoint / second) - if metricName == "Latency" || metricName == "Error" || metricName == "Fault" { - metricSampleCount = metricSampleCount * RetryCount - } if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount-2, metricSampleCount, int32(boundAndPeriod)); !ok { return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount-2, metricSampleCount) } else { From 42bf9879b07d627ac511a7903496f12d44b71ed2 Mon Sep 17 00:00:00 2001 From: siprmp Date: Thu, 4 Apr 2024 01:03:03 -0400 Subject: [PATCH 040/108] adding traces testing --- test/feature/mac/parameters.yml | 2 +- test/feature/windows/parameters.yml | 2 +- util/common/metrics.go | 63 ++++++++++++++++++- validator/models/validation_config.go | 2 +- validator/validators/basic/basic_validator.go | 21 ++++++- 5 files changed, 84 insertions(+), 6 deletions(-) diff --git a/test/feature/mac/parameters.yml b/test/feature/mac/parameters.yml index 0b2393177..15b9642bb 100644 --- a/test/feature/mac/parameters.yml +++ b/test/feature/mac/parameters.yml @@ -1,5 +1,5 @@ # Receivers that agent needs to tests -receivers: ["system","statsd","emf","app_signals"] +receivers: ["system","statsd","emf","app_signals","traces"] #Test case name test_case: "macos_feature" diff --git a/test/feature/windows/parameters.yml b/test/feature/windows/parameters.yml index 116753eb1..0273d5641 100644 --- a/test/feature/windows/parameters.yml +++ b/test/feature/windows/parameters.yml @@ -1,5 +1,5 @@ # Receivers that agent needs to tests -receivers: ["system","statsd","emf"] +receivers: ["system","statsd","emf","app_signals","traces"] #Test case name test_case: "win_feature" diff --git a/util/common/metrics.go b/util/common/metrics.go index 507506c2e..ad2ad4601 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -6,6 +6,9 @@ package common import ( "bytes" "context" + "crypto/rand" + "encoding/binary" + "encoding/hex" "errors" "fmt" "net" @@ -34,7 +37,10 @@ func StartSendingMetrics(receiver string, duration, sendingInterval time.Duratio case "emf": err = SendEMFMetrics(metricPerInterval, metricLogGroup, metricNamespace, sendingInterval, duration) case "app_signals": - err = SendAppSignalMetrics(metricPerInterval, []string{}, sendingInterval, duration) //does app signals have dimension for metric? + err = SendAppSignalMetrics(duration) //does app signals have dimension for metric? + case "traces": + err = SendAppTraceMetrics(duration) //does app signals have dimension for metric? + default: } }() @@ -42,6 +48,59 @@ func StartSendingMetrics(receiver string, duration, sendingInterval time.Duratio return err } +func SendAppTraceMetrics(duration time.Duration) error { + baseDir := getBaseDir() + + for i := 0; i < int(duration/(5*time.Second)); i++ { + startTime := time.Now().UnixNano() + traceID := generateTraceID() + traceIDStr := hex.EncodeToString(traceID[:]) + + err := processTraceFile(filepath.Join(baseDir, "traces.json"), startTime, traceIDStr) + if err != nil { + fmt.Println("Error processing trace file:", err) + return err + } + + time.Sleep(5 * time.Second) + } + + return nil +} + +func getBaseDir() string { + if runtime.GOOS == "windows" { + return "C:\\Users\\Administrator\\amazon-cloudwatch-agent-test\\test\\app_signals\\resources\\traces" + } + return "/Users/ec2-user/amazon-cloudwatch-agent-test/test/app_signals/resources/traces" +} + +func generateTraceID() [16]byte { + var r [16]byte + epochNow := time.Now().Unix() + binary.BigEndian.PutUint32(r[0:4], uint32(epochNow)) + rand.Read(r[4:]) + return r +} + +func processTraceFile(filePath string, startTime int64, traceID string) error { + data, err := os.ReadFile(filePath) + if err != nil { + return err + } + + modifiedData := strings.ReplaceAll(string(data), "START_TIME", fmt.Sprintf("%d", startTime)) + modifiedData = strings.ReplaceAll(modifiedData, "TRACE_ID", traceID) + + url := "http://127.0.0.1:4316/v1/traces" + _, err = http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) + if err != nil { + return err + } + + return nil +} + func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.Duration) error { // https://github.com/collectd/go-collectd/tree/92e86f95efac5eb62fa84acc6033e7a57218b606 ctx, cancel := context.WithCancel(context.Background()) @@ -155,7 +214,7 @@ func processFile(filePath string, startTime int64) { fmt.Println("Error sending request:", err) } } -func SendAppSignalMetrics(metricPerInterval int, metricDimension []string, sendingInterval, duration time.Duration) error { +func SendAppSignalMetrics(duration time.Duration) error { // The bash script to be executed asynchronously. dir, err := os.Getwd() if err != nil { diff --git a/validator/models/validation_config.go b/validator/models/validation_config.go index b2171705e..26fc57a91 100644 --- a/validator/models/validation_config.go +++ b/validator/models/validation_config.go @@ -15,7 +15,7 @@ import ( "gopkg.in/yaml.v3" ) -var supportedReceivers = []string{"logs", "statsd", "collectd", "system", "emf", "xray", "app_signals"} +var supportedReceivers = []string{"logs", "statsd", "collectd", "system", "emf", "xray", "app_signals", "traces"} var retryCount = 0 type ValidateConfig interface { diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 30e839903..973746358 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -113,9 +113,28 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { multiErr = multierr.Append(multiErr, err) } } + lookbackDuration := time.Duration(-5) * time.Minute + timeNow := time.Now() + var annotations = map[string]interface{}{ + "aws_remote_target": "remote-target", + "aws_remote_operation": "remote-operation", + "aws_local_service": "service-name", + "aws_remote_service": "service-name-remote", + "aws_local_operation": "replaced-operation", + } + xrayFilter := awsservice.FilterExpression(annotations) + traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, xrayFilter) + if err != nil { + fmt.Printf("error getting trace ids: %v", err) + multiErr = multierr.Append(multiErr, err) + } else { + fmt.Printf("Trace IDs: %v\n", traceIds) + if len(traceIds) > 0 { + fmt.Println("Trace IDs look good") + } + } } - for _, logValidation := range logValidations { err := s.ValidateLogs(logValidation.LogStream, logValidation.LogValue, logValidation.LogLevel, logValidation.LogSource, logValidation.LogLines, startTime, endTime) if err != nil { From 8a7dc41c41858cae617710ff8bf45a60fc6f0250 Mon Sep 17 00:00:00 2001 From: siprmp Date: Thu, 4 Apr 2024 09:52:37 -0400 Subject: [PATCH 041/108] adding a break in between sending metrics --- util/common/metrics.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/util/common/metrics.go b/util/common/metrics.go index ad2ad4601..9c59f0f64 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -11,6 +11,7 @@ import ( "encoding/hex" "errors" "fmt" + "io/ioutil" "net" "net/http" "os" @@ -26,6 +27,8 @@ import ( "github.com/prozz/aws-embedded-metrics-golang/emf" ) +const LastSendTimeFile = "last_send_time.txt" +const MinInterval = 60 // Minimum interval in seconds // StartSendingMetrics will generate metrics load based on the receiver (e.g 5000 statsd metrics per minute) func StartSendingMetrics(receiver string, duration, sendingInterval time.Duration, metricPerInterval int, metricLogGroup, metricNamespace string) (err error) { go func() { @@ -214,6 +217,27 @@ func processFile(filePath string, startTime int64) { fmt.Println("Error sending request:", err) } } +func shouldSendMetrics() (bool, error) { + data, err := os.ReadFile(LastSendTimeFile) + if err != nil { + if os.IsNotExist(err) { + return true, nil // File not found, so we should send + } + return false, err // Some other error reading the file + } + + lastSendTime, err := time.Parse(time.RFC3339, string(data)) + if err != nil { + return false, err // Error parsing the time + } + + return time.Since(lastSendTime).Seconds() > MinInterval, nil +} + +func updateLastSendTime() error { + now := time.Now().Format(time.RFC3339) + return ioutil.WriteFile(LastSendTimeFile, []byte(now), 0644) +} func SendAppSignalMetrics(duration time.Duration) error { // The bash script to be executed asynchronously. dir, err := os.Getwd() @@ -232,6 +256,14 @@ func SendAppSignalMetrics(duration time.Duration) error { } for i := 0; i < int(duration/5); i++ { + send, err := shouldSendMetrics() + if err != nil { + return err + } + if !send { + fmt.Println("Skipping sending metrics as it's too soon.") + continue + } // Get current time like `date +%s%N` startTime := time.Now().UnixNano() From c323a0535f40c6d8a0d7978cb1ce4b91e88f2375 Mon Sep 17 00:00:00 2001 From: siprmp Date: Fri, 5 Apr 2024 11:20:22 -0400 Subject: [PATCH 042/108] adding instance id to app signal metrics --- .../resources/metrics/client_producer.json | 20 +++++++++++- .../resources/metrics/server_consumer.json | 31 +++++++++++++++++++ util/common/metrics.go | 14 ++++----- validator/validators/basic/basic_validator.go | 4 +++ 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index fd0880075..57a36f502 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -54,7 +54,7 @@ { "key": "aws.local.service", "value": { - "stringValue": "alibaba-service" + "stringValue": "service-name" } }, { @@ -74,6 +74,12 @@ "value": { "stringValue": "remote-target" } + }, + { + "key": "InstanceID", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, @@ -127,6 +133,12 @@ "value": { "stringValue": "remote-target" } + }, + { + "key": "InstanceID", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, @@ -180,6 +192,12 @@ "value": { "stringValue": "remote-target" } + }, + { + "key": "InstanceID", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index eee7da3f6..a025d2bce 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -80,6 +80,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceID", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, @@ -139,6 +145,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceID", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, @@ -198,6 +210,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceID", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, @@ -257,8 +275,15 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceID", + "value": { + "stringValue": INSTANCE_ID + } } ], + "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, "sum": 1, @@ -316,6 +341,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceID", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, diff --git a/util/common/metrics.go b/util/common/metrics.go index 9c59f0f64..ae53b8bdc 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -11,7 +11,6 @@ import ( "encoding/hex" "errors" "fmt" - "io/ioutil" "net" "net/http" "os" @@ -40,7 +39,7 @@ func StartSendingMetrics(receiver string, duration, sendingInterval time.Duratio case "emf": err = SendEMFMetrics(metricPerInterval, metricLogGroup, metricNamespace, sendingInterval, duration) case "app_signals": - err = SendAppSignalMetrics(duration) //does app signals have dimension for metric? + err = SendAppSignalMetrics(duration, metricLogGroup) //does app signals have dimension for metric? case "traces": err = SendAppTraceMetrics(duration) //does app signals have dimension for metric? @@ -200,7 +199,7 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } } -func processFile(filePath string, startTime int64) { +func processFile(filePath string, startTime int64, instanceId string) { data, err := os.ReadFile(filePath) // Using os.ReadFile here if err != nil { fmt.Println("Error reading file:", err) @@ -209,6 +208,7 @@ func processFile(filePath string, startTime int64) { // Replace START_TIME with the current time modifiedData := strings.ReplaceAll(string(data), "START_TIME", fmt.Sprintf("%d", startTime)) + modifiedData = strings.ReplaceAll(string(data), "INSTANCE_ID", fmt.Sprintf("%d", instanceId)) // Mimic `curl` command - sending HTTP POST request url := "http://127.0.0.1:4316/v1/metrics" @@ -236,9 +236,9 @@ func shouldSendMetrics() (bool, error) { func updateLastSendTime() error { now := time.Now().Format(time.RFC3339) - return ioutil.WriteFile(LastSendTimeFile, []byte(now), 0644) + return os.WriteFile(LastSendTimeFile, []byte(now), 0644) } -func SendAppSignalMetrics(duration time.Duration) error { +func SendAppSignalMetrics(duration time.Duration, instanceId string) error { // The bash script to be executed asynchronously. dir, err := os.Getwd() if err != nil { @@ -268,8 +268,8 @@ func SendAppSignalMetrics(duration time.Duration) error { startTime := time.Now().UnixNano() // Process files with dynamic paths - processFile(filepath.Join(baseDir, "server_consumer.json"), startTime) - processFile(filepath.Join(baseDir, "client_producer.json"), startTime) + processFile(filepath.Join(baseDir, "server_consumer.json"), startTime, instanceId) + processFile(filepath.Join(baseDir, "client_producer.json"), startTime, instanceId) // Sleep for 5 seconds time.Sleep(5 * time.Second) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 973746358..795bd0273 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -100,6 +100,10 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Name: aws.String("Service"), Value: aws.String(serviceValue), }, + { + Name: aws.String("InstanceId"), + Value: aws.String(ec2InstanceId), + }, } //quick testing method for app signals if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { From f4fce6915df9a53920712f7c79a50f5c71555b41 Mon Sep 17 00:00:00 2001 From: siprmp Date: Fri, 5 Apr 2024 13:12:19 -0400 Subject: [PATCH 043/108] fixing dimension --- .../app_signals/resources/metrics/client_producer.json | 6 +++--- .../app_signals/resources/metrics/server_consumer.json | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 57a36f502..d23cd40a8 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -76,7 +76,7 @@ } }, { - "key": "InstanceID", + "key": "InstanceId", "value": { "stringValue": INSTANCE_ID } @@ -135,7 +135,7 @@ } }, { - "key": "InstanceID", + "key": "InstanceId", "value": { "stringValue": INSTANCE_ID } @@ -194,7 +194,7 @@ } }, { - "key": "InstanceID", + "key": "InstanceId", "value": { "stringValue": INSTANCE_ID } diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index a025d2bce..4218673d5 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -82,7 +82,7 @@ } }, { - "key": "InstanceID", + "key": "InstanceId", "value": { "stringValue": INSTANCE_ID } @@ -147,7 +147,7 @@ } }, { - "key": "InstanceID", + "key": "InstanceId", "value": { "stringValue": INSTANCE_ID } @@ -212,7 +212,7 @@ } }, { - "key": "InstanceID", + "key": "InstanceId", "value": { "stringValue": INSTANCE_ID } @@ -277,7 +277,7 @@ } }, { - "key": "InstanceID", + "key": "InstanceId", "value": { "stringValue": INSTANCE_ID } @@ -343,7 +343,7 @@ } }, { - "key": "InstanceID", + "key": "InstanceId", "value": { "stringValue": INSTANCE_ID } From 1eda9e7acb28d4be263c47d66b874c948dc9e2c2 Mon Sep 17 00:00:00 2001 From: siprmp Date: Sat, 6 Apr 2024 18:48:45 -0400 Subject: [PATCH 044/108] seeing if app signal works --- .../resources/metrics/client_producer.json | 18 ----------- .../resources/metrics/server_consumer.json | 31 ------------------- validator/validators/basic/basic_validator.go | 4 --- validator/validators/validator.go | 16 +++++----- 4 files changed, 8 insertions(+), 61 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index d23cd40a8..61cb1c812 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -74,12 +74,6 @@ "value": { "stringValue": "remote-target" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], "startTimeUnixNano": START_TIME, @@ -133,12 +127,6 @@ "value": { "stringValue": "remote-target" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], "startTimeUnixNano": START_TIME, @@ -192,12 +180,6 @@ "value": { "stringValue": "remote-target" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], "startTimeUnixNano": START_TIME, diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index 4218673d5..eee7da3f6 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -80,12 +80,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], "startTimeUnixNano": START_TIME, @@ -145,12 +139,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], "startTimeUnixNano": START_TIME, @@ -210,12 +198,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], "startTimeUnixNano": START_TIME, @@ -275,15 +257,8 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], - "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, "sum": 1, @@ -341,12 +316,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], "startTimeUnixNano": START_TIME, diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 795bd0273..973746358 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -100,10 +100,6 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Name: aws.String("Service"), Value: aws.String(serviceValue), }, - { - Name: aws.String("InstanceId"), - Value: aws.String(ec2InstanceId), - }, } //quick testing method for app signals if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { diff --git a/validator/validators/validator.go b/validator/validators/validator.go index e137c6b64..a0679995d 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -31,18 +31,18 @@ func NewValidator(vConfig models.ValidateConfig) (validator models.ValidatorFact func LaunchValidator(vConfig models.ValidateConfig) error { var ( - agentCollectionPeriod = vConfig.GetAgentCollectionPeriod() - startTimeValidation = time.Now().Truncate(time.Minute).Add(time.Minute) - endTimeValidation = startTimeValidation.Add(agentCollectionPeriod) - durationBeforeNextMinute = time.Until(startTimeValidation) + agentCollectionPeriod = vConfig.GetAgentCollectionPeriod() + startTimeValidation = time.Now() + endTimeValidation = startTimeValidation.Add(agentCollectionPeriod) + //durationBeforeNextMinute = time.Until(startTimeValidation) ) validator, err := NewValidator(vConfig) if err != nil { return err } - log.Printf("Start to sleep %f s for the metric to be available in the beginning of next minute ", durationBeforeNextMinute.Seconds()) - time.Sleep(durationBeforeNextMinute) + //log.Printf("Start to sleep %f s for the metric to be available in the beginning of next minute ", durationBeforeNextMinute.Seconds()) + //time.Sleep(durationBeforeNextMinute) log.Printf("Start to generate load in %f s for the agent to collect and send all the metrics to CloudWatch within the datapoint period ", agentCollectionPeriod.Seconds()) err = validator.GenerateLoad() @@ -52,8 +52,8 @@ func LaunchValidator(vConfig models.ValidateConfig) error { } time.Sleep(agentCollectionPeriod) - log.Printf("Start to sleep 120s for CloudWatch to process all the metrics") - time.Sleep(2 * time.Minute) + log.Printf("Start to sleep 20s for CloudWatch to process all the metrics") + time.Sleep(20 * time.Second) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From 26b07ceb0138944dd88251124f777475d9154a85 Mon Sep 17 00:00:00 2001 From: siprmp Date: Sat, 6 Apr 2024 19:02:40 -0400 Subject: [PATCH 045/108] first tyring to generate data regularly than will add instance id --- util/common/metrics.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index ae53b8bdc..01d04dea6 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -199,7 +199,7 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } } -func processFile(filePath string, startTime int64, instanceId string) { +func processFile(filePath string, startTime int64) { data, err := os.ReadFile(filePath) // Using os.ReadFile here if err != nil { fmt.Println("Error reading file:", err) @@ -208,7 +208,6 @@ func processFile(filePath string, startTime int64, instanceId string) { // Replace START_TIME with the current time modifiedData := strings.ReplaceAll(string(data), "START_TIME", fmt.Sprintf("%d", startTime)) - modifiedData = strings.ReplaceAll(string(data), "INSTANCE_ID", fmt.Sprintf("%d", instanceId)) // Mimic `curl` command - sending HTTP POST request url := "http://127.0.0.1:4316/v1/metrics" @@ -268,8 +267,8 @@ func SendAppSignalMetrics(duration time.Duration, instanceId string) error { startTime := time.Now().UnixNano() // Process files with dynamic paths - processFile(filepath.Join(baseDir, "server_consumer.json"), startTime, instanceId) - processFile(filepath.Join(baseDir, "client_producer.json"), startTime, instanceId) + processFile(filepath.Join(baseDir, "server_consumer.json"), startTime) + processFile(filepath.Join(baseDir, "client_producer.json"), startTime) // Sleep for 5 seconds time.Sleep(5 * time.Second) From cf7b928124174a29b24351c0b863c254c3b42593 Mon Sep 17 00:00:00 2001 From: siprmp Date: Sat, 6 Apr 2024 19:17:29 -0400 Subject: [PATCH 046/108] first tyring to generate data regularly than will add instance id --- validator/validators/validator.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/validator/validators/validator.go b/validator/validators/validator.go index a0679995d..e137c6b64 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -31,18 +31,18 @@ func NewValidator(vConfig models.ValidateConfig) (validator models.ValidatorFact func LaunchValidator(vConfig models.ValidateConfig) error { var ( - agentCollectionPeriod = vConfig.GetAgentCollectionPeriod() - startTimeValidation = time.Now() - endTimeValidation = startTimeValidation.Add(agentCollectionPeriod) - //durationBeforeNextMinute = time.Until(startTimeValidation) + agentCollectionPeriod = vConfig.GetAgentCollectionPeriod() + startTimeValidation = time.Now().Truncate(time.Minute).Add(time.Minute) + endTimeValidation = startTimeValidation.Add(agentCollectionPeriod) + durationBeforeNextMinute = time.Until(startTimeValidation) ) validator, err := NewValidator(vConfig) if err != nil { return err } - //log.Printf("Start to sleep %f s for the metric to be available in the beginning of next minute ", durationBeforeNextMinute.Seconds()) - //time.Sleep(durationBeforeNextMinute) + log.Printf("Start to sleep %f s for the metric to be available in the beginning of next minute ", durationBeforeNextMinute.Seconds()) + time.Sleep(durationBeforeNextMinute) log.Printf("Start to generate load in %f s for the agent to collect and send all the metrics to CloudWatch within the datapoint period ", agentCollectionPeriod.Seconds()) err = validator.GenerateLoad() @@ -52,8 +52,8 @@ func LaunchValidator(vConfig models.ValidateConfig) error { } time.Sleep(agentCollectionPeriod) - log.Printf("Start to sleep 20s for CloudWatch to process all the metrics") - time.Sleep(20 * time.Second) + log.Printf("Start to sleep 120s for CloudWatch to process all the metrics") + time.Sleep(2 * time.Minute) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From cd6f1024f99fb2b5c6c2d9f97cc8b6d709783398 Mon Sep 17 00:00:00 2001 From: siprmp Date: Sat, 6 Apr 2024 19:33:09 -0400 Subject: [PATCH 047/108] previous commit works, this adds instance id to metric --- .../resources/metrics/client_producer.json | 20 ++++++++++- .../resources/metrics/server_consumer.json | 34 ++++++++++++++++++- test/feature/mac/agent_config.json | 6 ++++ util/common/metrics.go | 7 ++-- validator/validators/basic/basic_validator.go | 4 +++ 5 files changed, 66 insertions(+), 5 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 61cb1c812..8e8473ac8 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -74,6 +74,12 @@ "value": { "stringValue": "remote-target" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, @@ -127,6 +133,12 @@ "value": { "stringValue": "remote-target" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, @@ -180,6 +192,12 @@ "value": { "stringValue": "remote-target" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, @@ -196,4 +214,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index eee7da3f6..8fbb1de35 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -1,3 +1,4 @@ +//server_consumer with instance id { "resourceMetrics": [ { @@ -80,6 +81,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, @@ -139,6 +146,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, @@ -198,6 +211,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, @@ -257,8 +276,15 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": INSTANCE_ID + } } ], + "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, "sum": 1, @@ -316,6 +342,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": INSTANCE_ID + } } ], "startTimeUnixNano": START_TIME, @@ -332,4 +364,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/test/feature/mac/agent_config.json b/test/feature/mac/agent_config.json index 90aca38cc..df3d39d57 100644 --- a/test/feature/mac/agent_config.json +++ b/test/feature/mac/agent_config.json @@ -4,6 +4,9 @@ }, "traces": { "traces_collected": { + "append_dimensions": { + "InstanceId": "${aws:InstanceId}" + }, "app_signals": {} } }, @@ -101,6 +104,9 @@ } }, "metrics_collected": { + "append_dimensions": { + "InstanceId": "${aws:InstanceId}" + }, "app_signals": {}, "emf": { } }, diff --git a/util/common/metrics.go b/util/common/metrics.go index 01d04dea6..ae53b8bdc 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -199,7 +199,7 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } } -func processFile(filePath string, startTime int64) { +func processFile(filePath string, startTime int64, instanceId string) { data, err := os.ReadFile(filePath) // Using os.ReadFile here if err != nil { fmt.Println("Error reading file:", err) @@ -208,6 +208,7 @@ func processFile(filePath string, startTime int64) { // Replace START_TIME with the current time modifiedData := strings.ReplaceAll(string(data), "START_TIME", fmt.Sprintf("%d", startTime)) + modifiedData = strings.ReplaceAll(string(data), "INSTANCE_ID", fmt.Sprintf("%d", instanceId)) // Mimic `curl` command - sending HTTP POST request url := "http://127.0.0.1:4316/v1/metrics" @@ -267,8 +268,8 @@ func SendAppSignalMetrics(duration time.Duration, instanceId string) error { startTime := time.Now().UnixNano() // Process files with dynamic paths - processFile(filepath.Join(baseDir, "server_consumer.json"), startTime) - processFile(filepath.Join(baseDir, "client_producer.json"), startTime) + processFile(filepath.Join(baseDir, "server_consumer.json"), startTime, instanceId) + processFile(filepath.Join(baseDir, "client_producer.json"), startTime, instanceId) // Sleep for 5 seconds time.Sleep(5 * time.Second) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 973746358..795bd0273 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -100,6 +100,10 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Name: aws.String("Service"), Value: aws.String(serviceValue), }, + { + Name: aws.String("InstanceId"), + Value: aws.String(ec2InstanceId), + }, } //quick testing method for app signals if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { From 1c32d679be5e0cace7b33cc55a090efa3d3c1cd9 Mon Sep 17 00:00:00 2001 From: siprmp Date: Sat, 6 Apr 2024 19:51:26 -0400 Subject: [PATCH 048/108] the last commit did not work, but having a better way to verify metrics --- .../resources/metrics/client_producer.json | 218 +----------------- .../resources/metrics/server_consumer.json | 34 +-- util/common/metrics.go | 11 +- validator/validators/basic/basic_validator.go | 13 +- 4 files changed, 14 insertions(+), 262 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 8e8473ac8..fa7af8bf5 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -1,217 +1 @@ -{ - "resourceMetrics": [ - { - "resource": { - "attributes": [ - { - "key": "k8s.namespace.name", - "value": { - "stringValue": "default" - } - }, - { - "key": "k8s.pod.name", - "value": { - "stringValue": "pod-name" - } - }, - { - "key": "aws.deployment.name", - "value": { - "stringValue": "deployment-name" - } - }, - { - "key": "host.id", - "value": { - "stringValue": "i-00000000000000000" - } - } - ] - }, - "scopeMetrics": [ - { - "metrics": [ - { - "name": "Error", - "unit": "Milliseconds", - "sum": { - "dataPoints": [ - { - "attributes": [ - { - "key": "aws.span.kind", - "value": { - "stringValue": "CLIENT" - } - }, - { - "key": "aws.local.operation", - "value": { - "stringValue": "operation" - } - }, - { - "key": "aws.local.service", - "value": { - "stringValue": "service-name" - } - }, - { - "key": "aws.remote.operation", - "value": { - "stringValue": "remote-operation" - } - }, - { - "key": "aws.remote.service", - "value": { - "stringValue": "service-name-remote" - } - }, - { - "key": "aws.remote.target", - "value": { - "stringValue": "remote-target" - } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } - } - ], - "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME, - "sum": 0, - "min": 0, - "max": 0 - } - ] - } - }, - { - "name": "Fault", - "unit": "Milliseconds", - "sum": { - "dataPoints": [ - { - "attributes": [ - { - "key": "aws.span.kind", - "value": { - "stringValue": "CLIENT" - } - }, - { - "key": "aws.local.operation", - "value": { - "stringValue": "operation" - } - }, - { - "key": "aws.local.service", - "value": { - "stringValue": "service-name" - } - }, - { - "key": "aws.remote.operation", - "value": { - "stringValue": "remote-operation" - } - }, - { - "key": "aws.remote.service", - "value": { - "stringValue": "service-name-remote" - } - }, - { - "key": "aws.remote.target", - "value": { - "stringValue": "remote-target" - } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } - } - ], - "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME, - "sum": 0, - "min": 0, - "max": 0 - } - ] - } - }, - { - "name": "Latency", - "unit": "Milliseconds", - "sum": { - "dataPoints": [ - { - "attributes": [ - { - "key": "aws.span.kind", - "value": { - "stringValue": "CLIENT" - } - }, - { - "key": "aws.local.operation", - "value": { - "stringValue": "operation" - } - }, - { - "key": "aws.local.service", - "value": { - "stringValue": "service-name" - } - }, - { - "key": "aws.remote.operation", - "value": { - "stringValue": "remote-operation" - } - }, - { - "key": "aws.remote.service", - "value": { - "stringValue": "service-name-remote" - } - }, - { - "key": "aws.remote.target", - "value": { - "stringValue": "remote-target" - } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } - } - ], - "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME, - "sum": 1, - "min": 1, - "max": 1 - } - ] - } - } - ] - } - ] - } - ] -} +z \ No newline at end of file diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index 8fbb1de35..eee7da3f6 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -1,4 +1,3 @@ -//server_consumer with instance id { "resourceMetrics": [ { @@ -81,12 +80,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], "startTimeUnixNano": START_TIME, @@ -146,12 +139,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], "startTimeUnixNano": START_TIME, @@ -211,12 +198,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], "startTimeUnixNano": START_TIME, @@ -276,15 +257,8 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], - "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, "sum": 1, @@ -342,12 +316,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": INSTANCE_ID - } } ], "startTimeUnixNano": START_TIME, @@ -364,4 +332,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/util/common/metrics.go b/util/common/metrics.go index ae53b8bdc..ab45587a2 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -39,7 +39,7 @@ func StartSendingMetrics(receiver string, duration, sendingInterval time.Duratio case "emf": err = SendEMFMetrics(metricPerInterval, metricLogGroup, metricNamespace, sendingInterval, duration) case "app_signals": - err = SendAppSignalMetrics(duration, metricLogGroup) //does app signals have dimension for metric? + err = SendAppSignalMetrics(duration) //does app signals have dimension for metric? case "traces": err = SendAppTraceMetrics(duration) //does app signals have dimension for metric? @@ -199,7 +199,7 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } } -func processFile(filePath string, startTime int64, instanceId string) { +func processFile(filePath string, startTime int64) { data, err := os.ReadFile(filePath) // Using os.ReadFile here if err != nil { fmt.Println("Error reading file:", err) @@ -208,7 +208,6 @@ func processFile(filePath string, startTime int64, instanceId string) { // Replace START_TIME with the current time modifiedData := strings.ReplaceAll(string(data), "START_TIME", fmt.Sprintf("%d", startTime)) - modifiedData = strings.ReplaceAll(string(data), "INSTANCE_ID", fmt.Sprintf("%d", instanceId)) // Mimic `curl` command - sending HTTP POST request url := "http://127.0.0.1:4316/v1/metrics" @@ -238,7 +237,7 @@ func updateLastSendTime() error { now := time.Now().Format(time.RFC3339) return os.WriteFile(LastSendTimeFile, []byte(now), 0644) } -func SendAppSignalMetrics(duration time.Duration, instanceId string) error { +func SendAppSignalMetrics(duration time.Duration) error { // The bash script to be executed asynchronously. dir, err := os.Getwd() if err != nil { @@ -268,8 +267,8 @@ func SendAppSignalMetrics(duration time.Duration, instanceId string) error { startTime := time.Now().UnixNano() // Process files with dynamic paths - processFile(filepath.Join(baseDir, "server_consumer.json"), startTime, instanceId) - processFile(filepath.Join(baseDir, "client_producer.json"), startTime, instanceId) + processFile(filepath.Join(baseDir, "server_consumer.json"), startTime) + processFile(filepath.Join(baseDir, "client_producer.json"), startTime) // Sleep for 5 seconds time.Sleep(5 * time.Second) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 795bd0273..c92e9357a 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -10,6 +10,7 @@ import ( "strings" "time" + apMetrics "github.com/aws/amazon-cloudwatch-agent-test/test/metric" cwtypes "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types" cwltypes "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types" "github.com/aws/aws-sdk-go/aws" @@ -100,16 +101,16 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Name: aws.String("Service"), Value: aws.String(serviceValue), }, - { - Name: aws.String("InstanceId"), - Value: aws.String(ec2InstanceId), - }, } //quick testing method for app signals if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { - err := s.ValidateMetric(metric.MetricName, "AppSignals", appSignalDimensions, metric.MetricValue, metric.MetricSampleCount, startTime, endTime) + fetcher := apMetrics.MetricValueFetcher{} + values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "sum", 60) if err != nil { - multiErr = multierr.Append(multiErr, err) + fmt.Printf("error getting fetching app signals metrics %v", err) + } + if !apMetrics.IsAllValuesGreaterThanOrEqualToExpectedValue(metric.MetricName, values, 0) { + fmt.Printf("error value not the epected values%v", err) } } else { err := s.ValidateMetric(metric.MetricName, metricNamespace, metricDimensions, metric.MetricValue, metric.MetricSampleCount, startTime, endTime) From 0cfa7e0270023df53d60959f1f209e04aa4929b1 Mon Sep 17 00:00:00 2001 From: siprmp Date: Sat, 6 Apr 2024 19:53:20 -0400 Subject: [PATCH 049/108] accidently removed all of client_producer --- .../resources/metrics/client_producer.json | 200 +++++++++++++++++- 1 file changed, 199 insertions(+), 1 deletion(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index fa7af8bf5..61cb1c812 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -1 +1,199 @@ -z \ No newline at end of file +{ + "resourceMetrics": [ + { + "resource": { + "attributes": [ + { + "key": "k8s.namespace.name", + "value": { + "stringValue": "default" + } + }, + { + "key": "k8s.pod.name", + "value": { + "stringValue": "pod-name" + } + }, + { + "key": "aws.deployment.name", + "value": { + "stringValue": "deployment-name" + } + }, + { + "key": "host.id", + "value": { + "stringValue": "i-00000000000000000" + } + } + ] + }, + "scopeMetrics": [ + { + "metrics": [ + { + "name": "Error", + "unit": "Milliseconds", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "aws.span.kind", + "value": { + "stringValue": "CLIENT" + } + }, + { + "key": "aws.local.operation", + "value": { + "stringValue": "operation" + } + }, + { + "key": "aws.local.service", + "value": { + "stringValue": "service-name" + } + }, + { + "key": "aws.remote.operation", + "value": { + "stringValue": "remote-operation" + } + }, + { + "key": "aws.remote.service", + "value": { + "stringValue": "service-name-remote" + } + }, + { + "key": "aws.remote.target", + "value": { + "stringValue": "remote-target" + } + } + ], + "startTimeUnixNano": START_TIME, + "timeUnixNano": START_TIME, + "sum": 0, + "min": 0, + "max": 0 + } + ] + } + }, + { + "name": "Fault", + "unit": "Milliseconds", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "aws.span.kind", + "value": { + "stringValue": "CLIENT" + } + }, + { + "key": "aws.local.operation", + "value": { + "stringValue": "operation" + } + }, + { + "key": "aws.local.service", + "value": { + "stringValue": "service-name" + } + }, + { + "key": "aws.remote.operation", + "value": { + "stringValue": "remote-operation" + } + }, + { + "key": "aws.remote.service", + "value": { + "stringValue": "service-name-remote" + } + }, + { + "key": "aws.remote.target", + "value": { + "stringValue": "remote-target" + } + } + ], + "startTimeUnixNano": START_TIME, + "timeUnixNano": START_TIME, + "sum": 0, + "min": 0, + "max": 0 + } + ] + } + }, + { + "name": "Latency", + "unit": "Milliseconds", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "aws.span.kind", + "value": { + "stringValue": "CLIENT" + } + }, + { + "key": "aws.local.operation", + "value": { + "stringValue": "operation" + } + }, + { + "key": "aws.local.service", + "value": { + "stringValue": "service-name" + } + }, + { + "key": "aws.remote.operation", + "value": { + "stringValue": "remote-operation" + } + }, + { + "key": "aws.remote.service", + "value": { + "stringValue": "service-name-remote" + } + }, + { + "key": "aws.remote.target", + "value": { + "stringValue": "remote-target" + } + } + ], + "startTimeUnixNano": START_TIME, + "timeUnixNano": START_TIME, + "sum": 1, + "min": 1, + "max": 1 + } + ] + } + } + ] + } + ] + } + ] +} \ No newline at end of file From 3f5a75d0f64770e1cadaa2fa9744a4229616ba46 Mon Sep 17 00:00:00 2001 From: siprmp Date: Sat, 6 Apr 2024 20:06:11 -0400 Subject: [PATCH 050/108] Everything works --- validator/validators/basic/basic_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index c92e9357a..92b47a6d8 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -102,7 +102,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Value: aws.String(serviceValue), }, } - //quick testing method for app signals + //App Signals metric testing (This is because we want to use a different checking method (same that was done for linux test) if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { fetcher := apMetrics.MetricValueFetcher{} values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "sum", 60) From c3ec34a1ca7e99ac51582560dda4f25e1360eaf6 Mon Sep 17 00:00:00 2001 From: siprmp Date: Sat, 6 Apr 2024 22:35:17 -0400 Subject: [PATCH 051/108] agent config is wrong --- test/feature/mac/agent_config.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/feature/mac/agent_config.json b/test/feature/mac/agent_config.json index df3d39d57..90aca38cc 100644 --- a/test/feature/mac/agent_config.json +++ b/test/feature/mac/agent_config.json @@ -4,9 +4,6 @@ }, "traces": { "traces_collected": { - "append_dimensions": { - "InstanceId": "${aws:InstanceId}" - }, "app_signals": {} } }, @@ -104,9 +101,6 @@ } }, "metrics_collected": { - "append_dimensions": { - "InstanceId": "${aws:InstanceId}" - }, "app_signals": {}, "emf": { } }, From 02a4e79ea0ac39387526e00d92ec017a90176762 Mon Sep 17 00:00:00 2001 From: siprmp Date: Fri, 12 Apr 2024 17:01:27 -0400 Subject: [PATCH 052/108] This works really well with deployment just need to add the others (its pretty fast) --- .../resources/metrics/client_producer.json | 21 +++++++++++- .../resources/metrics/server_consumer.json | 34 ++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 61cb1c812..0d70f8bd9 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -1,3 +1,4 @@ +//client { "resourceMetrics": [ { @@ -74,6 +75,12 @@ "value": { "stringValue": "remote-target" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "INSTANCE_ID" + } } ], "startTimeUnixNano": START_TIME, @@ -127,6 +134,12 @@ "value": { "stringValue": "remote-target" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "INSTANCE_ID" + } } ], "startTimeUnixNano": START_TIME, @@ -180,6 +193,12 @@ "value": { "stringValue": "remote-target" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "INSTANCE_ID" + } } ], "startTimeUnixNano": START_TIME, @@ -196,4 +215,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index eee7da3f6..0c45c21b4 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -1,3 +1,4 @@ +//server { "resourceMetrics": [ { @@ -80,6 +81,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "INSTANCE_ID" + } } ], "startTimeUnixNano": START_TIME, @@ -139,6 +146,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "INSTANCE_ID" + } } ], "startTimeUnixNano": START_TIME, @@ -198,6 +211,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "INSTANCE_ID" + } } ], "startTimeUnixNano": START_TIME, @@ -257,8 +276,15 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "INSTANCE_ID" + } } ], + "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, "sum": 1, @@ -316,6 +342,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "INSTANCE_ID" + } } ], "startTimeUnixNano": START_TIME, @@ -332,4 +364,4 @@ ] } ] -} \ No newline at end of file +} From a6bf09d87229965d25ca0a60c986fd7b101a3fe1 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Thu, 18 Apr 2024 17:49:24 -0400 Subject: [PATCH 053/108] pushing changes --- test/app_signals/agent_configs/config.json | 3 +++ .../app_signals/resources/metrics/client_producer.json | 6 +++--- .../app_signals/resources/metrics/server_consumer.json | 10 +++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/test/app_signals/agent_configs/config.json b/test/app_signals/agent_configs/config.json index 2a275eb83..2c843d371 100644 --- a/test/app_signals/agent_configs/config.json +++ b/test/app_signals/agent_configs/config.json @@ -4,6 +4,9 @@ }, "logs": { "metrics_collected": { + "append_dimensions": { + "InstanceId": "${aws:InstanceId}" + }, "app_signals": { "rules":[ { diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index d8557cb76..c127781e2 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -78,7 +78,7 @@ { "key": "InstanceId", "value": { - "stringValue": "INSTANCE_ID" + "stringValue": "i-08a2324055c43ab65" } } ], @@ -137,7 +137,7 @@ { "key": "InstanceId", "value": { - "stringValue": "INSTANCE_ID" + "stringValue": "i-08a2324055c43ab65" } } ], @@ -196,7 +196,7 @@ { "key": "InstanceId", "value": { - "stringValue": "INSTANCE_ID" + "stringValue": "i-08a2324055c43ab65" } } ], diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index d83df571b..5b035df5d 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -84,7 +84,7 @@ { "key": "InstanceId", "value": { - "stringValue": "INSTANCE_ID" + "stringValue": "i-08a2324055c43ab65" } } ], @@ -149,7 +149,7 @@ { "key": "InstanceId", "value": { - "stringValue": "INSTANCE_ID" + "stringValue": "i-08a2324055c43ab65" } } ], @@ -214,7 +214,7 @@ { "key": "InstanceId", "value": { - "stringValue": "INSTANCE_ID" + "stringValue": "i-08a2324055c43ab65" } } ], @@ -279,7 +279,7 @@ { "key": "InstanceId", "value": { - "stringValue": "INSTANCE_ID" + "stringValue": "i-08a2324055c43ab65" } } ], @@ -345,7 +345,7 @@ { "key": "InstanceId", "value": { - "stringValue": "INSTANCE_ID" + "stringValue": "i-08a2324055c43ab65" } } ], From 47ad0e32c8ed062c5b5be31ba09985332c8af771 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Thu, 18 Apr 2024 17:56:15 -0400 Subject: [PATCH 054/108] xray filter --- validator/validators/basic/basic_validator.go | 1 + 1 file changed, 1 insertion(+) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 92b47a6d8..a1e9dbc31 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -127,6 +127,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { "aws_remote_service": "service-name-remote", "aws_local_operation": "replaced-operation", } + annotations["HostedIn_Environment"] = "Generic" xrayFilter := awsservice.FilterExpression(annotations) traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, xrayFilter) if err != nil { From bf973b382aecc370d1e165d974ac2363e1299c2d Mon Sep 17 00:00:00 2001 From: Paramadon Date: Thu, 18 Apr 2024 17:58:54 -0400 Subject: [PATCH 055/108] xray filter --- validator/main.go | 2 +- validator/validators/validator.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/validator/main.go b/validator/main.go index bae8bdc92..428007df1 100644 --- a/validator/main.go +++ b/validator/main.go @@ -87,7 +87,7 @@ func validate(vConfig models.ValidateConfig) error { log.Printf("Test case: %s, validate type: %s has been successfully validated", vConfig.GetTestCase(), vConfig.GetValidateType()) return nil } - time.Sleep(60 * time.Second) + time.Sleep(20 * time.Second) log.Printf("test case: %s, validate type: %s, error: %v", vConfig.GetTestCase(), vConfig.GetValidateType(), err) continue } diff --git a/validator/validators/validator.go b/validator/validators/validator.go index e137c6b64..87dd3ffd5 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -53,7 +53,7 @@ func LaunchValidator(vConfig models.ValidateConfig) error { time.Sleep(agentCollectionPeriod) log.Printf("Start to sleep 120s for CloudWatch to process all the metrics") - time.Sleep(2 * time.Minute) + time.Sleep(20 * time.Second) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From 9362a974799463dcb53ccac5ec0b4140a7fe76b5 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Thu, 18 Apr 2024 18:35:12 -0400 Subject: [PATCH 056/108] fixing test --- validator/main.go | 2 +- validator/validators/validator.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/validator/main.go b/validator/main.go index 428007df1..bae8bdc92 100644 --- a/validator/main.go +++ b/validator/main.go @@ -87,7 +87,7 @@ func validate(vConfig models.ValidateConfig) error { log.Printf("Test case: %s, validate type: %s has been successfully validated", vConfig.GetTestCase(), vConfig.GetValidateType()) return nil } - time.Sleep(20 * time.Second) + time.Sleep(60 * time.Second) log.Printf("test case: %s, validate type: %s, error: %v", vConfig.GetTestCase(), vConfig.GetValidateType(), err) continue } diff --git a/validator/validators/validator.go b/validator/validators/validator.go index 87dd3ffd5..e137c6b64 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -53,7 +53,7 @@ func LaunchValidator(vConfig models.ValidateConfig) error { time.Sleep(agentCollectionPeriod) log.Printf("Start to sleep 120s for CloudWatch to process all the metrics") - time.Sleep(20 * time.Second) + time.Sleep(2 * time.Minute) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From e3952af13358bca8aced31040dbab68df69c8a37 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Thu, 18 Apr 2024 18:49:17 -0400 Subject: [PATCH 057/108] getting trace Ids --- validator/validators/basic/basic_validator.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index a1e9dbc31..e800b2e2c 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -120,16 +120,8 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { } lookbackDuration := time.Duration(-5) * time.Minute timeNow := time.Now() - var annotations = map[string]interface{}{ - "aws_remote_target": "remote-target", - "aws_remote_operation": "remote-operation", - "aws_local_service": "service-name", - "aws_remote_service": "service-name-remote", - "aws_local_operation": "replaced-operation", - } - annotations["HostedIn_Environment"] = "Generic" - xrayFilter := awsservice.FilterExpression(annotations) - traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, xrayFilter) + + traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, "") if err != nil { fmt.Printf("error getting trace ids: %v", err) multiErr = multierr.Append(multiErr, err) From b0fd08a9600485f13699fd5025730973ccd09079 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Thu, 18 Apr 2024 19:01:25 -0400 Subject: [PATCH 058/108] changing timing --- validator/main.go | 2 +- validator/validators/validator.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/validator/main.go b/validator/main.go index bae8bdc92..66aa061d0 100644 --- a/validator/main.go +++ b/validator/main.go @@ -87,7 +87,7 @@ func validate(vConfig models.ValidateConfig) error { log.Printf("Test case: %s, validate type: %s has been successfully validated", vConfig.GetTestCase(), vConfig.GetValidateType()) return nil } - time.Sleep(60 * time.Second) + time.Sleep(10 * time.Second) log.Printf("test case: %s, validate type: %s, error: %v", vConfig.GetTestCase(), vConfig.GetValidateType(), err) continue } diff --git a/validator/validators/validator.go b/validator/validators/validator.go index e137c6b64..87dd3ffd5 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -53,7 +53,7 @@ func LaunchValidator(vConfig models.ValidateConfig) error { time.Sleep(agentCollectionPeriod) log.Printf("Start to sleep 120s for CloudWatch to process all the metrics") - time.Sleep(2 * time.Minute) + time.Sleep(20 * time.Second) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From 5376d22d910eeaf71cc37bb51f3d48f4d54820dc Mon Sep 17 00:00:00 2001 From: Paramadon Date: Thu, 18 Apr 2024 19:09:27 -0400 Subject: [PATCH 059/108] adding a xray filter --- validator/validators/basic/basic_validator.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index e800b2e2c..a1e9dbc31 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -120,8 +120,16 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { } lookbackDuration := time.Duration(-5) * time.Minute timeNow := time.Now() - - traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, "") + var annotations = map[string]interface{}{ + "aws_remote_target": "remote-target", + "aws_remote_operation": "remote-operation", + "aws_local_service": "service-name", + "aws_remote_service": "service-name-remote", + "aws_local_operation": "replaced-operation", + } + annotations["HostedIn_Environment"] = "Generic" + xrayFilter := awsservice.FilterExpression(annotations) + traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, xrayFilter) if err != nil { fmt.Printf("error getting trace ids: %v", err) multiErr = multierr.Append(multiErr, err) From 456fdde2598bcc5121a374c2ea643b4b1fdde297 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Thu, 18 Apr 2024 19:15:36 -0400 Subject: [PATCH 060/108] changing type of stat --- validator/validators/basic/basic_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index a1e9dbc31..0875e3053 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -105,7 +105,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { //App Signals metric testing (This is because we want to use a different checking method (same that was done for linux test) if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { fetcher := apMetrics.MetricValueFetcher{} - values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "sum", 60) + values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "exponential_histogram", 60) if err != nil { fmt.Printf("error getting fetching app signals metrics %v", err) } From b46bdbf384f7db1db9f9d09ab39ec86ea80bcf0c Mon Sep 17 00:00:00 2001 From: Paramadon Date: Thu, 18 Apr 2024 19:20:57 -0400 Subject: [PATCH 061/108] changing type of stat --- .../resources/metrics/client_producer.json | 18 ----------- .../resources/metrics/server_consumer.json | 30 ------------------- 2 files changed, 48 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index c127781e2..42827ff4d 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -74,12 +74,6 @@ "value": { "stringValue": "remote-target" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, @@ -133,12 +127,6 @@ "value": { "stringValue": "remote-target" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, @@ -192,12 +180,6 @@ "value": { "stringValue": "remote-target" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index 5b035df5d..6044abe1f 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -80,12 +80,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, @@ -145,12 +139,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, @@ -210,12 +198,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, @@ -275,12 +257,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], @@ -341,12 +317,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, From 3b3ab21c7a6e7da296d49054c48f73392ff30d56 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Thu, 18 Apr 2024 19:27:11 -0400 Subject: [PATCH 062/108] changing type of stat --- validator/validators/basic/basic_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 0875e3053..a1e9dbc31 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -105,7 +105,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { //App Signals metric testing (This is because we want to use a different checking method (same that was done for linux test) if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { fetcher := apMetrics.MetricValueFetcher{} - values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "exponential_histogram", 60) + values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "sum", 60) if err != nil { fmt.Printf("error getting fetching app signals metrics %v", err) } From b56af7973e1569150cd3e08ae4f669b517a04ad4 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 09:42:25 -0400 Subject: [PATCH 063/108] commenting out traces --- validator/validators/basic/basic_validator.go | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index a1e9dbc31..223db23b6 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -118,29 +118,29 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { multiErr = multierr.Append(multiErr, err) } } - lookbackDuration := time.Duration(-5) * time.Minute - timeNow := time.Now() - var annotations = map[string]interface{}{ - "aws_remote_target": "remote-target", - "aws_remote_operation": "remote-operation", - "aws_local_service": "service-name", - "aws_remote_service": "service-name-remote", - "aws_local_operation": "replaced-operation", - } - annotations["HostedIn_Environment"] = "Generic" - xrayFilter := awsservice.FilterExpression(annotations) - traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, xrayFilter) - if err != nil { - fmt.Printf("error getting trace ids: %v", err) - multiErr = multierr.Append(multiErr, err) - } else { - fmt.Printf("Trace IDs: %v\n", traceIds) - if len(traceIds) > 0 { - fmt.Println("Trace IDs look good") - } - } - + //lookbackDuration := time.Duration(-5) * time.Minute + //timeNow := time.Now() + //var annotations = map[string]interface{}{ + // "aws_remote_target": "remote-target", + // "aws_remote_operation": "remote-operation", + // "aws_local_service": "service-name", + // "aws_remote_service": "service-name-remote", + // "aws_local_operation": "replaced-operation", + //} + //annotations["HostedIn_Environment"] = "Generic" + //xrayFilter := awsservice.FilterExpression(annotations) + //traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, xrayFilter) + //if err != nil { + // fmt.Printf("error getting trace ids: %v", err) + // multiErr = multierr.Append(multiErr, err) + //} else { + // fmt.Printf("Trace IDs: %v\n", traceIds) + // if len(traceIds) > 0 { + // fmt.Println("Trace IDs look good") + // } } + + //} for _, logValidation := range logValidations { err := s.ValidateLogs(logValidation.LogStream, logValidation.LogValue, logValidation.LogLevel, logValidation.LogSource, logValidation.LogLines, startTime, endTime) if err != nil { From 533de0f16ba50ab3433b212f76eb7ef75d625157 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 10:16:29 -0400 Subject: [PATCH 064/108] sample count --- validator/validators/basic/basic_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 223db23b6..a095ea578 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -105,7 +105,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { //App Signals metric testing (This is because we want to use a different checking method (same that was done for linux test) if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { fetcher := apMetrics.MetricValueFetcher{} - values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "sum", 60) + values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "SampleCount", 60) if err != nil { fmt.Printf("error getting fetching app signals metrics %v", err) } From 68c8d3a2ab81f133d20eb293b12e872c1e1feb51 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 10:54:35 -0400 Subject: [PATCH 065/108] testing something --- .../resources/metrics/client_producer.json | 18 +++++++++++ .../resources/metrics/server_consumer.json | 30 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 42827ff4d..c127781e2 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -74,6 +74,12 @@ "value": { "stringValue": "remote-target" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "i-08a2324055c43ab65" + } } ], "startTimeUnixNano": START_TIME, @@ -127,6 +133,12 @@ "value": { "stringValue": "remote-target" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "i-08a2324055c43ab65" + } } ], "startTimeUnixNano": START_TIME, @@ -180,6 +192,12 @@ "value": { "stringValue": "remote-target" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "i-08a2324055c43ab65" + } } ], "startTimeUnixNano": START_TIME, diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index 6044abe1f..5b035df5d 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -80,6 +80,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "i-08a2324055c43ab65" + } } ], "startTimeUnixNano": START_TIME, @@ -139,6 +145,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "i-08a2324055c43ab65" + } } ], "startTimeUnixNano": START_TIME, @@ -198,6 +210,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "i-08a2324055c43ab65" + } } ], "startTimeUnixNano": START_TIME, @@ -257,6 +275,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "i-08a2324055c43ab65" + } } ], @@ -317,6 +341,12 @@ "value": { "stringValue": "sample-app" } + }, + { + "key": "InstanceId", + "value": { + "stringValue": "i-08a2324055c43ab65" + } } ], "startTimeUnixNano": START_TIME, From 6f31361fc390054de8f445ca90b7e549e938900c Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 11:12:16 -0400 Subject: [PATCH 066/108] change exponential histogram to sum to see if metrics show up --- test/app_signals/agent_configs/config.json | 3 -- .../resources/metrics/client_producer.json | 24 ++--------- .../resources/metrics/server_consumer.json | 40 +++---------------- 3 files changed, 8 insertions(+), 59 deletions(-) diff --git a/test/app_signals/agent_configs/config.json b/test/app_signals/agent_configs/config.json index 2c843d371..2a275eb83 100644 --- a/test/app_signals/agent_configs/config.json +++ b/test/app_signals/agent_configs/config.json @@ -4,9 +4,6 @@ }, "logs": { "metrics_collected": { - "append_dimensions": { - "InstanceId": "${aws:InstanceId}" - }, "app_signals": { "rules":[ { diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index c127781e2..eaa4ce841 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -35,7 +35,7 @@ { "name": "Error", "unit": "", - "exponential_histogram": { + "sum": { "dataPoints": [ { "attributes": [ @@ -74,12 +74,6 @@ "value": { "stringValue": "remote-target" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, @@ -94,7 +88,7 @@ { "name": "Fault", "unit": "", - "exponential_histogram": { + "sum": { "dataPoints": [ { "attributes": [ @@ -133,12 +127,6 @@ "value": { "stringValue": "remote-target" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, @@ -153,7 +141,7 @@ { "name": "Latency", "unit": "Milliseconds", - "exponential_histogram": { + "sum": { "dataPoints": [ { "attributes": [ @@ -192,12 +180,6 @@ "value": { "stringValue": "remote-target" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index 5b035df5d..5241e5a34 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -35,7 +35,7 @@ { "name": "Error", "unit": "", - "exponential_histogram": { + "sum": { "dataPoints": [ { "attributes": [ @@ -80,12 +80,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, @@ -100,7 +94,7 @@ { "name": "Fault", "unit": "", - "exponential_histogram": { + "sum": { "dataPoints": [ { "attributes": [ @@ -145,12 +139,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, @@ -165,7 +153,7 @@ { "name": "Latency", "unit": "Milliseconds", - "exponential_histogram": { + "sum": { "dataPoints": [ { "attributes": [ @@ -210,12 +198,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, @@ -230,7 +212,7 @@ { "name": "Latency", "unit": "Milliseconds", - "exponential_histogram": { + "sum": { "dataPoints": [ { "attributes": [ @@ -275,12 +257,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], @@ -296,7 +272,7 @@ { "name": "Latency", "unit": "Milliseconds", - "exponential_histogram": { + "sum": { "dataPoints": [ { "attributes": [ @@ -341,12 +317,6 @@ "value": { "stringValue": "sample-app" } - }, - { - "key": "InstanceId", - "value": { - "stringValue": "i-08a2324055c43ab65" - } } ], "startTimeUnixNano": START_TIME, From 24e26b5348d4cc29861694ba1fa3277e525263fa Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 11:25:14 -0400 Subject: [PATCH 067/108] changing back to expHist, sum generates metric but not sure why expHist does not (its in logs tho) --- test/app_signals/agent_configs/config.json | 45 +------------------ .../resources/metrics/client_producer.json | 6 +-- .../resources/metrics/server_consumer.json | 10 ++--- 3 files changed, 9 insertions(+), 52 deletions(-) diff --git a/test/app_signals/agent_configs/config.json b/test/app_signals/agent_configs/config.json index 2a275eb83..9c03d5915 100644 --- a/test/app_signals/agent_configs/config.json +++ b/test/app_signals/agent_configs/config.json @@ -4,50 +4,7 @@ }, "logs": { "metrics_collected": { - "app_signals": { - "rules":[ - { - "selectors":[ - { - "dimension":"Operation", - "match":"operation" - } - ], - "action":"keep", - "rule_name":"keep01" - }, - { - "selectors":[ - { - "dimension":"Service", - "match":"drop-service-name*" - } - ], - "action":"drop", - "rule_name":"drop01" - }, - { - "selectors":[ - { - "dimension":"Operation", - "match":"operation" - }, - { - "dimension":"Service", - "match":"service-name" - } - ], - "replacements":[ - { - "target_dimension":"Operation", - "value":"replaced-operation" - } - ], - "action":"replace", - "rule_name":"replace01" - } - ] - } + "app_signals": {} } }, "traces": { diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index eaa4ce841..42827ff4d 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -35,7 +35,7 @@ { "name": "Error", "unit": "", - "sum": { + "exponential_histogram": { "dataPoints": [ { "attributes": [ @@ -88,7 +88,7 @@ { "name": "Fault", "unit": "", - "sum": { + "exponential_histogram": { "dataPoints": [ { "attributes": [ @@ -141,7 +141,7 @@ { "name": "Latency", "unit": "Milliseconds", - "sum": { + "exponential_histogram": { "dataPoints": [ { "attributes": [ diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index 5241e5a34..6044abe1f 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -35,7 +35,7 @@ { "name": "Error", "unit": "", - "sum": { + "exponential_histogram": { "dataPoints": [ { "attributes": [ @@ -94,7 +94,7 @@ { "name": "Fault", "unit": "", - "sum": { + "exponential_histogram": { "dataPoints": [ { "attributes": [ @@ -153,7 +153,7 @@ { "name": "Latency", "unit": "Milliseconds", - "sum": { + "exponential_histogram": { "dataPoints": [ { "attributes": [ @@ -212,7 +212,7 @@ { "name": "Latency", "unit": "Milliseconds", - "sum": { + "exponential_histogram": { "dataPoints": [ { "attributes": [ @@ -272,7 +272,7 @@ { "name": "Latency", "unit": "Milliseconds", - "sum": { + "exponential_histogram": { "dataPoints": [ { "attributes": [ From 3031cb4e8645523af27fdcb4c03c9739b41a286e Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 11:45:33 -0400 Subject: [PATCH 068/108] changing how sum, min,max are --- .../resources/metrics/client_producer.json | 18 +++++------ .../resources/metrics/server_consumer.json | 30 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 42827ff4d..6204ec535 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -78,9 +78,9 @@ ], "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, - "sum": 0, - "min": 0, - "max": 0 + "sum_": 0, + "min_": 0, + "max_": 0 } ] } @@ -131,9 +131,9 @@ ], "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, - "sum": 0, - "min": 0, - "max": 0 + "sum_": 0, + "min_": 0, + "max_": 0 } ] } @@ -184,9 +184,9 @@ ], "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, - "sum": 1, - "min": 1, - "max": 1 + "sum_": 1, + "min_": 1, + "max_": 1 } ] } diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index 6044abe1f..ec2ae82db 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -84,9 +84,9 @@ ], "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, - "sum": 0, - "min": 0, - "max": 0 + "sum_": 0, + "min_": 0, + "max_": 0 } ] } @@ -143,9 +143,9 @@ ], "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, - "sum": 0, - "min": 0, - "max": 0 + "sum_": 0, + "min_": 0, + "max_": 0 } ] } @@ -202,9 +202,9 @@ ], "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, - "sum": 1, - "min": 1, - "max": 1 + "sum_": 1, + "min_": 1, + "max_": 1 } ] } @@ -262,9 +262,9 @@ "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, - "sum": 1, - "min": 1, - "max": 1 + "sum_": 1, + "min_": 1, + "max_": 1 } ] } @@ -321,9 +321,9 @@ ], "startTimeUnixNano": START_TIME, "timeUnixNano": START_TIME, - "sum": 1, - "min": 1, - "max": 1 + "sum_": 1, + "min_": 1, + "max_": 1 } ] } From 9b9b1323dac0191dfeed6483d32933175d079b84 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 11:48:17 -0400 Subject: [PATCH 069/108] removing sum,max,min to see if metrics come --- .../resources/metrics/client_producer.json | 15 +++------------ .../resources/metrics/server_consumer.json | 15 +++------------ 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 6204ec535..14a14ee4b 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -77,10 +77,7 @@ } ], "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME, - "sum_": 0, - "min_": 0, - "max_": 0 + "timeUnixNano": START_TIME } ] } @@ -130,10 +127,7 @@ } ], "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME, - "sum_": 0, - "min_": 0, - "max_": 0 + "timeUnixNano": START_TIME } ] } @@ -183,10 +177,7 @@ } ], "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME, - "sum_": 1, - "min_": 1, - "max_": 1 + "timeUnixNano": START_TIME } ] } diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index ec2ae82db..02f69f579 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -201,10 +201,7 @@ } ], "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME, - "sum_": 1, - "min_": 1, - "max_": 1 + "timeUnixNano": START_TIME } ] } @@ -261,10 +258,7 @@ ], "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME, - "sum_": 1, - "min_": 1, - "max_": 1 + "timeUnixNano": START_TIME } ] } @@ -320,10 +314,7 @@ } ], "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME, - "sum_": 1, - "min_": 1, - "max_": 1 + "timeUnixNano": START_TIME } ] } From 7015d10c817e2d744045920a2b849a7541795635 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 11:53:29 -0400 Subject: [PATCH 070/108] removing everything from exponentatial and seeing if emtrics come --- .../resources/metrics/client_producer.json | 133 +-------- .../resources/metrics/server_consumer.json | 265 +----------------- 2 files changed, 4 insertions(+), 394 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 14a14ee4b..50c45cf31 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -36,150 +36,19 @@ "name": "Error", "unit": "", "exponential_histogram": { - "dataPoints": [ - { - "attributes": [ - { - "key": "aws.span.kind", - "value": { - "stringValue": "CLIENT" - } - }, - { - "key": "aws.local.operation", - "value": { - "stringValue": "operation" - } - }, - { - "key": "aws.local.service", - "value": { - "stringValue": "service-name" - } - }, - { - "key": "aws.remote.operation", - "value": { - "stringValue": "remote-operation" - } - }, - { - "key": "aws.remote.service", - "value": { - "stringValue": "service-name-remote" - } - }, - { - "key": "aws.remote.target", - "value": { - "stringValue": "remote-target" - } - } - ], - "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME - } - ] } }, { "name": "Fault", "unit": "", "exponential_histogram": { - "dataPoints": [ - { - "attributes": [ - { - "key": "aws.span.kind", - "value": { - "stringValue": "CLIENT" - } - }, - { - "key": "aws.local.operation", - "value": { - "stringValue": "operation" - } - }, - { - "key": "aws.local.service", - "value": { - "stringValue": "service-name" - } - }, - { - "key": "aws.remote.operation", - "value": { - "stringValue": "remote-operation" - } - }, - { - "key": "aws.remote.service", - "value": { - "stringValue": "service-name-remote" - } - }, - { - "key": "aws.remote.target", - "value": { - "stringValue": "remote-target" - } - } - ], - "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME - } - ] } }, { "name": "Latency", "unit": "Milliseconds", "exponential_histogram": { - "dataPoints": [ - { - "attributes": [ - { - "key": "aws.span.kind", - "value": { - "stringValue": "CLIENT" - } - }, - { - "key": "aws.local.operation", - "value": { - "stringValue": "operation" - } - }, - { - "key": "aws.local.service", - "value": { - "stringValue": "service-name" - } - }, - { - "key": "aws.remote.operation", - "value": { - "stringValue": "remote-operation" - } - }, - { - "key": "aws.remote.service", - "value": { - "stringValue": "service-name-remote" - } - }, - { - "key": "aws.remote.target", - "value": { - "stringValue": "remote-target" - } - } - ], - "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME - } - ] + } } ] diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index 02f69f579..b0f611358 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -36,287 +36,28 @@ "name": "Error", "unit": "", "exponential_histogram": { - "dataPoints": [ - { - "attributes": [ - { - "key": "aws.span.kind", - "value": { - "stringValue": "SERVER" - } - }, - { - "key": "Operation", - "value": { - "stringValue": "operation" - } - }, - { - "key": "Service", - "value": { - "stringValue": "service-name" - } - }, - { - "key": "K8s.Namespace", - "value": { - "stringValue": "default" - } - }, - { - "key": "K8s.Pod", - "value": { - "stringValue": "pod-name" - } - }, - { - "key": "K8s.Node", - "value": { - "stringValue": "i-00000000000000000" - } - }, - { - "key": "K8s.Workload", - "value": { - "stringValue": "sample-app" - } - } - ], - "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME, - "sum_": 0, - "min_": 0, - "max_": 0 - } - ] + } }, { "name": "Fault", "unit": "", "exponential_histogram": { - "dataPoints": [ - { - "attributes": [ - { - "key": "aws.span.kind", - "value": { - "stringValue": "SERVER" - } - }, - { - "key": "Operation", - "value": { - "stringValue": "operation" - } - }, - { - "key": "Service", - "value": { - "stringValue": "service-name" - } - }, - { - "key": "K8s.Namespace", - "value": { - "stringValue": "default" - } - }, - { - "key": "K8s.Pod", - "value": { - "stringValue": "pod-name" - } - }, - { - "key": "K8s.Node", - "value": { - "stringValue": "i-00000000000000000" - } - }, - { - "key": "K8s.Workload", - "value": { - "stringValue": "sample-app" - } - } - ], - "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME, - "sum_": 0, - "min_": 0, - "max_": 0 - } - ] - } - }, - { - "name": "Latency", - "unit": "Milliseconds", - "exponential_histogram": { - "dataPoints": [ - { - "attributes": [ - { - "key": "aws.span.kind", - "value": { - "stringValue": "SERVER" - } - }, - { - "key": "Operation", - "value": { - "stringValue": "operation" - } - }, - { - "key": "Service", - "value": { - "stringValue": "service-name" - } - }, - { - "key": "K8s.Namespace", - "value": { - "stringValue": "default" - } - }, - { - "key": "K8s.Pod", - "value": { - "stringValue": "pod-name" - } - }, - { - "key": "K8s.Node", - "value": { - "stringValue": "i-00000000000000000" - } - }, - { - "key": "K8s.Workload", - "value": { - "stringValue": "sample-app" - } - } - ], - "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME - } - ] + } }, { "name": "Latency", "unit": "Milliseconds", "exponential_histogram": { - "dataPoints": [ - { - "attributes": [ - { - "key": "aws.span.kind", - "value": { - "stringValue": "SERVER" - } - }, - { - "key": "Operation", - "value": { - "stringValue": "operation" - } - }, - { - "key": "Service", - "value": { - "stringValue": "drop-service-name-1" - } - }, - { - "key": "K8s.Namespace", - "value": { - "stringValue": "default" - } - }, - { - "key": "K8s.Pod", - "value": { - "stringValue": "pod-name" - } - }, - { - "key": "K8s.Node", - "value": { - "stringValue": "i-00000000000000000" - } - }, - { - "key": "K8s.Workload", - "value": { - "stringValue": "sample-app" - } - } - ], - "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME - } - ] } }, { "name": "Latency", "unit": "Milliseconds", "exponential_histogram": { - "dataPoints": [ - { - "attributes": [ - { - "key": "aws.span.kind", - "value": { - "stringValue": "SERVER" - } - }, - { - "key": "Operation", - "value": { - "stringValue": "do-not-keep-operation-1" - } - }, - { - "key": "Service", - "value": { - "stringValue": "service-name" - } - }, - { - "key": "K8s.Namespace", - "value": { - "stringValue": "default" - } - }, - { - "key": "K8s.Pod", - "value": { - "stringValue": "pod-name" - } - }, - { - "key": "K8s.Node", - "value": { - "stringValue": "i-00000000000000000" - } - }, - { - "key": "K8s.Workload", - "value": { - "stringValue": "sample-app" - } - } - ], - "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME - } - ] + } } ] From a942bbe5190b3682a075c8c7abe7158c558b7fe1 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 12:21:45 -0400 Subject: [PATCH 071/108] tyring to fix json values --- .../resources/metrics/client_producer.json | 166 ++++++++- .../resources/metrics/server_consumer.json | 314 +++++++++++++++++- 2 files changed, 476 insertions(+), 4 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 50c45cf31..949b7d2c9 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -36,19 +36,183 @@ "name": "Error", "unit": "", "exponential_histogram": { + "dataPoints": [ + { + "attributes": [ + { + "key": "aws.span.kind", + "value": { + "stringValue": "CLIENT" + } + }, + { + "key": "aws.local.operation", + "value": { + "stringValue": "operation" + } + }, + { + "key": "aws.local.service", + "value": { + "stringValue": "service-name" + } + }, + { + "key": "aws.remote.operation", + "value": { + "stringValue": "remote-operation" + } + }, + { + "key": "aws.remote.service", + "value": { + "stringValue": "service-name-remote" + } + }, + { + "key": "aws.remote.target", + "value": { + "stringValue": "remote-target" + } + } + ], + "startTimeUnixNano": START_TIME, + "timeUnixNano": START_TIME + "count": 0, + "scale": 0, + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } + } + ] } }, { "name": "Fault", "unit": "", "exponential_histogram": { + "dataPoints": [ + { + "attributes": [ + { + "key": "aws.span.kind", + "value": { + "stringValue": "CLIENT" + } + }, + { + "key": "aws.local.operation", + "value": { + "stringValue": "operation" + } + }, + { + "key": "aws.local.service", + "value": { + "stringValue": "service-name" + } + }, + { + "key": "aws.remote.operation", + "value": { + "stringValue": "remote-operation" + } + }, + { + "key": "aws.remote.service", + "value": { + "stringValue": "service-name-remote" + } + }, + { + "key": "aws.remote.target", + "value": { + "stringValue": "remote-target" + } + } + ], + "startTimeUnixNano": START_TIME, + "timeUnixNano": START_TIME, + "count": 0, + "scale": 0, + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } + } + ] } }, { "name": "Latency", "unit": "Milliseconds", "exponential_histogram": { - + "dataPoints": [ + { + "attributes": [ + { + "key": "aws.span.kind", + "value": { + "stringValue": "CLIENT" + } + }, + { + "key": "aws.local.operation", + "value": { + "stringValue": "operation" + } + }, + { + "key": "aws.local.service", + "value": { + "stringValue": "service-name" + } + }, + { + "key": "aws.remote.operation", + "value": { + "stringValue": "remote-operation" + } + }, + { + "key": "aws.remote.service", + "value": { + "stringValue": "service-name-remote" + } + }, + { + "key": "aws.remote.target", + "value": { + "stringValue": "remote-target" + } + } + ], + "startTimeUnixNano": START_TIME, + "timeUnixNano": START_TIME, + "count": 0, + "scale": 0, + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } + } + ] } } ] diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index b0f611358..cf6c7e247 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -36,28 +36,336 @@ "name": "Error", "unit": "", "exponential_histogram": { - + "dataPoints": [ + { + "attributes": [ + { + "key": "aws.span.kind", + "value": { + "stringValue": "SERVER" + } + }, + { + "key": "Operation", + "value": { + "stringValue": "operation" + } + }, + { + "key": "Service", + "value": { + "stringValue": "service-name" + } + }, + { + "key": "K8s.Namespace", + "value": { + "stringValue": "default" + } + }, + { + "key": "K8s.Pod", + "value": { + "stringValue": "pod-name" + } + }, + { + "key": "K8s.Node", + "value": { + "stringValue": "i-00000000000000000" + } + }, + { + "key": "K8s.Workload", + "value": { + "stringValue": "sample-app" + } + } + ], + "startTimeUnixNano": START_TIME, + "timeUnixNano": START_TIME, + "count": 0, + "scale": 0, + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } + } + ] } }, { "name": "Fault", "unit": "", "exponential_histogram": { - + "dataPoints": [ + { + "attributes": [ + { + "key": "aws.span.kind", + "value": { + "stringValue": "SERVER" + } + }, + { + "key": "Operation", + "value": { + "stringValue": "operation" + } + }, + { + "key": "Service", + "value": { + "stringValue": "service-name" + } + }, + { + "key": "K8s.Namespace", + "value": { + "stringValue": "default" + } + }, + { + "key": "K8s.Pod", + "value": { + "stringValue": "pod-name" + } + }, + { + "key": "K8s.Node", + "value": { + "stringValue": "i-00000000000000000" + } + }, + { + "key": "K8s.Workload", + "value": { + "stringValue": "sample-app" + } + } + ], + "startTimeUnixNano": START_TIME, + "timeUnixNano": START_TIME, + "count": 0, + "scale": 0, + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } + } + ] } }, { "name": "Latency", "unit": "Milliseconds", "exponential_histogram": { - + "dataPoints": [ + { + "attributes": [ + { + "key": "aws.span.kind", + "value": { + "stringValue": "SERVER" + } + }, + { + "key": "Operation", + "value": { + "stringValue": "operation" + } + }, + { + "key": "Service", + "value": { + "stringValue": "service-name" + } + }, + { + "key": "K8s.Namespace", + "value": { + "stringValue": "default" + } + }, + { + "key": "K8s.Pod", + "value": { + "stringValue": "pod-name" + } + }, + { + "key": "K8s.Node", + "value": { + "stringValue": "i-00000000000000000" + } + }, + { + "key": "K8s.Workload", + "value": { + "stringValue": "sample-app" + } + } + ], + "startTimeUnixNano": START_TIME, + "timeUnixNano": START_TIME, + "count": 0, + "scale": 0, + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } + } + ] } }, { "name": "Latency", "unit": "Milliseconds", "exponential_histogram": { + "dataPoints": [ + { + "attributes": [ + { + "key": "aws.span.kind", + "value": { + "stringValue": "SERVER" + } + }, + { + "key": "Operation", + "value": { + "stringValue": "operation" + } + }, + { + "key": "Service", + "value": { + "stringValue": "drop-service-name-1" + } + }, + { + "key": "K8s.Namespace", + "value": { + "stringValue": "default" + } + }, + { + "key": "K8s.Pod", + "value": { + "stringValue": "pod-name" + } + }, + { + "key": "K8s.Node", + "value": { + "stringValue": "i-00000000000000000" + } + }, + { + "key": "K8s.Workload", + "value": { + "stringValue": "sample-app" + } + } + ], + "startTimeUnixNano": START_TIME, + "timeUnixNano": START_TIME, + "count": 0, + "scale": 0, + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } + } + ] + } + }, + { + "name": "Latency", + "unit": "Milliseconds", + "exponential_histogram": { + "dataPoints": [ + { + "attributes": [ + { + "key": "aws.span.kind", + "value": { + "stringValue": "SERVER" + } + }, + { + "key": "Operation", + "value": { + "stringValue": "do-not-keep-operation-1" + } + }, + { + "key": "Service", + "value": { + "stringValue": "service-name" + } + }, + { + "key": "K8s.Namespace", + "value": { + "stringValue": "default" + } + }, + { + "key": "K8s.Pod", + "value": { + "stringValue": "pod-name" + } + }, + { + "key": "K8s.Node", + "value": { + "stringValue": "i-00000000000000000" + } + }, + { + "key": "K8s.Workload", + "value": { + "stringValue": "sample-app" + } + } + ], + "startTimeUnixNano": START_TIME, + "timeUnixNano": START_TIME, + "count": 0, + "scale": 0, + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } + } + ] } } ] From 269cb8158dd98af69f4a99ebd24d1022a57fa2c8 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 12:22:58 -0400 Subject: [PATCH 072/108] tyring to fix json values --- test/app_signals/resources/metrics/client_producer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 949b7d2c9..6095c78ac 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -77,7 +77,7 @@ } ], "startTimeUnixNano": START_TIME, - "timeUnixNano": START_TIME + "timeUnixNano": START_TIME, "count": 0, "scale": 0, "zeroCount": 0, From c33d8173a52083974b3827e0dd92210a039ce469 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 12:27:11 -0400 Subject: [PATCH 073/108] previous commit generated metrics but it was a lotttt so trying to fix that --- .../resources/metrics/client_producer.json | 10 +--- .../resources/metrics/server_consumer.json | 50 ++----------------- 2 files changed, 6 insertions(+), 54 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index 6095c78ac..b1f312cc6 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -202,15 +202,7 @@ "timeUnixNano": START_TIME, "count": 0, "scale": 0, - "zeroCount": 0, - "positive": { - "offset": 0, - "bucket_counts": [1, 2, 3] - }, - "negative": { - "offset": 0, - "bucket_counts": [1, 2, 3] - } + "zeroCount": 0 } ] } diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index cf6c7e247..9cfbbcda9 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -86,15 +86,7 @@ "timeUnixNano": START_TIME, "count": 0, "scale": 0, - "zeroCount": 0, - "positive": { - "offset": 0, - "bucket_counts": [1, 2, 3] - }, - "negative": { - "offset": 0, - "bucket_counts": [1, 2, 3] - } + "zeroCount": 0 } ] } @@ -153,15 +145,7 @@ "timeUnixNano": START_TIME, "count": 0, "scale": 0, - "zeroCount": 0, - "positive": { - "offset": 0, - "bucket_counts": [1, 2, 3] - }, - "negative": { - "offset": 0, - "bucket_counts": [1, 2, 3] - } + "zeroCount": 0 } ] } @@ -220,15 +204,7 @@ "timeUnixNano": START_TIME, "count": 0, "scale": 0, - "zeroCount": 0, - "positive": { - "offset": 0, - "bucket_counts": [1, 2, 3] - }, - "negative": { - "offset": 0, - "bucket_counts": [1, 2, 3] - } + "zeroCount": 0 } ] } @@ -288,15 +264,7 @@ "timeUnixNano": START_TIME, "count": 0, "scale": 0, - "zeroCount": 0, - "positive": { - "offset": 0, - "bucket_counts": [1, 2, 3] - }, - "negative": { - "offset": 0, - "bucket_counts": [1, 2, 3] - } + "zeroCount": 0 } ] } @@ -355,15 +323,7 @@ "timeUnixNano": START_TIME, "count": 0, "scale": 0, - "zeroCount": 0, - "positive": { - "offset": 0, - "bucket_counts": [1, 2, 3] - }, - "negative": { - "offset": 0, - "bucket_counts": [1, 2, 3] - } + "zeroCount": 0 } ] } From 76f8db20443e00641d952e6545426052e116e8c9 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 12:30:28 -0400 Subject: [PATCH 074/108] previous commit generated metrics but it was a lotttt so trying to fix that --- .../resources/metrics/client_producer.json | 10 +++- .../resources/metrics/server_consumer.json | 50 +++++++++++++++++-- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/test/app_signals/resources/metrics/client_producer.json b/test/app_signals/resources/metrics/client_producer.json index b1f312cc6..6095c78ac 100644 --- a/test/app_signals/resources/metrics/client_producer.json +++ b/test/app_signals/resources/metrics/client_producer.json @@ -202,7 +202,15 @@ "timeUnixNano": START_TIME, "count": 0, "scale": 0, - "zeroCount": 0 + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } } ] } diff --git a/test/app_signals/resources/metrics/server_consumer.json b/test/app_signals/resources/metrics/server_consumer.json index 9cfbbcda9..cf6c7e247 100644 --- a/test/app_signals/resources/metrics/server_consumer.json +++ b/test/app_signals/resources/metrics/server_consumer.json @@ -86,7 +86,15 @@ "timeUnixNano": START_TIME, "count": 0, "scale": 0, - "zeroCount": 0 + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } } ] } @@ -145,7 +153,15 @@ "timeUnixNano": START_TIME, "count": 0, "scale": 0, - "zeroCount": 0 + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } } ] } @@ -204,7 +220,15 @@ "timeUnixNano": START_TIME, "count": 0, "scale": 0, - "zeroCount": 0 + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } } ] } @@ -264,7 +288,15 @@ "timeUnixNano": START_TIME, "count": 0, "scale": 0, - "zeroCount": 0 + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } } ] } @@ -323,7 +355,15 @@ "timeUnixNano": START_TIME, "count": 0, "scale": 0, - "zeroCount": 0 + "zeroCount": 0, + "positive": { + "offset": 0, + "bucket_counts": [1, 2, 3] + }, + "negative": { + "offset": 0, + "bucket_counts": [1, 2, 3] + } } ] } From 91277ae0d0930bfb00c0034db9b04ab092799eba Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 13:18:41 -0400 Subject: [PATCH 075/108] adding marshalling --- test/app_signals/agent_configs/config.json | 45 +++++++++++++++++++++- test/metric/metric_value_query.go | 10 +++++ validator/main.go | 2 +- validator/validators/validator.go | 2 +- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/test/app_signals/agent_configs/config.json b/test/app_signals/agent_configs/config.json index 9c03d5915..2a275eb83 100644 --- a/test/app_signals/agent_configs/config.json +++ b/test/app_signals/agent_configs/config.json @@ -4,7 +4,50 @@ }, "logs": { "metrics_collected": { - "app_signals": {} + "app_signals": { + "rules":[ + { + "selectors":[ + { + "dimension":"Operation", + "match":"operation" + } + ], + "action":"keep", + "rule_name":"keep01" + }, + { + "selectors":[ + { + "dimension":"Service", + "match":"drop-service-name*" + } + ], + "action":"drop", + "rule_name":"drop01" + }, + { + "selectors":[ + { + "dimension":"Operation", + "match":"operation" + }, + { + "dimension":"Service", + "match":"service-name" + } + ], + "replacements":[ + { + "target_dimension":"Operation", + "value":"replaced-operation" + } + ], + "action":"replace", + "rule_name":"replace01" + } + ] + } } }, "traces": { diff --git a/test/metric/metric_value_query.go b/test/metric/metric_value_query.go index eea358074..17505f9ea 100644 --- a/test/metric/metric_value_query.go +++ b/test/metric/metric_value_query.go @@ -5,6 +5,7 @@ package metric import ( "context" + "encoding/json" "fmt" "log" "strings" @@ -50,6 +51,15 @@ func (n *MetricValueFetcher) Fetch(namespace, metricName string, metricSpecificD }, } + // Marshal the metricDataQueries slice into JSON with indentation + jsonData, err := json.MarshalIndent(metricDataQueries, "", " ") + if err != nil { + fmt.Println("Error marshaling JSON:", err) + } + + // Print the JSON data + fmt.Println(string(jsonData)) + endTime := time.Now() startTime := subtractMinutes(endTime, 10) getMetricDataInput := cloudwatch.GetMetricDataInput{ diff --git a/validator/main.go b/validator/main.go index 66aa061d0..bae8bdc92 100644 --- a/validator/main.go +++ b/validator/main.go @@ -87,7 +87,7 @@ func validate(vConfig models.ValidateConfig) error { log.Printf("Test case: %s, validate type: %s has been successfully validated", vConfig.GetTestCase(), vConfig.GetValidateType()) return nil } - time.Sleep(10 * time.Second) + time.Sleep(60 * time.Second) log.Printf("test case: %s, validate type: %s, error: %v", vConfig.GetTestCase(), vConfig.GetValidateType(), err) continue } diff --git a/validator/validators/validator.go b/validator/validators/validator.go index 87dd3ffd5..9fc9499b7 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -53,7 +53,7 @@ func LaunchValidator(vConfig models.ValidateConfig) error { time.Sleep(agentCollectionPeriod) log.Printf("Start to sleep 120s for CloudWatch to process all the metrics") - time.Sleep(20 * time.Second) + time.Sleep(120 * time.Second) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From 9c285a17e84b7fc9651193826099f65d5ee217bb Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 13:27:50 -0400 Subject: [PATCH 076/108] adding test --- validator/validators/basic/basic_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index a095ea578..223db23b6 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -105,7 +105,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { //App Signals metric testing (This is because we want to use a different checking method (same that was done for linux test) if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { fetcher := apMetrics.MetricValueFetcher{} - values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "SampleCount", 60) + values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "sum", 60) if err != nil { fmt.Printf("error getting fetching app signals metrics %v", err) } From ddefa9df9783f8247adefd9481a11537bd58fb3b Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 13:42:00 -0400 Subject: [PATCH 077/108] changing sum to sample count --- validator/validators/basic/basic_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 223db23b6..a095ea578 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -105,7 +105,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { //App Signals metric testing (This is because we want to use a different checking method (same that was done for linux test) if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { fetcher := apMetrics.MetricValueFetcher{} - values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "sum", 60) + values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "SampleCount", 60) if err != nil { fmt.Printf("error getting fetching app signals metrics %v", err) } From fe6ab3180f76e05e7872c17529903d82d8cd9c83 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 14:04:33 -0400 Subject: [PATCH 078/108] changing stat to sum --- validator/validators/basic/basic_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index a095ea578..220d8f9ff 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -105,7 +105,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { //App Signals metric testing (This is because we want to use a different checking method (same that was done for linux test) if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { fetcher := apMetrics.MetricValueFetcher{} - values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "SampleCount", 60) + values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "Sum", 60) if err != nil { fmt.Printf("error getting fetching app signals metrics %v", err) } From 02d0b7b7344dcb5a3884e888c0667444b6852c06 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 14:15:33 -0400 Subject: [PATCH 079/108] adding traces --- validator/validators/basic/basic_validator.go | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 220d8f9ff..fef54aa5c 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -118,26 +118,27 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { multiErr = multierr.Append(multiErr, err) } } - //lookbackDuration := time.Duration(-5) * time.Minute - //timeNow := time.Now() - //var annotations = map[string]interface{}{ - // "aws_remote_target": "remote-target", - // "aws_remote_operation": "remote-operation", - // "aws_local_service": "service-name", - // "aws_remote_service": "service-name-remote", - // "aws_local_operation": "replaced-operation", - //} - //annotations["HostedIn_Environment"] = "Generic" - //xrayFilter := awsservice.FilterExpression(annotations) - //traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, xrayFilter) - //if err != nil { - // fmt.Printf("error getting trace ids: %v", err) - // multiErr = multierr.Append(multiErr, err) - //} else { - // fmt.Printf("Trace IDs: %v\n", traceIds) - // if len(traceIds) > 0 { - // fmt.Println("Trace IDs look good") - // } + lookbackDuration := time.Duration(-5) * time.Minute + timeNow := time.Now() + var annotations = map[string]interface{}{ + "aws_remote_target": "remote-target", + "aws_remote_operation": "remote-operation", + "aws_local_service": "service-name", + "aws_remote_service": "service-name-remote", + "aws_local_operation": "replaced-operation", + } + annotations["HostedIn_Environment"] = "Generic" + xrayFilter := awsservice.FilterExpression(annotations) + traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, xrayFilter) + if err != nil { + fmt.Printf("error getting trace ids: %v", err) + multiErr = multierr.Append(multiErr, err) + } else { + fmt.Printf("Trace IDs: %v\n", traceIds) + if len(traceIds) > 0 { + fmt.Println("Trace IDs look good") + } + } } //} From 8cc8ee487c93c4fa975db320f9d66a320224bbf7 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 16:07:10 -0400 Subject: [PATCH 080/108] tyrign to get trace ids --- validator/validators/basic/basic_validator.go | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index fef54aa5c..451eefcc2 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -118,18 +118,14 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { multiErr = multierr.Append(multiErr, err) } } - lookbackDuration := time.Duration(-5) * time.Minute - timeNow := time.Now() - var annotations = map[string]interface{}{ - "aws_remote_target": "remote-target", - "aws_remote_operation": "remote-operation", - "aws_local_service": "service-name", - "aws_remote_service": "service-name-remote", - "aws_local_operation": "replaced-operation", - } - annotations["HostedIn_Environment"] = "Generic" - xrayFilter := awsservice.FilterExpression(annotations) - traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, xrayFilter) + //lookbackDuration := time.Duration(-5) * time.Minute + serviceName := "service-name" + filterExpression := fmt.Sprintf("annotation.aws.local.service='%s'", serviceName) + + startTime := time.Now().Add(-time.Hour) // Example: 1 hour ago + endTime := time.Now() // Current time + + traceIds, err := awsservice.GetTraceIDs(startTime, endTime, filterExpression) if err != nil { fmt.Printf("error getting trace ids: %v", err) multiErr = multierr.Append(multiErr, err) @@ -139,6 +135,8 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { fmt.Println("Trace IDs look good") } } + fmt.Println("Trace IDs:", traceIds) + } //} From a86d6f484f0bf70bb3d3079a27d625ea8989e51b Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 16:14:02 -0400 Subject: [PATCH 081/108] tyrign to get trace ids --- validator/validators/basic/basic_validator.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 451eefcc2..daacd8da7 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -120,7 +120,8 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { } //lookbackDuration := time.Duration(-5) * time.Minute serviceName := "service-name" - filterExpression := fmt.Sprintf("annotation.aws.local.service='%s'", serviceName) + serviceType := "AWS::EC2::Instance" + filterExpression := fmt.Sprintf("(service(id(name: \"%s\", type: \"%s\")))", serviceName, serviceType) startTime := time.Now().Add(-time.Hour) // Example: 1 hour ago endTime := time.Now() // Current time From a81795cc6cb43c968eb95ba2569e8dc3bdb8e1b2 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 16:22:33 -0400 Subject: [PATCH 082/108] prev trac ids do generate --- validator/validators/basic/basic_validator.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index daacd8da7..dd7bbd337 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -118,15 +118,13 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { multiErr = multierr.Append(multiErr, err) } } - //lookbackDuration := time.Duration(-5) * time.Minute + lookbackDuration := time.Duration(-5) * time.Minute serviceName := "service-name" serviceType := "AWS::EC2::Instance" filterExpression := fmt.Sprintf("(service(id(name: \"%s\", type: \"%s\")))", serviceName, serviceType) + timeNow := time.Now() - startTime := time.Now().Add(-time.Hour) // Example: 1 hour ago - endTime := time.Now() // Current time - - traceIds, err := awsservice.GetTraceIDs(startTime, endTime, filterExpression) + traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, filterExpression) if err != nil { fmt.Printf("error getting trace ids: %v", err) multiErr = multierr.Append(multiErr, err) From fb8f6937485c6f1454793bbad2d35c9b5ca40990 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 16:25:34 -0400 Subject: [PATCH 083/108] adding to traceids --- validator/validators/basic/basic_validator.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index dd7bbd337..373d3f716 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -132,9 +132,10 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { fmt.Printf("Trace IDs: %v\n", traceIds) if len(traceIds) > 0 { fmt.Println("Trace IDs look good") + } else { + multiErr = multierr.Append(multiErr, fmt.Errorf("no trace IDs found")) } } - fmt.Println("Trace IDs:", traceIds) } From da371adba0b7ea357d17e86021259dc5f8f23407 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 19 Apr 2024 16:31:02 -0400 Subject: [PATCH 084/108] this works with traces too --- test/feature/mac/parameters.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/feature/mac/parameters.yml b/test/feature/mac/parameters.yml index 15b9642bb..12bd99100 100644 --- a/test/feature/mac/parameters.yml +++ b/test/feature/mac/parameters.yml @@ -129,7 +129,7 @@ metric_validation: metric_sample_count: 60 metric_dimension: [] - metric_name: "Fault" - metric_sample_count: 12 + metric_sample_count: 60 metric_dimension: - name: "HostedIn.Environment" value: "Generic" @@ -138,7 +138,7 @@ metric_validation: - name: "Service" value: "service-name" - metric_name: "Latency" - metric_sample_count: 12 + metric_sample_count: 60 metric_dimension: - name: "HostedIn.Environment" value: "Generic" @@ -147,7 +147,7 @@ metric_validation: - name: "Service" value: "service-name" - metric_name: "Error" - metric_sample_count: 12 + metric_sample_count: 60 metric_dimension: - name: "HostedIn.Environment" value: "Generic" From e190808248872b11c37454a189758ff6a580eec8 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 09:58:47 -0400 Subject: [PATCH 085/108] Tests works for macos and windows --- validator/validators/basic/basic_validator.go | 21 ++++++++----------- validator/validators/validator.go | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 373d3f716..b6608cc63 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -102,15 +102,16 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Value: aws.String(serviceValue), }, } - //App Signals metric testing (This is because we want to use a different checking method (same that was done for linux test) + //App Signals metric testing (This is because we want to use a different checking method (same that was done for linux test)) if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { fetcher := apMetrics.MetricValueFetcher{} values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "Sum", 60) if err != nil { - fmt.Printf("error getting fetching app signals metrics %v", err) + multiErr = multierr.Append(multiErr, err) } if !apMetrics.IsAllValuesGreaterThanOrEqualToExpectedValue(metric.MetricName, values, 0) { - fmt.Printf("error value not the epected values%v", err) + fmt.Printf("Error values are not the epected values%v", err) + multiErr = multierr.Append(multiErr, fmt.Errorf("Incorrect Metric values ")) } } else { err := s.ValidateMetric(metric.MetricName, metricNamespace, metricDimensions, metric.MetricValue, metric.MetricSampleCount, startTime, endTime) @@ -121,6 +122,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { lookbackDuration := time.Duration(-5) * time.Minute serviceName := "service-name" serviceType := "AWS::EC2::Instance" + //filtering traces filterExpression := fmt.Sprintf("(service(id(name: \"%s\", type: \"%s\")))", serviceName, serviceType) timeNow := time.Now() @@ -138,8 +140,6 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { } } - - //} for _, logValidation := range logValidations { err := s.ValidateLogs(logValidation.LogStream, logValidation.LogValue, logValidation.LogLevel, logValidation.LogSource, logValidation.LogLines, startTime, endTime) if err != nil { @@ -209,18 +209,15 @@ func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metr if err != nil { return err } - fmt.Printf("For metric: %v This is the metric data result: %v and the result values: %v", metricName, metrics.MetricDataResults, metrics.MetricDataResults[0].Values) + if len(metrics.MetricDataResults) == 0 || len(metrics.MetricDataResults[0].Values) == 0 { return fmt.Errorf("\n getting metric %s failed with the namespace %s and dimension %v", metricName, metricNamespace, util.LogCloudWatchDimension(metricDimensions)) } // Validate if the metrics are not dropping any metrics and able to backfill within the same minute (e.g if the memory_rss metric is having collection_interval 1 // , it will need to have 60 sample counts - 1 datapoint / second) - - if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount-2, metricSampleCount, int32(boundAndPeriod)); !ok { - return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount-2, metricSampleCount) - } else { - fmt.Println("Yayyyyyyy!!!!!!! sample count is good for :", metricName) + if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount, metricSampleCount, int32(boundAndPeriod)); !ok { + return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount, metricSampleCount) } // Validate if the corresponding metrics are within the acceptable range [acceptable value +- 10%] @@ -255,7 +252,7 @@ func (s *BasicValidator) buildMetricQueries(metricName, metricNamespace string, }, } - fmt.Println("Maybe better form of metric query") + fmt.Println("Display query: ") jsonBytes, err := json.MarshalIndent(metricDataQueries, "", " ") if err != nil { // handle error diff --git a/validator/validators/validator.go b/validator/validators/validator.go index 9fc9499b7..e137c6b64 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -53,7 +53,7 @@ func LaunchValidator(vConfig models.ValidateConfig) error { time.Sleep(agentCollectionPeriod) log.Printf("Start to sleep 120s for CloudWatch to process all the metrics") - time.Sleep(120 * time.Second) + time.Sleep(2 * time.Minute) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From 82469aabcd1489d7a50c38ca6c83941b2168d0ec Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 10:38:18 -0400 Subject: [PATCH 086/108] Tests works for macos and windows --- test/feature/mac/agent_config.json | 198 ++++++++++++++--------------- 1 file changed, 99 insertions(+), 99 deletions(-) diff --git a/test/feature/mac/agent_config.json b/test/feature/mac/agent_config.json index 90aca38cc..e31a21550 100644 --- a/test/feature/mac/agent_config.json +++ b/test/feature/mac/agent_config.json @@ -1,110 +1,110 @@ { - "agent": { - "debug": true + "agent": { + "debug": true + }, + "logs": { + "force_flush_interval": 5, + "logs_collected": { + "files": { + "collect_list": [ + { + "file_path": "/tmp/test1.log", + "log_group_name": "{instance_id}", + "log_stream_name": "test1.log", + "retention_in_days": 1, + "timezone": "UTC" + } + ] + } }, - "traces": { - "traces_collected": { - "app_signals": {} + "metrics_collected": { + "app_signals": {}, + "emf": {} } }, - "metrics": { - "namespace": "CloudWatchAgentMacFeature", - "metrics_collected": { - "statsd": { - "metrics_aggregation_interval": 60, - "metrics_collection_interval": 60, - "service_address": ":8125" - }, - "cpu": { - "measurement": [ - "time_active", - "time_guest" - ], - "metrics_collection_interval": 1 - }, - "swap": { - "measurement": [ - "free", - "used_percent" - ], - "metrics_collection_interval": 1 - }, - "processes": { - "measurement": [ - "blocked", - "running" - ], - "metrics_collection_interval": 1 - }, - "netstat": { - "measurement": [ - "tcp_close", - "udp_socket" - ], - "metrics_collection_interval": 1 - }, - "mem": { - "measurement": [ - "available_percent", - "used_percent" - ], - "metrics_collection_interval": 1 - }, - "disk": { - "resources": [ - "*" - ], - "measurement": [ - "free", - "used_percent" - ], - "drop_device": true, - "metrics_collection_interval": 1 - }, - "net": { - "resources": [ - "en0" - ], - "measurement": [ - "bytes_sent", - "bytes_recv" - ], - "metrics_collection_interval": 1 - }, - "procstat": [ - { - "exe": "amazon-cloudwatch-agent", - "measurement": [ - "cpu_usage", - "memory_rss" - ], - "metrics_collection_interval": 1 - } + "metrics": { + "append_dimensions": { + "InstanceId": "${aws:InstanceId}" + }, + "force_flush_interval": 30, + "metrics_collected": { + "cpu": { + "measurement": [ + "time_active", + "time_guest" + ], + "metrics_collection_interval": 1 + }, + "disk": { + "drop_device": true, + "measurement": [ + "free", + "used_percent" + ], + "metrics_collection_interval": 1, + "resources": [ + "*" ] }, - "append_dimensions": { - "InstanceId": "${aws:InstanceId}" + "mem": { + "measurement": [ + "available_percent", + "used_percent" + ], + "metrics_collection_interval": 1 }, - "force_flush_interval": 30 - }, - "logs": { - "logs_collected": { - "files": { - "collect_list": [ - { - "file_path": "/tmp/test1.log", - "log_group_name": "{instance_id}", - "log_stream_name": "test1.log", - "timezone": "UTC" - } + "net": { + "measurement": [ + "bytes_sent", + "bytes_recv" + ], + "metrics_collection_interval": 1, + "resources": [ + "en0" ] - } }, - "metrics_collected": { - "app_signals": {}, - "emf": { } + "netstat": { + "measurement": [ + "tcp_close", + "udp_socket" + ], + "metrics_collection_interval": 1 + }, + "processes": { + "measurement": [ + "blocked", + "running" + ], + "metrics_collection_interval": 1 + }, + "procstat": [ + { + "exe": "amazon-cloudwatch-agent", + "measurement": [ + "cpu_usage", + "memory_rss" + ], + "metrics_collection_interval": 1 + } + ], + "statsd": { + "metrics_aggregation_interval": 60, + "metrics_collection_interval": 60, + "service_address": ":8125" }, - "force_flush_interval": 5 + "swap": { + "measurement": [ + "free", + "used_percent" + ], + "metrics_collection_interval": 1 + } + }, + "namespace": "CloudWatchAgentMacFeature" + }, + "traces": { + "traces_collected": { + "app_signals": {} } -} - + } +} \ No newline at end of file From 6a039c510371227c829a06f70f43b61fbbf12b67 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 11:38:45 -0400 Subject: [PATCH 087/108] Tests works for macos and windows --- validator/validators/basic/basic_validator.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index b6608cc63..478d1e08a 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -84,10 +84,9 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { }) } environmentValue := "Generic" - operationValue := "operation" + operationValue := "replaced-operation" serviceValue := "service-name" - // Creating the first group of dimensions appSignalDimensions := []cwtypes.Dimension{ { Name: aws.String("HostedIn.Environment"), @@ -102,6 +101,21 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { Value: aws.String(serviceValue), }, } + + appSignalDimensions2 := []cwtypes.Dimension{ + { + Name: aws.String("HostedIn.Environment"), + Value: aws.String(environmentValue), + }, + { + Name: aws.String("Operation"), + Value: aws.String(operationValue), + }, + { + Name: aws.String("Service"), + Value: aws.String(serviceValue), + }, + } //App Signals metric testing (This is because we want to use a different checking method (same that was done for linux test)) if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { fetcher := apMetrics.MetricValueFetcher{} From ae872ce7c38d3f0c940dbb1d3aca2c78ad5e7634 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 11:53:11 -0400 Subject: [PATCH 088/108] Tests works for macos and windows --- validator/validators/basic/basic_validator.go | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 478d1e08a..4aabcb933 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -84,7 +84,7 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { }) } environmentValue := "Generic" - operationValue := "replaced-operation" + operationValue := "operation" serviceValue := "service-name" appSignalDimensions := []cwtypes.Dimension{ @@ -102,20 +102,6 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { }, } - appSignalDimensions2 := []cwtypes.Dimension{ - { - Name: aws.String("HostedIn.Environment"), - Value: aws.String(environmentValue), - }, - { - Name: aws.String("Operation"), - Value: aws.String(operationValue), - }, - { - Name: aws.String("Service"), - Value: aws.String(serviceValue), - }, - } //App Signals metric testing (This is because we want to use a different checking method (same that was done for linux test)) if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { fetcher := apMetrics.MetricValueFetcher{} From 309bdfcf761992127c81b242ac9a2914f80269a5 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 14:06:13 -0400 Subject: [PATCH 089/108] Tests works for macos and windows --- terraform/ec2/mac/main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/terraform/ec2/mac/main.tf b/terraform/ec2/mac/main.tf index 3791b008f..74831c68e 100644 --- a/terraform/ec2/mac/main.tf +++ b/terraform/ec2/mac/main.tf @@ -128,6 +128,7 @@ resource "null_resource" "integration_test" { "sudo chmod +x ./validator", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:${module.validator.instance_agent_config}", + "sleep 5", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=false", "cd ~/amazon-cloudwatch-agent-test", "echo run sanity test && sudo go test ./test/sanity -p 1 -v", From a198d4224f22707fe53e9967124afc21157aad6e Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 16:16:19 -0400 Subject: [PATCH 090/108] Tests works for macos and windows --- terraform/ec2/mac/main.tf | 4 +++- util/common/metrics.go | 40 +++++++------------------------ validator/validators/validator.go | 4 ++-- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/terraform/ec2/mac/main.tf b/terraform/ec2/mac/main.tf index 74831c68e..f09dda3ef 100644 --- a/terraform/ec2/mac/main.tf +++ b/terraform/ec2/mac/main.tf @@ -128,7 +128,9 @@ resource "null_resource" "integration_test" { "sudo chmod +x ./validator", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:${module.validator.instance_agent_config}", - "sleep 5", + "tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log ", + "sleep 60", + "tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log " "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=false", "cd ~/amazon-cloudwatch-agent-test", "echo run sanity test && sudo go test ./test/sanity -p 1 -v", diff --git a/util/common/metrics.go b/util/common/metrics.go index ab45587a2..d5c5ceb66 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -200,43 +200,24 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } func processFile(filePath string, startTime int64) { - data, err := os.ReadFile(filePath) // Using os.ReadFile here + data, err := os.ReadFile(filePath) if err != nil { fmt.Println("Error reading file:", err) return } - // Replace START_TIME with the current time + //replace START_TIME with the current time modifiedData := strings.ReplaceAll(string(data), "START_TIME", fmt.Sprintf("%d", startTime)) - // Mimic `curl` command - sending HTTP POST request + //curl command url := "http://127.0.0.1:4316/v1/metrics" _, err = http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) - if err != nil { - fmt.Println("Error sending request:", err) - } -} -func shouldSendMetrics() (bool, error) { - data, err := os.ReadFile(LastSendTimeFile) - if err != nil { - if os.IsNotExist(err) { - return true, nil // File not found, so we should send - } - return false, err // Some other error reading the file - } - lastSendTime, err := time.Parse(time.RFC3339, string(data)) if err != nil { - return false, err // Error parsing the time + fmt.Println("Error sending request:", err) } - - return time.Since(lastSendTime).Seconds() > MinInterval, nil } -func updateLastSendTime() error { - now := time.Now().Format(time.RFC3339) - return os.WriteFile(LastSendTimeFile, []byte(now), 0644) -} func SendAppSignalMetrics(duration time.Duration) error { // The bash script to be executed asynchronously. dir, err := os.Getwd() @@ -254,23 +235,18 @@ func SendAppSignalMetrics(duration time.Duration) error { baseDir = "/Users/ec2-user/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics" } - for i := 0; i < int(duration/5); i++ { - send, err := shouldSendMetrics() + for i := 0; i < 12; i++ { if err != nil { return err } - if !send { - fmt.Println("Skipping sending metrics as it's too soon.") - continue - } - // Get current time like `date +%s%N` + + //start time to send to process file startTime := time.Now().UnixNano() - // Process files with dynamic paths + //process files processFile(filepath.Join(baseDir, "server_consumer.json"), startTime) processFile(filepath.Join(baseDir, "client_producer.json"), startTime) - // Sleep for 5 seconds time.Sleep(5 * time.Second) } diff --git a/validator/validators/validator.go b/validator/validators/validator.go index e137c6b64..cc40f5ad4 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -51,9 +51,9 @@ func LaunchValidator(vConfig models.ValidateConfig) error { } - time.Sleep(agentCollectionPeriod) + //time.Sleep(agentCollectionPeriod) log.Printf("Start to sleep 120s for CloudWatch to process all the metrics") - time.Sleep(2 * time.Minute) + //time.Sleep(2 * time.Second) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From b20ae4bcb225020a6df699b7e74a358a14c9176c Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 16:26:29 -0400 Subject: [PATCH 091/108] Tests works for macos and windows --- validator/validators/validator.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validator/validators/validator.go b/validator/validators/validator.go index cc40f5ad4..d5b7166ca 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -51,9 +51,9 @@ func LaunchValidator(vConfig models.ValidateConfig) error { } - //time.Sleep(agentCollectionPeriod) + time.Sleep(agentCollectionPeriod) log.Printf("Start to sleep 120s for CloudWatch to process all the metrics") - //time.Sleep(2 * time.Second) + time.Sleep(2 * time.Second) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From f9933213cdf164848ce6ab623a133a0421becba6 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 16:31:24 -0400 Subject: [PATCH 092/108] Tests works for macos and windows --- validator/validators/validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/validators/validator.go b/validator/validators/validator.go index d5b7166ca..e137c6b64 100644 --- a/validator/validators/validator.go +++ b/validator/validators/validator.go @@ -53,7 +53,7 @@ func LaunchValidator(vConfig models.ValidateConfig) error { time.Sleep(agentCollectionPeriod) log.Printf("Start to sleep 120s for CloudWatch to process all the metrics") - time.Sleep(2 * time.Second) + time.Sleep(2 * time.Minute) err = validator.CheckData(startTimeValidation, endTimeValidation) if err != nil { From 39c20715b42154d9855c6c3f7a087c46348e7ab5 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 16:41:08 -0400 Subject: [PATCH 093/108] Tests works for macos and windows --- util/common/metrics.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index d5c5ceb66..d8fcb354a 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -11,6 +11,7 @@ import ( "encoding/hex" "errors" "fmt" + "io" "net" "net/http" "os" @@ -213,9 +214,26 @@ func processFile(filePath string, startTime int64) { url := "http://127.0.0.1:4316/v1/metrics" _, err = http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) + resp, err := http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) if err != nil { - fmt.Println("Error sending request:", err) + fmt.Println("Failed to send POST request to", url) + fmt.Printf("Error: %v\n", err) + return } + defer resp.Body.Close() + + fmt.Println("Response Status:", resp.Status) + fmt.Println("Response Body:") + + // Copy response body to standard output + _, err = io.Copy(os.Stdout, resp.Body) + if err != nil { + fmt.Println("Failed to copy response body:", err) + return + } else { + fmt.Println("Success with post app signals!!!") + } + } func SendAppSignalMetrics(duration time.Duration) error { From 205b882ad032321280db4ac3048704f831c4996e Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 17:01:24 -0400 Subject: [PATCH 094/108] Tests works for macos and windows --- terraform/ec2/mac/main.tf | 2 +- util/common/metrics.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/ec2/mac/main.tf b/terraform/ec2/mac/main.tf index f09dda3ef..933d3e4f3 100644 --- a/terraform/ec2/mac/main.tf +++ b/terraform/ec2/mac/main.tf @@ -130,7 +130,7 @@ resource "null_resource" "integration_test" { "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:${module.validator.instance_agent_config}", "tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log ", "sleep 60", - "tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log " + "tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log ", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=false", "cd ~/amazon-cloudwatch-agent-test", "echo run sanity test && sudo go test ./test/sanity -p 1 -v", diff --git a/util/common/metrics.go b/util/common/metrics.go index d8fcb354a..fc754584f 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -225,7 +225,7 @@ func processFile(filePath string, startTime int64) { fmt.Println("Response Status:", resp.Status) fmt.Println("Response Body:") - // Copy response body to standard output + //copy response body to standard output _, err = io.Copy(os.Stdout, resp.Body) if err != nil { fmt.Println("Failed to copy response body:", err) From eafe9bf5441731dcb783962cb7ca407b58801698 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 17:46:29 -0400 Subject: [PATCH 095/108] Tests works for macos and windows --- terraform/ec2/mac/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/ec2/mac/main.tf b/terraform/ec2/mac/main.tf index 933d3e4f3..7da7c0ece 100644 --- a/terraform/ec2/mac/main.tf +++ b/terraform/ec2/mac/main.tf @@ -128,10 +128,10 @@ resource "null_resource" "integration_test" { "sudo chmod +x ./validator", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:${module.validator.instance_agent_config}", - "tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log ", "sleep 60", - "tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log ", + "cat /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log ", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=false", + "cat /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log ", "cd ~/amazon-cloudwatch-agent-test", "echo run sanity test && sudo go test ./test/sanity -p 1 -v", "sudo go test ./test/run_as_user -p 1 -timeout 1h -computeType=EC2 -bucket=${var.s3_bucket} -cwaCommitSha=${var.cwa_github_sha} -instanceId=${aws_instance.cwagent.id} -v", From 8002975f59d1ed4a6706c5563fac411acbdbbc4c Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 18:01:47 -0400 Subject: [PATCH 096/108] Tests works for macos and windows --- generator/resources/ec2_mac_test_matrix.json | 42 -------------------- 1 file changed, 42 deletions(-) diff --git a/generator/resources/ec2_mac_test_matrix.json b/generator/resources/ec2_mac_test_matrix.json index b131e6553..c88eda07c 100644 --- a/generator/resources/ec2_mac_test_matrix.json +++ b/generator/resources/ec2_mac_test_matrix.json @@ -1,50 +1,8 @@ [ - { - "os": "macOS Big Sur Arm64", - "instanceType":"mac2.metal", - "ami": "cloudwatch-agent-integration-test-mac-bigsur-arm64", - "arc": "arm64" - }, - { - "os": "macOS Big Sur Amd64", - "instanceType":"mac1.metal", - "ami": "cloudwatch-agent-integration-test-mac-bigsur-x86", - "arc": "amd64" - }, - { - "os": "macOS Ventura Arm64", - "instanceType":"mac2.metal", - "ami": "cloudwatch-agent-integration-test-mac-ventura-arm64", - "arc": "arm64" - }, { "os": "macOS Ventura Amd64", "instanceType":"mac1.metal", "ami": "cloudwatch-agent-integration-test-mac-ventura-x86", "arc": "amd64" - }, - { - "os": "macOS Monterey Arm64", - "instanceType":"mac2.metal", - "ami": "cloudwatch-agent-integration-test-mac-monterey-arm64", - "arc": "arm64" - }, - { - "os": "macOS Monterey Amd64", - "instanceType":"mac1.metal", - "ami": "cloudwatch-agent-integration-test-mac-monterey-x86", - "arc": "amd64" - }, - { - "os": "macOS Sonoma Arm64", - "instanceType":"mac2.metal", - "ami": "cloudwatch-agent-integration-test-mac-sonoma-arm64", - "arc": "arm64" - }, - { - "os": "macOS Sonoma Amd64", - "instanceType":"mac1.metal", - "ami": "cloudwatch-agent-integration-test-mac-sonoma-x86", - "arc": "amd64" } ] \ No newline at end of file From 0112b5dc4e6733e90130fd695ab0553f4a83f11b Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 18:31:25 -0400 Subject: [PATCH 097/108] Removing terraform delete --- generator/resources/ec2_mac_test_matrix.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/generator/resources/ec2_mac_test_matrix.json b/generator/resources/ec2_mac_test_matrix.json index c88eda07c..d493c6f3f 100644 --- a/generator/resources/ec2_mac_test_matrix.json +++ b/generator/resources/ec2_mac_test_matrix.json @@ -1,8 +1,28 @@ [ + + { "os": "macOS Ventura Amd64", "instanceType":"mac1.metal", "ami": "cloudwatch-agent-integration-test-mac-ventura-x86", "arc": "amd64" + }, + { + "os": "macOS Monterey Arm64", + "instanceType":"mac2.metal", + "ami": "cloudwatch-agent-integration-test-mac-monterey-arm64", + "arc": "arm64" + }, + { + "os": "macOS Monterey Amd64", + "instanceType":"mac1.metal", + "ami": "cloudwatch-agent-integration-test-mac-monterey-x86", + "arc": "amd64" + }, + { + "os": "macOS Sonoma Arm64", + "instanceType":"mac2.metal", + "ami": "cloudwatch-agent-integration-test-mac-sonoma-arm64", + "arc": "arm64" } ] \ No newline at end of file From 98aa56e6dc12b23bbb67eff2195bab1988abee24 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 21:12:39 -0400 Subject: [PATCH 098/108] making sure to checkout the correct test branch --- terraform/ec2/mac/main.tf | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/terraform/ec2/mac/main.tf b/terraform/ec2/mac/main.tf index 7da7c0ece..9864430a1 100644 --- a/terraform/ec2/mac/main.tf +++ b/terraform/ec2/mac/main.tf @@ -126,12 +126,10 @@ resource "null_resource" "integration_test" { "echo Execute integration tests", "export AWS_REGION=${var.region}", "sudo chmod +x ./validator", + "git checkout MacOSEC2Test -f" "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:${module.validator.instance_agent_config}", - "sleep 60", - "cat /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log ", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=false", - "cat /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log ", "cd ~/amazon-cloudwatch-agent-test", "echo run sanity test && sudo go test ./test/sanity -p 1 -v", "sudo go test ./test/run_as_user -p 1 -timeout 1h -computeType=EC2 -bucket=${var.s3_bucket} -cwaCommitSha=${var.cwa_github_sha} -instanceId=${aws_instance.cwagent.id} -v", From b8acfcb187a1ec46527e11641c432a8c9249b4d9 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 22 Apr 2024 21:13:49 -0400 Subject: [PATCH 099/108] adding all the instance back making sure we are in the right test repo Finished App Signal EC2 test for mac and windows --- generator/resources/ec2_mac_test_matrix.json | 26 ++++++++++++- terraform/ec2/mac/main.tf | 1 - util/common/metrics.go | 37 ++++++++----------- validator/validators/basic/basic_validator.go | 9 ----- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/generator/resources/ec2_mac_test_matrix.json b/generator/resources/ec2_mac_test_matrix.json index d493c6f3f..b131e6553 100644 --- a/generator/resources/ec2_mac_test_matrix.json +++ b/generator/resources/ec2_mac_test_matrix.json @@ -1,6 +1,22 @@ [ - - + { + "os": "macOS Big Sur Arm64", + "instanceType":"mac2.metal", + "ami": "cloudwatch-agent-integration-test-mac-bigsur-arm64", + "arc": "arm64" + }, + { + "os": "macOS Big Sur Amd64", + "instanceType":"mac1.metal", + "ami": "cloudwatch-agent-integration-test-mac-bigsur-x86", + "arc": "amd64" + }, + { + "os": "macOS Ventura Arm64", + "instanceType":"mac2.metal", + "ami": "cloudwatch-agent-integration-test-mac-ventura-arm64", + "arc": "arm64" + }, { "os": "macOS Ventura Amd64", "instanceType":"mac1.metal", @@ -24,5 +40,11 @@ "instanceType":"mac2.metal", "ami": "cloudwatch-agent-integration-test-mac-sonoma-arm64", "arc": "arm64" + }, + { + "os": "macOS Sonoma Amd64", + "instanceType":"mac1.metal", + "ami": "cloudwatch-agent-integration-test-mac-sonoma-x86", + "arc": "amd64" } ] \ No newline at end of file diff --git a/terraform/ec2/mac/main.tf b/terraform/ec2/mac/main.tf index 9864430a1..3791b008f 100644 --- a/terraform/ec2/mac/main.tf +++ b/terraform/ec2/mac/main.tf @@ -126,7 +126,6 @@ resource "null_resource" "integration_test" { "echo Execute integration tests", "export AWS_REGION=${var.region}", "sudo chmod +x ./validator", - "git checkout MacOSEC2Test -f" "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:${module.validator.instance_agent_config}", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=false", diff --git a/util/common/metrics.go b/util/common/metrics.go index fc754584f..61bd3c852 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -11,7 +11,6 @@ import ( "encoding/hex" "errors" "fmt" - "io" "net" "net/http" "os" @@ -40,7 +39,7 @@ func StartSendingMetrics(receiver string, duration, sendingInterval time.Duratio case "emf": err = SendEMFMetrics(metricPerInterval, metricLogGroup, metricNamespace, sendingInterval, duration) case "app_signals": - err = SendAppSignalMetrics(duration) //does app signals have dimension for metric? + err = SendAppSignalMetrics() //does app signals have dimension for metric? case "traces": err = SendAppTraceMetrics(duration) //does app signals have dimension for metric? @@ -200,11 +199,11 @@ func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.D } } -func processFile(filePath string, startTime int64) { +func processFile(filePath string, startTime int64) error { data, err := os.ReadFile(filePath) if err != nil { fmt.Println("Error reading file:", err) - return + return nil } //replace START_TIME with the current time @@ -214,29 +213,17 @@ func processFile(filePath string, startTime int64) { url := "http://127.0.0.1:4316/v1/metrics" _, err = http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) - resp, err := http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) + _, err = http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) if err != nil { fmt.Println("Failed to send POST request to", url) fmt.Printf("Error: %v\n", err) - return - } - defer resp.Body.Close() - - fmt.Println("Response Status:", resp.Status) - fmt.Println("Response Body:") - - //copy response body to standard output - _, err = io.Copy(os.Stdout, resp.Body) - if err != nil { - fmt.Println("Failed to copy response body:", err) - return - } else { - fmt.Println("Success with post app signals!!!") + return err } + return nil } -func SendAppSignalMetrics(duration time.Duration) error { +func SendAppSignalMetrics() error { // The bash script to be executed asynchronously. dir, err := os.Getwd() if err != nil { @@ -262,8 +249,14 @@ func SendAppSignalMetrics(duration time.Duration) error { startTime := time.Now().UnixNano() //process files - processFile(filepath.Join(baseDir, "server_consumer.json"), startTime) - processFile(filepath.Join(baseDir, "client_producer.json"), startTime) + err = processFile(filepath.Join(baseDir, "server_consumer.json"), startTime) + if err != nil { + return err + } + err = processFile(filepath.Join(baseDir, "client_producer.json"), startTime) + if err != nil { + return err + } time.Sleep(5 * time.Second) } diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 4aabcb933..8b2a720dd 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -4,7 +4,6 @@ package basic import ( - "encoding/json" "fmt" "log" "strings" @@ -251,13 +250,5 @@ func (s *BasicValidator) buildMetricQueries(metricName, metricNamespace string, Id: aws.String(strings.ToLower(metricName)), }, } - - fmt.Println("Display query: ") - jsonBytes, err := json.MarshalIndent(metricDataQueries, "", " ") - if err != nil { - // handle error - log.Fatal(err) - } - fmt.Println(string(jsonBytes)) return metricDataQueries } From b6b396233a558e68ce32055543c754e93c3d53de Mon Sep 17 00:00:00 2001 From: Paramadon Date: Tue, 23 Apr 2024 10:46:50 -0400 Subject: [PATCH 100/108] making sure agent configuration is right --- test/feature/mac/agent_config.json | 115 ++++++++++++++--------------- 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/test/feature/mac/agent_config.json b/test/feature/mac/agent_config.json index e31a21550..3ceb9c6b3 100644 --- a/test/feature/mac/agent_config.json +++ b/test/feature/mac/agent_config.json @@ -2,32 +2,14 @@ "agent": { "debug": true }, - "logs": { - "force_flush_interval": 5, - "logs_collected": { - "files": { - "collect_list": [ - { - "file_path": "/tmp/test1.log", - "log_group_name": "{instance_id}", - "log_stream_name": "test1.log", - "retention_in_days": 1, - "timezone": "UTC" - } - ] - } - }, - "metrics_collected": { - "app_signals": {}, - "emf": {} - } - }, "metrics": { - "append_dimensions": { - "InstanceId": "${aws:InstanceId}" - }, - "force_flush_interval": 30, + "namespace": "CloudWatchAgentMacFeature", "metrics_collected": { + "statsd": { + "metrics_aggregation_interval": 60, + "metrics_collection_interval": 60, + "service_address": ":8125" + }, "cpu": { "measurement": [ "time_active", @@ -35,16 +17,26 @@ ], "metrics_collection_interval": 1 }, - "disk": { - "drop_device": true, + "swap": { "measurement": [ "free", "used_percent" ], - "metrics_collection_interval": 1, - "resources": [ - "*" - ] + "metrics_collection_interval": 1 + }, + "processes": { + "measurement": [ + "blocked", + "running" + ], + "metrics_collection_interval": 1 + }, + "netstat": { + "measurement": [ + "tcp_close", + "udp_socket" + ], + "metrics_collection_interval": 1 }, "mem": { "measurement": [ @@ -53,27 +45,24 @@ ], "metrics_collection_interval": 1 }, - "net": { - "measurement": [ - "bytes_sent", - "bytes_recv" - ], - "metrics_collection_interval": 1, + "disk": { "resources": [ - "en0" - ] - }, - "netstat": { + "*" + ], "measurement": [ - "tcp_close", - "udp_socket" + "free", + "used_percent" ], + "drop_device": true, "metrics_collection_interval": 1 }, - "processes": { + "net": { + "resources": [ + "en0" + ], "measurement": [ - "blocked", - "running" + "bytes_sent", + "bytes_recv" ], "metrics_collection_interval": 1 }, @@ -86,21 +75,31 @@ ], "metrics_collection_interval": 1 } - ], - "statsd": { - "metrics_aggregation_interval": 60, - "metrics_collection_interval": 60, - "service_address": ":8125" - }, - "swap": { - "measurement": [ - "free", - "used_percent" - ], - "metrics_collection_interval": 1 + ] + }, + "append_dimensions": { + "InstanceId": "${aws:InstanceId}" + }, + "force_flush_interval": 30 + }, + "logs": { + "logs_collected": { + "files": { + "collect_list": [ + { + "file_path": "/tmp/test1.log", + "log_group_name": "{instance_id}", + "log_stream_name": "test1.log", + "timezone": "UTC" + } + ] } }, - "namespace": "CloudWatchAgentMacFeature" + "metrics_collected": { + "app_signals": {}, + "emf": { } + }, + "force_flush_interval": 5 }, "traces": { "traces_collected": { From aa19fb4af833e159e7dec0e1500960edccb40d15 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Tue, 23 Apr 2024 10:50:42 -0400 Subject: [PATCH 101/108] test one more time to make sure --- terraform/ec2/mac/main.tf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/terraform/ec2/mac/main.tf b/terraform/ec2/mac/main.tf index 3791b008f..c18944f6f 100644 --- a/terraform/ec2/mac/main.tf +++ b/terraform/ec2/mac/main.tf @@ -126,6 +126,9 @@ resource "null_resource" "integration_test" { "echo Execute integration tests", "export AWS_REGION=${var.region}", "sudo chmod +x ./validator", + "cd amazon-cloudwatch-agent-test", + "git checkout MacOSEC2Test -f", + "cd ..", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:${module.validator.instance_agent_config}", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=false", From 2439b7175c7b08a777c1f99778ccd569e78341e1 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Tue, 23 Apr 2024 10:52:25 -0400 Subject: [PATCH 102/108] Finished testing --- terraform/ec2/mac/main.tf | 3 --- 1 file changed, 3 deletions(-) diff --git a/terraform/ec2/mac/main.tf b/terraform/ec2/mac/main.tf index c18944f6f..3791b008f 100644 --- a/terraform/ec2/mac/main.tf +++ b/terraform/ec2/mac/main.tf @@ -126,9 +126,6 @@ resource "null_resource" "integration_test" { "echo Execute integration tests", "export AWS_REGION=${var.region}", "sudo chmod +x ./validator", - "cd amazon-cloudwatch-agent-test", - "git checkout MacOSEC2Test -f", - "cd ..", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:${module.validator.instance_agent_config}", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=false", From 05834b23089871fdfc571ac0383f7bbc62b8cb3b Mon Sep 17 00:00:00 2001 From: Paramadon Date: Tue, 23 Apr 2024 10:54:24 -0400 Subject: [PATCH 103/108] adding tests --- terraform/ec2/mac/main.tf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/terraform/ec2/mac/main.tf b/terraform/ec2/mac/main.tf index 3791b008f..c18944f6f 100644 --- a/terraform/ec2/mac/main.tf +++ b/terraform/ec2/mac/main.tf @@ -126,6 +126,9 @@ resource "null_resource" "integration_test" { "echo Execute integration tests", "export AWS_REGION=${var.region}", "sudo chmod +x ./validator", + "cd amazon-cloudwatch-agent-test", + "git checkout MacOSEC2Test -f", + "cd ..", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:${module.validator.instance_agent_config}", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=false", From c73f8e2e02b85f0875bc9b8e6c38ce43083a1cbe Mon Sep 17 00:00:00 2001 From: Paramadon Date: Tue, 23 Apr 2024 12:42:29 -0400 Subject: [PATCH 104/108] running lint --- terraform/ec2/mac/main.tf | 3 --- test/metric/metric_value_query.go | 10 ---------- validator/main.go | 2 +- validator/validators/basic/basic_validator.go | 2 +- validator/validators/stress/stress_validator.go | 4 +--- 5 files changed, 3 insertions(+), 18 deletions(-) diff --git a/terraform/ec2/mac/main.tf b/terraform/ec2/mac/main.tf index c18944f6f..3791b008f 100644 --- a/terraform/ec2/mac/main.tf +++ b/terraform/ec2/mac/main.tf @@ -126,9 +126,6 @@ resource "null_resource" "integration_test" { "echo Execute integration tests", "export AWS_REGION=${var.region}", "sudo chmod +x ./validator", - "cd amazon-cloudwatch-agent-test", - "git checkout MacOSEC2Test -f", - "cd ..", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:${module.validator.instance_agent_config}", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=false", diff --git a/test/metric/metric_value_query.go b/test/metric/metric_value_query.go index 17505f9ea..eea358074 100644 --- a/test/metric/metric_value_query.go +++ b/test/metric/metric_value_query.go @@ -5,7 +5,6 @@ package metric import ( "context" - "encoding/json" "fmt" "log" "strings" @@ -51,15 +50,6 @@ func (n *MetricValueFetcher) Fetch(namespace, metricName string, metricSpecificD }, } - // Marshal the metricDataQueries slice into JSON with indentation - jsonData, err := json.MarshalIndent(metricDataQueries, "", " ") - if err != nil { - fmt.Println("Error marshaling JSON:", err) - } - - // Print the JSON data - fmt.Println(string(jsonData)) - endTime := time.Now() startTime := subtractMinutes(endTime, 10) getMetricDataInput := cloudwatch.GetMetricDataInput{ diff --git a/validator/main.go b/validator/main.go index bae8bdc92..545a9bac5 100644 --- a/validator/main.go +++ b/validator/main.go @@ -6,7 +6,6 @@ package main import ( "flag" "fmt" - "github.com/aws/amazon-cloudwatch-agent-test/validator/validators/basic" "log" "os" "strings" @@ -19,6 +18,7 @@ import ( "github.com/aws/amazon-cloudwatch-agent-test/util/common" "github.com/aws/amazon-cloudwatch-agent-test/validator/models" "github.com/aws/amazon-cloudwatch-agent-test/validator/validators" + "github.com/aws/amazon-cloudwatch-agent-test/validator/validators/basic" ) var ( diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 8b2a720dd..5925b568c 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -9,12 +9,12 @@ import ( "strings" "time" - apMetrics "github.com/aws/amazon-cloudwatch-agent-test/test/metric" cwtypes "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types" cwltypes "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types" "github.com/aws/aws-sdk-go/aws" "go.uber.org/multierr" + apMetrics "github.com/aws/amazon-cloudwatch-agent-test/test/metric" "github.com/aws/amazon-cloudwatch-agent-test/util/awsservice" "github.com/aws/amazon-cloudwatch-agent-test/util/common" "github.com/aws/amazon-cloudwatch-agent-test/util/common/traces" diff --git a/validator/validators/stress/stress_validator.go b/validator/validators/stress/stress_validator.go index 2c42325ca..440e821fb 100644 --- a/validator/validators/stress/stress_validator.go +++ b/validator/validators/stress/stress_validator.go @@ -406,10 +406,8 @@ func (s *StressValidator) ValidateStressMetric(metricName, metricNamespace strin // Validate if the metrics are not dropping any metrics and able to backfill within the same minute (e.g if the memory_rss metric is having collection_interval 1 // , it will need to have 60 sample counts - 1 datapoint / second) - if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, 5, 10, int32(boundAndPeriod)); !ok { + if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount-5, metricSampleCount, int32(boundAndPeriod)); !ok { return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount-5, metricSampleCount) - } else { - fmt.Println("Yayyyyyyy!!!!!!! sample count is good for :", metricName, metricSampleCount) } return nil From 90e0fd15577bf482b8c05ae37467f06c7d2b699c Mon Sep 17 00:00:00 2001 From: Paramadon Date: Wed, 24 Apr 2024 11:49:23 -0400 Subject: [PATCH 105/108] resolving all comment(cleaning up code) --- util/common/metrics.go | 27 ++-- validator/main.go | 2 - validator/validators/basic/basic_validator.go | 121 ++++++++++-------- 3 files changed, 85 insertions(+), 65 deletions(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index 61bd3c852..f84a6e85d 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -26,8 +26,11 @@ import ( "github.com/prozz/aws-embedded-metrics-golang/emf" ) -const LastSendTimeFile = "last_send_time.txt" -const MinInterval = 60 // Minimum interval in seconds +const SleepDuration = 5 * time.Second + +const TracesPort = "4316/v1/traces" +const MetricPort = "4316/v1/metrics" + // StartSendingMetrics will generate metrics load based on the receiver (e.g 5000 statsd metrics per minute) func StartSendingMetrics(receiver string, duration, sendingInterval time.Duration, metricPerInterval int, metricLogGroup, metricNamespace string) (err error) { go func() { @@ -39,9 +42,9 @@ func StartSendingMetrics(receiver string, duration, sendingInterval time.Duratio case "emf": err = SendEMFMetrics(metricPerInterval, metricLogGroup, metricNamespace, sendingInterval, duration) case "app_signals": - err = SendAppSignalMetrics() //does app signals have dimension for metric? + err = SendAppSignalMetrics(duration) //does app signals have dimension for metric? case "traces": - err = SendAppTraceMetrics(duration) //does app signals have dimension for metric? + err = SendAppSignalsTraceMetrics(duration) //does app signals have dimension for metric? default: } @@ -50,7 +53,7 @@ func StartSendingMetrics(receiver string, duration, sendingInterval time.Duratio return err } -func SendAppTraceMetrics(duration time.Duration) error { +func SendAppSignalsTraceMetrics(duration time.Duration) error { baseDir := getBaseDir() for i := 0; i < int(duration/(5*time.Second)); i++ { @@ -94,7 +97,7 @@ func processTraceFile(filePath string, startTime int64, traceID string) error { modifiedData := strings.ReplaceAll(string(data), "START_TIME", fmt.Sprintf("%d", startTime)) modifiedData = strings.ReplaceAll(modifiedData, "TRACE_ID", traceID) - url := "http://127.0.0.1:4316/v1/traces" + url := "http://127.0.0.1:" + TracesPort _, err = http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) if err != nil { return err @@ -210,7 +213,7 @@ func processFile(filePath string, startTime int64) error { modifiedData := strings.ReplaceAll(string(data), "START_TIME", fmt.Sprintf("%d", startTime)) //curl command - url := "http://127.0.0.1:4316/v1/metrics" + url := "http://127.0.0.1:" + MetricPort _, err = http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) _, err = http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) @@ -223,7 +226,7 @@ func processFile(filePath string, startTime int64) error { } -func SendAppSignalMetrics() error { +func SendAppSignalMetrics(duration time.Duration) error { // The bash script to be executed asynchronously. dir, err := os.Getwd() if err != nil { @@ -235,12 +238,14 @@ func SendAppSignalMetrics() error { // Determine the base directory for the files based on the OS var baseDir string if runtime.GOOS == "windows" { - baseDir = "C:\\Users\\Administrator\\amazon-cloudwatch-agent-test\\test\\app_signals\\resources\\metrics" + baseDir = filepath.Join("C:", "Users", "Administrator", "amazon-cloudwatch-agent-test", "test", "app_signals", "resources", "metrics") } else { // assuming macOS or Unix-like system - baseDir = "/Users/ec2-user/amazon-cloudwatch-agent-test/test/app_signals/resources/metrics" + baseDir = filepath.Join("/", "Users", "ec2-user", "amazon-cloudwatch-agent-test", "test", "app_signals", "resources", "metrics") } - for i := 0; i < 12; i++ { + fmt.Println("Base directory:", baseDir) + + for i := 0; i < int(duration/SleepDuration); i++ { if err != nil { return err } diff --git a/validator/main.go b/validator/main.go index 545a9bac5..7395e5dab 100644 --- a/validator/main.go +++ b/validator/main.go @@ -18,7 +18,6 @@ import ( "github.com/aws/amazon-cloudwatch-agent-test/util/common" "github.com/aws/amazon-cloudwatch-agent-test/validator/models" "github.com/aws/amazon-cloudwatch-agent-test/validator/validators" - "github.com/aws/amazon-cloudwatch-agent-test/validator/validators/basic" ) var ( @@ -80,7 +79,6 @@ func main() { func validate(vConfig models.ValidateConfig) error { var err error for i := 0; i < awsservice.StandardRetries; i++ { - basic.RetryCount = i + 1 err = validators.LaunchValidator(vConfig) if err == nil { diff --git a/validator/validators/basic/basic_validator.go b/validator/validators/basic/basic_validator.go index 5925b568c..67fad58cf 100644 --- a/validator/validators/basic/basic_validator.go +++ b/validator/validators/basic/basic_validator.go @@ -14,7 +14,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "go.uber.org/multierr" - apMetrics "github.com/aws/amazon-cloudwatch-agent-test/test/metric" + AppSignalMetrics "github.com/aws/amazon-cloudwatch-agent-test/test/metric" "github.com/aws/amazon-cloudwatch-agent-test/util/awsservice" "github.com/aws/amazon-cloudwatch-agent-test/util/common" "github.com/aws/amazon-cloudwatch-agent-test/util/common/traces" @@ -23,12 +23,12 @@ import ( ) const metricErrorBound = 0.1 +const AppSignalNamespace = "AppSignals" type BasicValidator struct { vConfig models.ValidateConfig } -var RetryCount = 1 var _ models.ValidatorFactory = (*BasicValidator)(nil) func NewBasicValidator(vConfig models.ValidateConfig) models.ValidatorFactory { @@ -39,7 +39,7 @@ func NewBasicValidator(vConfig models.ValidateConfig) models.ValidatorFactory { func (s *BasicValidator) GenerateLoad() error { var ( - metricSendingInterval = 10 * time.Second + metricSendingInterval = time.Minute logGroup = awsservice.GetInstanceId() metricNamespace = s.vConfig.GetMetricNamespace() dataRate = s.vConfig.GetDataRate() @@ -70,75 +70,46 @@ func (s *BasicValidator) CheckData(startTime, endTime time.Time) error { ) for _, metric := range validationMetric { - metricDimensions := []cwtypes.Dimension{ - { - Name: aws.String("InstanceId"), - Value: aws.String(ec2InstanceId), - }, + metricDimensions := []cwtypes.Dimension{} + //App Signal Metrics don't have instanceid dimension + if !isAppSignalMetric(metric) { + metricDimensions = []cwtypes.Dimension{ + { + Name: aws.String("InstanceId"), + Value: aws.String(ec2InstanceId), + }, + } } + for _, dimension := range metric.MetricDimension { metricDimensions = append(metricDimensions, cwtypes.Dimension{ Name: aws.String(dimension.Name), Value: aws.String(dimension.Value), }) } - environmentValue := "Generic" - operationValue := "operation" - serviceValue := "service-name" - - appSignalDimensions := []cwtypes.Dimension{ - { - Name: aws.String("HostedIn.Environment"), - Value: aws.String(environmentValue), - }, - { - Name: aws.String("Operation"), - Value: aws.String(operationValue), - }, - { - Name: aws.String("Service"), - Value: aws.String(serviceValue), - }, - } //App Signals metric testing (This is because we want to use a different checking method (same that was done for linux test)) if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { - fetcher := apMetrics.MetricValueFetcher{} - values, err := fetcher.Fetch("AppSignals", metric.MetricName, appSignalDimensions, "Sum", 60) + err := s.ValidateAppSignalMetrics(metric, metricDimensions) if err != nil { multiErr = multierr.Append(multiErr, err) - } - if !apMetrics.IsAllValuesGreaterThanOrEqualToExpectedValue(metric.MetricName, values, 0) { - fmt.Printf("Error values are not the epected values%v", err) - multiErr = multierr.Append(multiErr, fmt.Errorf("Incorrect Metric values ")) + } else { + fmt.Println("App Signal Metrics are correct!") } } else { err := s.ValidateMetric(metric.MetricName, metricNamespace, metricDimensions, metric.MetricValue, metric.MetricSampleCount, startTime, endTime) if err != nil { - multiErr = multierr.Append(multiErr, err) - } - } - lookbackDuration := time.Duration(-5) * time.Minute - serviceName := "service-name" - serviceType := "AWS::EC2::Instance" - //filtering traces - filterExpression := fmt.Sprintf("(service(id(name: \"%s\", type: \"%s\")))", serviceName, serviceType) - timeNow := time.Now() - - traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, filterExpression) - if err != nil { - fmt.Printf("error getting trace ids: %v", err) - multiErr = multierr.Append(multiErr, err) - } else { - fmt.Printf("Trace IDs: %v\n", traceIds) - if len(traceIds) > 0 { - fmt.Println("Trace IDs look good") - } else { - multiErr = multierr.Append(multiErr, fmt.Errorf("no trace IDs found")) + return err } } } + err := s.ValidateTracesMetrics() + if err != nil { + multiErr = multierr.Append(multiErr, err) + } else { + fmt.Println("Traces Metrics are correct!") + } for _, logValidation := range logValidations { err := s.ValidateLogs(logValidation.LogStream, logValidation.LogValue, logValidation.LogLevel, logValidation.LogSource, logValidation.LogLines, startTime, endTime) if err != nil { @@ -162,6 +133,52 @@ func (s *BasicValidator) Cleanup() error { return nil } +func isAppSignalMetric(metric models.MetricValidation) bool { + if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { + return true + } + return false +} +func (s *BasicValidator) ValidateAppSignalMetrics(metric models.MetricValidation, metricDimensions []cwtypes.Dimension) error { + + if metric.MetricName == "Latency" || metric.MetricName == "Fault" || metric.MetricName == "Error" { + fetcher := AppSignalMetrics.MetricValueFetcher{} + values, err := fetcher.Fetch(AppSignalNamespace, metric.MetricName, metricDimensions, "Sum", 60) + if err != nil { + return err + } + if !AppSignalMetrics.IsAllValuesGreaterThanOrEqualToExpectedValue(metric.MetricName, values, 0) { + fmt.Printf("Error values are not the epected values%v", err) + return err + } + } + + return nil +} + +func (s *BasicValidator) ValidateTracesMetrics() error { + lookbackDuration := time.Duration(-5) * time.Minute + serviceName := "service-name" + serviceType := "AWS::EC2::Instance" + //filtering traces + filterExpression := fmt.Sprintf("(service(id(name: \"%s\", type: \"%s\")))", serviceName, serviceType) + timeNow := time.Now() + + traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, filterExpression) + if err != nil { + fmt.Printf("error getting trace ids: %v", err) + return err + } else { + fmt.Printf("Trace IDs: %v\n", traceIds) + if len(traceIds) > 0 { + fmt.Println("Trace IDs look good") + } else { + return err + } + } + return nil +} + func (s *BasicValidator) ValidateLogs(logStream, logLine, logLevel, logSource string, expectedMinimumEventCount int, startTime, endTime time.Time) error { logGroup := awsservice.GetInstanceId() log.Printf("Start to validate that substring '%s' has at least %d log event(s) within log group %s, log stream %s, between %v and %v", logLine, expectedMinimumEventCount, logGroup, logStream, startTime, endTime) From c1bef9c7aa959edcf510737b0c9c6194b9874d32 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Wed, 24 Apr 2024 12:30:53 -0400 Subject: [PATCH 106/108] testing --- terraform/ec2/mac/main.tf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/terraform/ec2/mac/main.tf b/terraform/ec2/mac/main.tf index 3791b008f..c18944f6f 100644 --- a/terraform/ec2/mac/main.tf +++ b/terraform/ec2/mac/main.tf @@ -126,6 +126,9 @@ resource "null_resource" "integration_test" { "echo Execute integration tests", "export AWS_REGION=${var.region}", "sudo chmod +x ./validator", + "cd amazon-cloudwatch-agent-test", + "git checkout MacOSEC2Test -f", + "cd ..", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:${module.validator.instance_agent_config}", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=false", From 6f2689f6a9bc61842d9c4690c30753ebf28904e1 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Wed, 24 Apr 2024 13:52:23 -0400 Subject: [PATCH 107/108] Test is passing --- terraform/ec2/mac/main.tf | 3 --- 1 file changed, 3 deletions(-) diff --git a/terraform/ec2/mac/main.tf b/terraform/ec2/mac/main.tf index c18944f6f..3791b008f 100644 --- a/terraform/ec2/mac/main.tf +++ b/terraform/ec2/mac/main.tf @@ -126,9 +126,6 @@ resource "null_resource" "integration_test" { "echo Execute integration tests", "export AWS_REGION=${var.region}", "sudo chmod +x ./validator", - "cd amazon-cloudwatch-agent-test", - "git checkout MacOSEC2Test -f", - "cd ..", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:${module.validator.instance_agent_config}", "./validator --validator-config=${module.validator.instance_validator_config} --preparation-mode=false", From 5109add42ea3a20fbb2a66fc74eafea18c746582 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Mon, 29 Apr 2024 17:36:17 -0400 Subject: [PATCH 108/108] changing var name --- util/common/metrics.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/common/metrics.go b/util/common/metrics.go index f84a6e85d..bf9435f8a 100644 --- a/util/common/metrics.go +++ b/util/common/metrics.go @@ -28,8 +28,8 @@ import ( const SleepDuration = 5 * time.Second -const TracesPort = "4316/v1/traces" -const MetricPort = "4316/v1/metrics" +const TracesEndpoint = "4316/v1/traces" +const MetricEndpoint = "4316/v1/metrics" // StartSendingMetrics will generate metrics load based on the receiver (e.g 5000 statsd metrics per minute) func StartSendingMetrics(receiver string, duration, sendingInterval time.Duration, metricPerInterval int, metricLogGroup, metricNamespace string) (err error) { @@ -97,7 +97,7 @@ func processTraceFile(filePath string, startTime int64, traceID string) error { modifiedData := strings.ReplaceAll(string(data), "START_TIME", fmt.Sprintf("%d", startTime)) modifiedData = strings.ReplaceAll(modifiedData, "TRACE_ID", traceID) - url := "http://127.0.0.1:" + TracesPort + url := "http://127.0.0.1:" + TracesEndpoint _, err = http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) if err != nil { return err @@ -213,7 +213,7 @@ func processFile(filePath string, startTime int64) error { modifiedData := strings.ReplaceAll(string(data), "START_TIME", fmt.Sprintf("%d", startTime)) //curl command - url := "http://127.0.0.1:" + MetricPort + url := "http://127.0.0.1:" + MetricEndpoint _, err = http.Post(url, "application/json", bytes.NewBufferString(modifiedData)) _, err = http.Post(url, "application/json", bytes.NewBufferString(modifiedData))