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

Remove JSON exposition format support #18

Merged
merged 1 commit into from
Jan 12, 2016
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
6 changes: 1 addition & 5 deletions examples/rack/run
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ installed() {
which $1 > /dev/null
}

pretty_json() {
ruby -e "require 'json'; puts JSON.pretty_generate(JSON.load(STDIN))"
}

fatal() {
echo >&2 $1
exit 1
Expand Down Expand Up @@ -39,4 +35,4 @@ sleep 1
printf "GET ${URL}\nPOST ${URL}\nDELETE ${URL}" | vegeta attack &>> /dev/null

# output the result
curl -s "${URL}metrics" | pretty_json
curl -s "${URL}metrics"
33 changes: 0 additions & 33 deletions lib/prometheus/client/formats/json.rb

This file was deleted.

5 changes: 2 additions & 3 deletions lib/prometheus/client/rack/exporter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# encoding: UTF-8

require 'prometheus/client'
require 'prometheus/client/formats/json'
require 'prometheus/client/formats/text'

module Prometheus
Expand All @@ -12,8 +11,8 @@ module Rack
class Exporter
attr_reader :app, :registry, :path

FORMATS = [Formats::Text, Formats::JSON]
FALLBACK = Formats::JSON
FORMATS = [Formats::Text]
FALLBACK = Formats::Text

def initialize(app, options = {})
@app = app
Expand Down
71 changes: 0 additions & 71 deletions spec/prometheus/client/formats/json_spec.rb

This file was deleted.

42 changes: 8 additions & 34 deletions spec/prometheus/client/rack/exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# encoding: UTF-8

require 'json'
require 'rack/test'
require 'prometheus/client/rack/exporter'

Expand All @@ -27,7 +26,6 @@

context 'when requesting /metrics' do
text = Prometheus::Client::Formats::Text
json = Prometheus::Client::Formats::JSON

shared_examples 'ok' do |headers, fmt|
it "responds with 200 OK and Content-Type #{fmt::CONTENT_TYPE}" do
Expand All @@ -43,7 +41,7 @@

shared_examples 'not acceptable' do |headers|
it 'responds with 406 Not Acceptable' do
message = 'Supported media types: text/plain, application/json'
message = 'Supported media types: text/plain'

get '/metrics', nil, headers

Expand All @@ -54,37 +52,19 @@
end

context 'when client does not send a Accept header' do
include_examples 'ok', {}, json
include_examples 'ok', {}, text
end

context 'when client accpets any media type' do
accept = '*/*'

include_examples 'ok', { 'HTTP_ACCEPT' => accept }, json
include_examples 'ok', { 'HTTP_ACCEPT' => '*/*' }, text
end

context 'when client requests application/json' do
accept = 'application/json'

include_examples 'ok', { 'HTTP_ACCEPT' => accept }, json
end

context "when client requests '#{json::CONTENT_TYPE}'" do
accept = json::CONTENT_TYPE

include_examples 'ok', { 'HTTP_ACCEPT' => accept }, json
include_examples 'not acceptable', 'HTTP_ACCEPT' => 'application/json'
end

context 'when client requests text/plain' do
accept = 'text/plain'

include_examples 'ok', { 'HTTP_ACCEPT' => accept }, text
end

context "when client requests '#{text::CONTENT_TYPE}'" do
accept = text::CONTENT_TYPE

include_examples 'ok', { 'HTTP_ACCEPT' => accept }, text
include_examples 'ok', { 'HTTP_ACCEPT' => 'text/plain' }, text
end

context 'when client uses different white spaces in Accept header' do
Expand All @@ -93,20 +73,14 @@
include_examples 'ok', { 'HTTP_ACCEPT' => accept }, text
end

context 'when client accepts multiple formats' do
accept = "#{json::CONTENT_TYPE};q=0.5, #{text::CONTENT_TYPE};q=0.7"

include_examples 'ok', { 'HTTP_ACCEPT' => accept }, text
end

context 'when client does not include quality attribute' do
accept = "#{json::CONTENT_TYPE};q=0.5, #{text::CONTENT_TYPE}"
accept = 'application/json;q=0.5, text/plain'

include_examples 'ok', { 'HTTP_ACCEPT' => accept }, text
end

context 'when client accepts some unknown formats' do
accept = "#{text::CONTENT_TYPE};q=0.3, proto/buf;q=0.7"
accept = 'text/plain;q=0.3, proto/buf;q=0.7'

include_examples 'ok', { 'HTTP_ACCEPT' => accept }, text
end
Expand All @@ -120,7 +94,7 @@
context 'when client accepts unknown formats and wildcard' do
accept = 'fancy/woo;q=0.3, proto/buf;q=0.7, */*;q=0.1'

include_examples 'ok', { 'HTTP_ACCEPT' => accept }, json
include_examples 'ok', { 'HTTP_ACCEPT' => accept }, text
end
end
end