Skip to content

Commit

Permalink
add a healthcheck endpoint to frontend-ruby
Browse files Browse the repository at this point in the history
* adds a HEALTHCHECK command to the Dockerfile so that Docker
  will nag the healthcheck endpoint
* adds OTel instrumentation config to ignore healthcheck endpoint
  (doesn't generate traces for requests to /up)
  • Loading branch information
robbkidd committed Apr 2, 2024
1 parent 619d38e commit 4b01666
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ruby/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ COPY frontend.ru /myapp
COPY o11y_wrapper.rb /myapp

EXPOSE 7777

HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "curl", "--fail", "http://localhost:7777/up" ]
CMD [ "bundle", "exec", "rackup", "frontend.ru", "--server", "puma", "--host", "0.0.0.0"]
16 changes: 14 additions & 2 deletions ruby/frontend/frontend.ru
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ begin
OpenTelemetry::SDK.configure do |c|
c.service_name = ENV['SERVICE_NAME'] || "frontend-ruby"

# enable all auto-instrumentation available
c.use_all()
# enable all instrumentation libraries installed in the Gemfile
# and configure some
c.use_all({
'OpenTelemetry::Instrumentation::Rack' => {
untraced_endpoints: ['/up'], # don't create traces for healthchecks
},
})

# add the Baggage and CarryOn processors to thepipeline
c.add_span_processor(O11yWrapper::BaggageSpanProcessor.new)
Expand Down Expand Up @@ -49,10 +54,17 @@ class FrontendGreetingApp < Rails::Application
Rails.logger = config.logger

routes.append do
get "/up" => "health#show"
get "/greeting" => "greetings#index"
end
end

class HealthController < ActionController::Base
def show
render plain: "ok"
end
end

class GreetingsController < ActionController::Base
around_action :context_for_named_visitor

Expand Down

0 comments on commit 4b01666

Please sign in to comment.