Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always send reports, even with no metrics PRD-492 #203

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions judoscale-ruby/lib/judoscale/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,17 @@ def stop!
@_thread&.terminate
@_thread = nil
@pid = nil
@reported = false
end

private

def report(config, metrics)
# Make sure we report at least once, even if there are no metrics,
# so Judoscale knows the adapter is installed and running.
if @reported && metrics.empty?
logger.debug "No metrics to report - skipping"
return
end

report = Report.new(Judoscale.adapters, config, metrics)
logger.info "Reporting #{report.metrics.size} metrics"
result = AdapterApi.new(config).report_metrics(report.as_json)

case result
when AdapterApi::SuccessResponse
@reported = true
logger.debug "Reported successfully"
when AdapterApi::FailureResponse
logger.error "Reporter failed: #{result.failure_message}"
Expand Down
20 changes: 4 additions & 16 deletions judoscale-ruby/test/reporter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ module Judoscale
Judoscale.configure do |config|
config.current_runtime_container = Config::RuntimeContainer.new("web.1")
config.api_base_url = "http://example.com/api/test-token"
config.test_job_config.enabled = true
end
}

after { Reporter.instance.stop! }

describe ".start" do
it "initializes the reporter with the current configuration and loaded adapters" do
reporter_mock = Minitest::Mock.new
Expand All @@ -42,6 +39,10 @@ module Judoscale
end

describe "#start!" do
after {
Reporter.instance.stop!
}

def run_reporter_start_thread
stub_reporter_loop {
reporter_thread = Reporter.instance.start!(Config.instance, Judoscale.adapters)
Expand Down Expand Up @@ -171,19 +172,6 @@ def stub_reporter_loop
assert_requested stub
end

it "only sends an empty (no metrics) report one time" do
metrics_collector = Test::TestEmptyMetricsCollector.new

expected_body = Report.new(Judoscale.adapters, Config.instance, metrics_collector.collect).as_json
stub = stub_request(:post, "http://example.com/api/test-token/v3/reports")
.with(body: JSON.generate(expected_body)).to_return({status: 200}).times(1)

Reporter.instance.run_metrics_collection Config.instance, [metrics_collector]
Reporter.instance.run_metrics_collection Config.instance, [metrics_collector]

assert_requested stub
end

it "logs reporting failures" do
metrics_collector = Test::TestWebMetricsCollector.new

Expand Down
6 changes: 0 additions & 6 deletions judoscale-ruby/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ def collect
[Metric.new(:qt, 1, Time.now)]
end
end

class TestEmptyMetricsCollector < Judoscale::WebMetricsCollector
def collect
[]
end
end
end

add_adapter :test_web, {}, metrics_collector: Test::TestWebMetricsCollector
Expand Down