meowtrics

module
v0.0.0-...-2d899db Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2016 License: MIT

README

###What is Meowtrics?### Meowtrics is a metrics collection server written in Go. For this first version it provides a very basic API for storing and retrieving events. Current version is built using negroni, gorilla mux, protocol buffers, and stores data in memory.

###API Docs###

####Heartbeat####

Request

For checking the service status, heartbeat requests can be sent.

  • Path - /heartbeat

Response

The response would be in the following JSON format.

{
    "status": "OK",
    "timestamp": "2015-01-28 07:18:14.450707079 +0000 UTC"
}

####ClientEventUploadRequest####

  • Method - POST

  • Path - /v1/events

  • Content-Type - application/json or application/x-protobuf

Request body format for JSON

{
  "request_id": "testRequestId",
  "device_type": "testDeviceAndroid",
  "events": [
    {
      "event_id": "123",
      "event_type": 1,
      "timestamp": 1422409858,
      "data": "testTestTestTestTest"
    }
  ]
}

For protobuf, more details can be found in the metrics.proto file in the model package.

Response

For successful POST, the response body will be empty. For error cases, please check the error details section below.

####ClientEventData####

Request

  • Method - GET

  • Path - /v1/events/id (id should be replaced by the eventId)

  • Accept header - application/json or application/x-protobuf or */* or none

Note: This version of the meowtrics server only accepts numerical ids for GET requests, non-numerical ids would get a NOT_FOUND error response.

Response

Successful response to GET request is returned in following JSON format (if the accept header is application/json or */* or none ) -

{
  "event_id": "123",
  "event_type": 1,
  "timestamp": 1422409858,
  "data": "testTestTestTestTest"
}

####Error details####

Error response is always returned in JSON format for the ease of debugging.

Response

In case of errors, the response body will include the error response in following JSON format.

{
    "code": "SAMPLE",
    "error_message": "sample",
    "description": "sample-meow"
}

Error codes

- NOT_FOUND
- INVALID_REQUEST_PARAMETERS
- MALFORMED_REQUEST
- HEADER_NOT_RECOGNIZED
- REQUESTED_RECORD_NOT_FOUND
- FATAL_OPERATION
- UNSUPPORTED_MEDIA_TYPE

####Response Status####

200 OK - For successful POST and GET requests

404 Not Found - For invalid resource urls or invalid id requests when making a GET request

500 Internal Server Error

415 Unsupported Media Type - For invalid Content-Type and Accept headers

400 Bad Request - For POST requests with ClientEventData with no eventId

###Notes###

  • I like to create a config directory with the name same as the project under '$GOPATH/bin/config/', and this is set as the DefaultDeploymentPath for the config file ('$GOPATH/bin/config/meowtrics/' for this project).
  • Viper is configured to check first in the default deployment directory and then in the injected config path.
  • Each ClientEventUploadRequest POST can have multiple events, to achieve transcational behavior the datastore will be switched to boltdb in a later version. For now the client events bundle is validated to achieve atomicity, either all of them are stored or an error response is sent back.
  • Partial storage is performed in case of errors from in memory database StoreEvent() method
  • Header --> "Content-Type" ---> "application/json" OR "application/x-protobuf"
  • POST calls have no restriction on eventId type (can be string or integers), GET calls only accept numeric values as id

###Done List###

  • Implement in memory database access to use for testing.
  • Implement POST and GET handlers.
  • The POST handler(s) should allow both protobuf and JSON encoding as input depending on the Content-Type header.
  • The GET handler(s) should allow both protobuf and JSON as output depending on the Accept header and if no Accept header is present, or set to “/”, output should be JSON by default.
  • The GET request handlers should only accept numerical id’s and return a 404 otherwise.
  • Modify metrics.proto so that clients can submit arbitrary key/value pairs as part of the ClientEventData object.
  • Add test cases demonstrating successful storage and retrieval plus error cases.

###TODO List###

  • Update documentation to include details about the API endpoints
  • Write deployment scripts
  • Include more tests
  • Update documentation to include details about response header status
  • Dockerize meowtrics
  • Modify datasource to use bolt instead of a map

###Why call it Meowtrics?### Because it is a metrics collection server, but.....

And [Super Troopers](http://www.imdb.com/title/tt0247745/) is an awesome movie.

###Why not use an existing solution?### I will try this out for meow, this is more of a learning exercise to use protobuf in Go. If you want to extend this solution or if you have feature suggestions, you should fork this repository right meow.

(P.S. - Inspiration from a test project)

Directories

Path Synopsis
Package model is a generated protocol buffer package.
Package model is a generated protocol buffer package.
Godeps/_workspace/src/github.com/golang/protobuf/proto
Package proto converts data structures to and from the wire format of protocol buffers.
Package proto converts data structures to and from the wire format of protocol buffers.
Godeps/_workspace/src/github.com/codegangsta/negroni
Package negroni is an idiomatic approach to web middleware in Go.
Package negroni is an idiomatic approach to web middleware in Go.
Godeps/_workspace/src/github.com/golang/protobuf/proto
Package proto converts data structures to and from the wire format of protocol buffers.
Package proto converts data structures to and from the wire format of protocol buffers.
Godeps/_workspace/src/github.com/gorilla/context
Package gorilla/context stores values shared during a request lifetime.
Package gorilla/context stores values shared during a request lifetime.
Godeps/_workspace/src/github.com/gorilla/mux
Package gorilla/mux implements a request router and dispatcher.
Package gorilla/mux implements a request router and dispatcher.
Godeps/_workspace/src/github.com/kr/pretty
Package pretty provides pretty-printing for Go values.
Package pretty provides pretty-printing for Go values.
Godeps/_workspace/src/github.com/kr/text
Package text provides rudimentary functions for manipulating text in paragraphs.
Package text provides rudimentary functions for manipulating text in paragraphs.
Godeps/_workspace/src/github.com/kr/text/colwriter
Package colwriter provides a write filter that formats input lines in multiple columns.
Package colwriter provides a write filter that formats input lines in multiple columns.
Godeps/_workspace/src/github.com/kr/text/mc
Command mc prints in multiple columns.
Command mc prints in multiple columns.
Godeps/_workspace/src/github.com/mitchellh/mapstructure
The mapstructure package exposes functionality to convert an abitrary map[string]interface{} into a native Go structure.
The mapstructure package exposes functionality to convert an abitrary map[string]interface{} into a native Go structure.
Godeps/_workspace/src/github.com/spf13/pflag
pflag is a drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags.
pflag is a drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags.
Godeps/_workspace/src/github.com/unrolled/render
Package render is a package that provides functionality for easily rendering JSON, XML, binary data, and HTML templates.
Package render is a package that provides functionality for easily rendering JSON, XML, binary data, and HTML templates.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL