Skip to content

Commit

Permalink
removed loggly and added more metering tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar committed Nov 17, 2017
1 parent 3a35013 commit 0501d04
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 427 deletions.
2 changes: 1 addition & 1 deletion broker/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func NewService(cfg *config.Config) (s *Service, err error) {
}

// Load the logging provider
logging.Logger = config.LoadProvider(cfg.Logging, logging.NewStdErr(), logging.NewLoggly()).(logging.Logging)
logging.Logger = config.LoadProvider(cfg.Logging, logging.NewStdErr()).(logging.Logging)
logging.LogTarget("service", "configured logging provider", logging.Logger.Name())

// Load the storage provider
Expand Down
40 changes: 0 additions & 40 deletions logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
package logging

import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"

"github.com/emitter-io/config"
"github.com/kelindar/go-loggly"
)

// Discard is the discard logger.
Expand Down Expand Up @@ -83,40 +80,3 @@ func (s *stderrLogger) Configure(config map[string]interface{}) error {
func (s *stderrLogger) Printf(format string, v ...interface{}) {
(*log.Logger)(s).Printf(format+"\n", v...)
}

// ------------------------------------------------------------------------------------

// logglyLogger implements Logging contract.
var _ Logging = new(logglyLogger)

// logglyLogger represents a simple golang logger.
type logglyLogger struct {
cli *loggly.Client
}

// NewLoggly creates a new loggly logger.
func NewLoggly() Logging {
return &logglyLogger{}
}

// Name returns the name of the provider.
func (s *logglyLogger) Name() string {
return "loggly"
}

// Configure configures the provider
func (s *logglyLogger) Configure(config map[string]interface{}) error {
if v, ok := config["token"]; ok {
if token, ok := v.(string); ok {
s.cli = loggly.New(token)
return nil
}
}

return errors.New("Loggly client did not contain a configuration for the 'token'")
}

// Printf prints a log line.
func (s *logglyLogger) Printf(format string, v ...interface{}) {
s.cli.Info(fmt.Sprintf(format, v...))
}
4 changes: 3 additions & 1 deletion security/usage/metering.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ type HTTPStorage struct {
counters *sync.Map // The counters map.
url string // The url to post to.
http http.Client // The http client to use.
done chan bool // The closing channel.
}

// NewHTTP creates a new HTTP storage
func NewHTTP() *HTTPStorage {
return &HTTPStorage{
counters: new(sync.Map),
done: make(chan bool),
}
}

Expand All @@ -88,7 +90,7 @@ func (s *HTTPStorage) Configure(config map[string]interface{}) (err error) {
// Get the url from the provider configuration
if url, ok := config["url"]; ok {
s.url = url.(string)
utils.Repeat(s.store, interval, make(chan bool)) // TODO: closing chan
utils.Repeat(s.store, interval, s.done) // TODO: closing chan

// Create a new HTTP client to use
s.http, err = http.NewClient(s.url, 30*time.Second)
Expand Down
21 changes: 21 additions & 0 deletions security/usage/metering_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package usage

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -36,3 +37,23 @@ func TestHTTP_Name(t *testing.T) {
s := new(HTTPStorage)
assert.Equal(t, "http", s.Name())
}

func TestHTTP_Configure(t *testing.T) {
s := NewHTTP()
defer close(s.done)

{
err := s.Configure(nil)
assert.Error(t, errors.New("Configuration was not provided for HTTP metering provider"), err)
}

{
err := s.Configure(map[string]interface{}{
"interval": 1000.0,
"url": "http://localhost/test",
})
assert.NoError(t, err)
assert.Equal(t, "http://localhost/test", s.url)
assert.NotNil(t, s.http)
}
}
71 changes: 0 additions & 71 deletions vendor/github.com/kelindar/go-loggly/History.md

This file was deleted.

17 changes: 0 additions & 17 deletions vendor/github.com/kelindar/go-loggly/Readme.md

This file was deleted.

0 comments on commit 0501d04

Please sign in to comment.