From 24cc811d89c78501bcfaa4aa721aa61a6238bf4d Mon Sep 17 00:00:00 2001 From: Brad Buchanan Date: Wed, 12 Sep 2018 11:45:57 -0700 Subject: [PATCH 1/2] Set unit when sending NetSim metrics Sets the appropriate unit when sending NetSim metrics to Cloudwatch. In this particular case, our unit is always either "Count" or "Bytes". See [the docs](https://docs.aws.amazon.com/sdkforruby/api/Aws/CloudWatch/Types/MetricDatum.html#unit-instance_method) for possible values to the `:unit` parameter. --- shared/middleware/net_sim_api.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shared/middleware/net_sim_api.rb b/shared/middleware/net_sim_api.rb index 09bd14bc6b788..ab097a0853f6b 100644 --- a/shared/middleware/net_sim_api.rb +++ b/shared/middleware/net_sim_api.rb @@ -225,7 +225,7 @@ def owns_shard?(shard_id) # Block request if payload is unusually large. if body_string.length > MAX_REQUEST_SIZE - record_metric("InsertTooLarge_#{table_name}", body_string.length) + record_metric("InsertTooLarge_#{table_name}", body_string.length, 'Bytes') too_large end @@ -251,7 +251,7 @@ def owns_shard?(shard_id) table = get_table(shard_id, table_name) result = values.map {|value| table.insert(value, request.ip)} - record_metric("InsertBytes_#{table_name}", body_string.length) + record_metric("InsertBytes_#{table_name}", body_string.length, 'Bytes') record_metric("InsertRows_#{table_name}", values.count) # Finally, if we are not performing a multi-insert, denormalize our @@ -355,7 +355,7 @@ def validate_wire(shard_id, wire) # Block request if payload is unusually large. if body_string.length > MAX_REQUEST_SIZE - record_metric("UpdateTooLarge_#{table_name}", body_string.length) + record_metric("UpdateTooLarge_#{table_name}", body_string.length, 'Bytes') too_large end @@ -369,7 +369,7 @@ def validate_wire(shard_id, wire) json_bad_request end - record_metric("UpdateBytes_#{table_name}", body_string.length) + record_metric("UpdateBytes_#{table_name}", body_string.length, 'Bytes') dont_cache content_type :json @@ -504,7 +504,7 @@ def delete_messages_for_nodes(shard_id, node_ids) # @param [String] event_type - unique metric key within NetSimApi # @param [Number] value (default 1) value of measurement, omit if we only care # about event counts. - def record_metric(event_type, value = 1) + def record_metric(event_type, value = 1, unit = 'Count') return unless CDO.netsim_enable_metrics Cdo::Metrics.push('NetSimApi', [ From 83e67b144ecbf4b1295cefaada026e5f652ad6f8 Mon Sep 17 00:00:00 2001 From: Brad Buchanan Date: Wed, 12 Sep 2018 14:33:34 -0700 Subject: [PATCH 2/2] Param comment [ci skip] --- shared/middleware/net_sim_api.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shared/middleware/net_sim_api.rb b/shared/middleware/net_sim_api.rb index ab097a0853f6b..89dbfb8cd0d7f 100644 --- a/shared/middleware/net_sim_api.rb +++ b/shared/middleware/net_sim_api.rb @@ -504,6 +504,8 @@ def delete_messages_for_nodes(shard_id, node_ids) # @param [String] event_type - unique metric key within NetSimApi # @param [Number] value (default 1) value of measurement, omit if we only care # about event counts. + # @param [String] unit (default 'Count') unit of measurement. For allowed units, + # see https://docs.aws.amazon.com/sdkforruby/api/Aws/CloudWatch/Types/MetricDatum.html#unit-instance_method def record_metric(event_type, value = 1, unit = 'Count') return unless CDO.netsim_enable_metrics Cdo::Metrics.push('NetSimApi',