Skip to content

Commit

Permalink
add domain name to search expression
Browse files Browse the repository at this point in the history
  • Loading branch information
akumar1214 committed Nov 6, 2024
1 parent 008fb13 commit 97aa51e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {})
Expand Down

0 comments on commit 97aa51e

Please sign in to comment.