diff --git a/elasticgraph-indexer_autoscaler_lambda/lib/elastic_graph/indexer_autoscaler_lambda/concurrency_scaler.rb b/elasticgraph-indexer_autoscaler_lambda/lib/elastic_graph/indexer_autoscaler_lambda/concurrency_scaler.rb index f7f25010..ed36c1be 100644 --- a/elasticgraph-indexer_autoscaler_lambda/lib/elastic_graph/indexer_autoscaler_lambda/concurrency_scaler.rb +++ b/elasticgraph-indexer_autoscaler_lambda/lib/elastic_graph/indexer_autoscaler_lambda/concurrency_scaler.rb @@ -22,7 +22,7 @@ def initialize(datastore_core:, sqs_client:, lambda_client:, cloudwatch_client:) MINIMUM_CONCURRENCY = 2 - def tune_indexer_concurrency(queue_urls:, min_cpu_target:, max_cpu_target:, maximum_concurrency:, minimum_free_storage:, indexer_function_name:) + def tune_indexer_concurrency(queue_urls:, min_cpu_target:, max_cpu_target:, maximum_concurrency:, minimum_free_storage:, indexer_function_name:, cluster_name:) queue_attributes = get_queue_attributes(queue_urls) queue_arns = queue_attributes.fetch(:queue_arns) num_messages = queue_attributes.fetch(:total_messages) @@ -38,7 +38,7 @@ def tune_indexer_concurrency(queue_urls:, min_cpu_target:, max_cpu_target:, maxi new_target_concurrency = if num_messages.positive? - free_storage = get_min_free_storage + free_storage = get_min_free_storage(cluster_name) cpu_utilization = get_max_cpu_utilization cpu_midpoint = (max_cpu_target + min_cpu_target) / 2.0 @@ -103,14 +103,14 @@ def get_max_cpu_utilization end.max.to_f end - def get_min_free_storage + def get_min_free_storage(cluster_name) metric_response = @cloudwatch_client.get_metric_data({ - start_time: ::Time.now - 900, # past 15 minutes + start_time: ::Time.now - 1200, # past 20 minutes end_time: ::Time.now, metric_data_queries: [ { id: "minFreeStorageAcrossNodes", - expression: "SEARCH('{AWS/ES,ClientId,DomainName,NodeId} MetricName=\"FreeStorageSpace\"', 'Minimum', 30)", + expression: "SEARCH('{AWS/ES,ClientId,DomainName} MetricName=\"FreeStorageSpace\" AND DomainName=\"#{cluster_name}\"', 'Minimum', 60)", return_data: true } ] diff --git a/elasticgraph-indexer_autoscaler_lambda/lib/elastic_graph/indexer_autoscaler_lambda/lambda_function.rb b/elasticgraph-indexer_autoscaler_lambda/lib/elastic_graph/indexer_autoscaler_lambda/lambda_function.rb index 7a277347..357b64cb 100644 --- a/elasticgraph-indexer_autoscaler_lambda/lib/elastic_graph/indexer_autoscaler_lambda/lambda_function.rb +++ b/elasticgraph-indexer_autoscaler_lambda/lib/elastic_graph/indexer_autoscaler_lambda/lambda_function.rb @@ -27,7 +27,8 @@ def handle_request(event:, context:) max_cpu_target: event.fetch("max_cpu_target"), maximum_concurrency: event.fetch("maximum_concurrency"), minimum_free_storage: event.fetch("minimum_free_storage"), - indexer_function_name: event.fetch("indexer_function_name") + indexer_function_name: event.fetch("indexer_function_name"), + cluster_name: event.fetch("cluster_name") ) end end diff --git a/elasticgraph-indexer_autoscaler_lambda/sig/elastic_graph/idexer_autoscaler_lambda/concurrency_scaler.rbs b/elasticgraph-indexer_autoscaler_lambda/sig/elastic_graph/idexer_autoscaler_lambda/concurrency_scaler.rbs index 32f6ce47..aae45cef 100644 --- a/elasticgraph-indexer_autoscaler_lambda/sig/elastic_graph/idexer_autoscaler_lambda/concurrency_scaler.rbs +++ b/elasticgraph-indexer_autoscaler_lambda/sig/elastic_graph/idexer_autoscaler_lambda/concurrency_scaler.rbs @@ -16,7 +16,8 @@ module ElasticGraph max_cpu_target: ::Integer, maximum_concurrency: ::Integer, minimum_free_storage: ::Integer, - indexer_function_name: ::String + indexer_function_name: ::String, + cluster_name: ::String ) -> void private @@ -28,7 +29,7 @@ module ElasticGraph @cloudwatch_client: Aws::CloudWatch::Client def get_max_cpu_utilization: () -> ::Float - def get_min_free_storage: () -> ::Float + def get_min_free_storage: (::String) -> ::Float def get_queue_attributes: (::Array[::String]) -> { total_messages: ::Integer, queue_arns: ::Array[::String] } def get_concurrency: (::String) -> ::Integer? diff --git a/elasticgraph-indexer_autoscaler_lambda/spec/unit/elastic_graph/indexer_autoscaler_lambda/concurrency_scaler_spec.rb b/elasticgraph-indexer_autoscaler_lambda/spec/unit/elastic_graph/indexer_autoscaler_lambda/concurrency_scaler_spec.rb index 275e8f0d..e985da1c 100644 --- a/elasticgraph-indexer_autoscaler_lambda/spec/unit/elastic_graph/indexer_autoscaler_lambda/concurrency_scaler_spec.rb +++ b/elasticgraph-indexer_autoscaler_lambda/spec/unit/elastic_graph/indexer_autoscaler_lambda/concurrency_scaler_spec.rb @@ -279,7 +279,8 @@ def tune_indexer_concurrency(concurrency_scaler) max_cpu_target: max_cpu_target, maximum_concurrency: maximum_concurrency, minimum_free_storage: minimum_free_storage, - indexer_function_name: indexer_function_name + indexer_function_name: indexer_function_name, + cluster_name: "some-eg-cluster" ) end end diff --git a/elasticgraph-indexer_autoscaler_lambda/spec/unit/elastic_graph/indexer_autoscaler_lambda/lambda_function_spec.rb b/elasticgraph-indexer_autoscaler_lambda/spec/unit/elastic_graph/indexer_autoscaler_lambda/lambda_function_spec.rb index 27464cd6..eacaec44 100644 --- a/elasticgraph-indexer_autoscaler_lambda/spec/unit/elastic_graph/indexer_autoscaler_lambda/lambda_function_spec.rb +++ b/elasticgraph-indexer_autoscaler_lambda/spec/unit/elastic_graph/indexer_autoscaler_lambda/lambda_function_spec.rb @@ -41,6 +41,7 @@ "max_cpu_target" => 80, "maximum_concurrency" => 1000, "minimum_free_storage" => 100, + "cluster_name" => "some-eg-cluster", "indexer_function_name" => "some-eg-app-indexer" } lambda_function.handle_request(event: event, context: {})