@@ -73,11 +73,10 @@ delete_stack() {
73
73
fi
74
74
}
75
75
76
- validate_stack_resources () {
76
+ validate_stack_resources_with_subscription () {
77
77
local stack_name=$1
78
- local validate_only_firehose_stack=$2
79
- local log_group_name=$3
80
- local log_group_filter=$4
78
+ local log_group_name=$2
79
+ local log_group_filter=$3
81
80
82
81
83
82
log " Validating stack resources for stack: $stack_name "
@@ -100,12 +99,6 @@ validate_stack_resources() {
100
99
exit_with_error " Failed to retrieve Firehose delivery stream ARN for physical ID: $firehose_stream_physical_id "
101
100
fi
102
101
103
- # Skip log group subscription validation if validate_only_firehose_stack is true or log_group_filter is empty
104
- if [ " $validate_only_firehose_stack " == " true" ] || [ -z " $log_group_filter " ]; then
105
- log " Validated Firehose Stream, skipping log group subscription validation."
106
- return
107
- fi
108
-
109
102
subscriptions=$( aws logs describe-subscription-filters --log-group-name " $log_group_name " --query ' subscriptionFilters[*].[destinationArn, filterPattern]' --output text)
110
103
111
104
# Check if the Firehose delivery stream is subscribed to the log group with the specified filter pattern
@@ -117,105 +110,34 @@ validate_stack_resources() {
117
110
118
111
}
119
112
113
+ validate_stack_resources_without_subscription () {
114
+ local stack_name=$1
115
+ local log_group_name=$2
120
116
121
- exit_with_error () {
122
- echo " Error: $1 "
123
- exit 1
124
- }
125
-
126
- create_log_event () {
127
- local log_group_name=$1
128
- local log_stream_name=$2
129
- local log_message=$3
130
-
131
- log " Creating log event in CloudWatch Log Group: $log_group_name "
132
- local log_stream_exists=$( aws logs describe-log-streams --log-group-name " $log_group_name " --log-stream-name-prefix " $log_stream_name " --query " logStreams[?logStreamName=='$log_stream_name '] | length(@)" --output text)
133
-
134
- if [ " $log_stream_exists " -eq 0 ]; then
135
- log " Creating log stream: $log_stream_name "
136
- aws logs create-log-stream --log-group-name " $log_group_name " --log-stream-name " $log_stream_name "
137
- fi
138
-
139
- # Get the current timestamp in milliseconds
140
- timestamp=$(( $(date +% s) * 1000 + $(date +% N) / 1000000 ))
141
-
142
- # Put log event
143
- aws logs put-log-events \
144
- --log-group-name " $log_group_name " \
145
- --log-stream-name " $log_stream_name " \
146
- --log-events timestamp=$timestamp ,message=" $log_message "
147
-
148
- log " Log event created successfully."
149
117
150
- }
118
+ log " Validating stack resources for stack: $stack_name "
119
+ firehose_stream_physical_id=$( aws cloudformation describe-stack-resources \
120
+ --stack-name " $stack_name " \
121
+ --logical-resource-id " $FIREHOSE_STREAM_LOGICAL_ID " \
122
+ --query " StackResources[0].PhysicalResourceId" \
123
+ --output text
124
+ )
151
125
152
- validate_logs_in_new_relic () {
153
- local user_key=$1
154
- local account_id=$2
155
- local log_message=$3
156
- local common_attributes=$4
157
- local should_log_exist=$5
158
-
159
- local nrql_query=" SELECT * FROM Log WHERE message LIKE '%$log_message %' SINCE 10 minutes ago"
160
- local query=' {"query":"query($id: Int!, $nrql: Nrql!) { actor { account(id: $id) { nrql(query: $nrql) { results } } } }","variables":{"id":' $account_id ' ,"nrql":"' $nrql_query ' "}}'
161
-
162
- local log_message_exists=false
163
-
164
- sleep_time=$SLEEP_TIME
165
-
166
- for i in {1..5}; do
167
- local response=$( curl -s -X POST \
168
- -H " Content-Type: application/json" \
169
- -H " API-Key: $user_key " \
170
- -d " $query " \
171
- https://api.newrelic.com/graphql)
172
-
173
- if echo " $response " | grep -q " $log_message " ; then
174
- log " Log event successfully found in New Relic."
175
- log_message_exists=true
176
- validate_logs_meta_data " $response " " $common_attributes "
177
- break
178
- else
179
- log " Log event not found in New Relic. Retrying in $sleep_time seconds..."
180
- sleep $sleep_time
181
- sleep_time=$(( sleep_time * 2 ))
182
- fi
183
- done
126
+ # Get the ARN of the Firehose delivery stream using the physical ID
127
+ firehose_stream_arn=$( aws firehose describe-delivery-stream \
128
+ --delivery-stream-name " $firehose_stream_physical_id " \
129
+ --query " DeliveryStreamDescription.DeliveryStreamARN" \
130
+ --output text
131
+ )
184
132
185
- if [ " $should_log_exist " == " true" ] && [ " $log_message_exists " == " false" ]; then
186
- exit_with_error " Log event not found in New Relic after 10 retries."
187
- elif [ " $should_log_exist " == " false" ] && [ " $log_message_exists " == " true" ]; then
188
- exit_with_error " Log event should not exist in New Relic, but it was found."
133
+ # Check firehose_stream_arn is not null
134
+ if [ -z " $firehose_stream_arn " ] || [ " $firehose_stream_arn " == " None" ]; then
135
+ exit_with_error " Failed to retrieve Firehose delivery stream ARN for physical ID: $firehose_stream_physical_id "
189
136
fi
190
-
191
137
}
192
138
193
- validate_logs_meta_data (){
194
- local response=$1
195
- local common_attributes=$2
196
-
197
- # Remove single quotes from common_attributes
198
- common_attributes=$( echo " $common_attributes " | sed " s/'//g" )
199
-
200
- # Validate common attributes
201
- for attribute in $( echo " $common_attributes " | jq -c ' .[]' ) ; do
202
- attribute_name=$( echo " $attribute " | jq -r ' .AttributeName' )
203
- attribute_value=$( echo " $attribute " | jq -r ' .AttributeValue' )
204
- if ! echo " $response " | grep -q " \" $attribute_name \" :\" $attribute_value \" " ; then
205
- exit_with_error " Common attribute $attribute_name with value $attribute_value not found in New Relic logs."
206
- fi
207
- done
208
- log " Common attributes validated successfully."
209
-
210
- # Read default attributes from config file and replace underscores with dots
211
- while IFS=' =' read -r key value; do
212
- if [[ $key == instrumentation_* ]]; then
213
- new_key=$( echo " $key " | sed ' s/_/./g' )
214
- if ! echo " $response " | grep -q " \" $new_key \" :\" $value \" " ; then
215
- exit_with_error " Entity synthesis attribute $new_key with value $value not found in New Relic logs."
216
- fi
217
- fi
218
- done < config-file.cfg
219
139
220
- log " Entity synthesis parameter validated successfully."
140
+ exit_with_error () {
141
+ echo " Error: $1 "
142
+ exit 1
221
143
}
0 commit comments