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

Create simple HTTP-logging middleware #28

Merged
merged 1 commit into from
Aug 11, 2020
Merged

Create simple HTTP-logging middleware #28

merged 1 commit into from
Aug 11, 2020

Conversation

JoelQ
Copy link
Contributor

@JoelQ JoelQ commented Aug 11, 2020

🧰 What's being changed?

This creates a simple middleware that logs requests received to the
given logging API endpoint in the format: "GET http://example.com".

The actual Readme.io payload format is more complicated than this. We
will add support for it in a follow-up commit.

🧪 Testing

There is an automated test using Rspec and Rack::Test. We also tested manually with a simple Rack application that acts as both the client API and the Readme API:

# config.ru
$LOAD_PATH << File.expand_path("../path/to/metrics-sdks/packages/ruby/lib", __FILE__)
require "readme/metrics"

class ApiApp
  def call(env)
    puts "=== API ==="
    [200, {}, ["Ok"]]
  end
end

class ReadmeApp
  def call(env)
    puts "=== README ==="
    puts env['rack.input'].read
    [200, {}, ["Ok"]]
  end
end

map "/readme" do |builder|
  run ReadmeApp.new
end

map "/api" do
  use Readme::Metrics, "http://localhost:9292/readme"
  run ApiApp.new
end

Run this on the command-line with

$ rackup

Then try to hit one of the "client API" endpoints:

$ curl http://localhost:9292/api/path/to/thing

In the server logs of the rack application, you should expect to see:

Webcam 2020-08-11 11-01-46

Copy link
Member

@erunion erunion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm as a solid framework for the coming work!

Copy link

@joshuaclayton joshuaclayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple minor/perhaps anticipatory comments around future changes, but this looks great!

This creates a simple middleware that logs requests received to the
given logging API endpoint in the format: `"GET http://example.com"`.

The actual Readme.io payload format is more complicated than this. We
will add support for it in a follow-up commit.

When comparing Rack mock responses to real ones, we needed to convert to
the raw status, headers, body triple ourselves since there isn't a
built-in method to do so and we needed a way to compare against the real
triple.

_Note that Rack::MockResponse converts the array body into a
single string for ease of testing so we had to convert back to an array
as part of destructuring._
@JoelQ JoelQ merged commit 7fd3c24 into master Aug 11, 2020
@JoelQ JoelQ deleted the echo branch August 11, 2020 19:12
djmango pushed a commit to djmango/metrics-sdks that referenced this pull request Sep 19, 2023
* chore: Bump eslint from 6.7.2 to 6.8.0

Bumps [eslint](https://github.com/eslint/eslint) from 6.7.2 to 6.8.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](eslint/eslint@v6.7.2...v6.8.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* style: require-atomic-updates is no longer part of eslint/rec

Co-authored-by: Jon Ursenbach <[email protected]>
@erunion erunion added ruby Issues related to our Ruby SDK and removed area:ruby labels Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ruby Issues related to our Ruby SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants