-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from lessonnine/TNT-2411/release-gem
[TNT-2411] Release gem
- Loading branch information
Showing
12 changed files
with
253 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
## [0.1.0] - 2020-12-18 | ||
### Added | ||
- Core Plugin | ||
- Telemetry generation | ||
- IO Target with JSON formatter | ||
- Datadog Statsd Target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
|
||
module Puma | ||
class Plugin | ||
module Telemetry | ||
module Targets | ||
# Simple IO Target, publishing metrics to STDOUT or logs | ||
# | ||
class IOTarget | ||
# JSON formatter for IO, expects `call` method accepting telemetry hash | ||
# | ||
class JSONFormatter | ||
def self.call(telemetry) | ||
::JSON.dump(telemetry.merge(name: "Puma::Plugin::Telemetry", message: "Publish telemetry")) | ||
end | ||
end | ||
|
||
def initialize(io: $stdout, formatter: :json) | ||
@io = io | ||
@formatter = case formatter | ||
when :json then JSONFormatter | ||
else formatter | ||
end | ||
end | ||
|
||
def call(telemetry) | ||
@io.puts(@formatter.call(telemetry)) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# frozen_string_literal: true | ||
|
||
module Puma | ||
class Plugin | ||
module Telemetry | ||
RSpec.describe Config do | ||
subject(:config) { described_class.new } | ||
|
||
describe "#enabled?" do | ||
context "when default" do | ||
it { expect(config.enabled?).to eq false } | ||
end | ||
|
||
context "when enabled" do | ||
before { config.enabled = true } | ||
|
||
it { expect(config.enabled?).to eq true } | ||
end | ||
end | ||
|
||
describe "#add_target" do | ||
context "when built in: IO" do | ||
it "adds new target" do | ||
expect { config.add_target(:io) }.to change(config.targets, :size).by(1) | ||
end | ||
|
||
it "adds new IO Target" do | ||
config.add_target(:io) | ||
expect(config.targets.first).to be_a(Telemetry::Targets::IOTarget) | ||
end | ||
end | ||
|
||
context "when built in: Datadog" do | ||
let(:client) { instance_double("statsd") } | ||
|
||
it "adds new target" do | ||
expect do | ||
config.add_target(:dogstatsd, client: client) | ||
end.to change(config.targets, :size).by(1) | ||
end | ||
|
||
it "adds new Datadog Target" do | ||
config.add_target(:dogstatsd, client: client) | ||
expect(config.targets.first).to be_a(Telemetry::Targets::DatadogStatsdTarget) | ||
end | ||
end | ||
|
||
context "when custom" do | ||
let(:target) { proc { |telemetry| puts telemetry.inspect } } | ||
|
||
it "adds new target" do | ||
expect do | ||
config.add_target(target) | ||
end.to change(config.targets, :size).by(1) | ||
end | ||
|
||
it "adds new Custom Target" do | ||
config.add_target(target) | ||
expect(config.targets.first).to be_a(Proc) | ||
end | ||
end | ||
|
||
context "when multiple targets" do | ||
it "adds new targets" do | ||
expect do | ||
config.add_target(proc { |telemetry| puts telemetry.inspect }) | ||
config.add_target(:io) | ||
config.add_target(:io) | ||
end.to change(config.targets, :size).by(3) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |