Skip to content

thezelus/meowtrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

###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)

About

Meowtrics is a metrics collection server written in Go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages