NoMethodError: undefined method `ping' for nil:NilClass
Description
prometheus_client
can be a nil
object from L103.
So when we test the connection L96, it fails with a NoMethodError
.
Implementation Guide
There are two options:
- Return an object that implements the
ping
method, following the Null Object Pattern. - Include
NoMethodError
in the rescue or catch a more generic error, likeStandardError
to include this possible error.
When a user hits Test integration for Prometheus, occasionally this issue occurs. If the URL for the connection is not correct, it is failing (probably as 500 error for the user).
Backtrace
https://sentry.gitlab.net/gitlab/gitlabcom/issues/3190063/?referrer=gitlab_plugin
NoMethodError: undefined method `ping' for nil:NilClass
app/models/integrations/prometheus.rb:96:in `test'
prometheus_client.ping
app/services/integrations/test/base_service.rb:26:in `execute'
integration.test(data)
app/controllers/projects/services_controller.rb:77:in `service_test_response'
result = ::Integrations::Test::ProjectService.new(integration, current_user, params[:event]).execute
app/controllers/projects/services_controller.rb:60:in `test'
render json: service_test_response, status: :ok
app/controllers/application_controller.rb:520:in `set_current_admin'
return yield unless Gitlab::CurrentSettings.admin_mode
...
(153 additional frame(s) were not displayed)
Edited by Grant Hickman