-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from ConvertKit/spec-and-refactor-for-prime-time
CircleCI/Test + Refactor for official usage
- Loading branch information
Showing
14 changed files
with
295 additions
and
17 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,26 @@ | ||
# Stories | ||
|
||
Stories is a lightweight agent for StoryTeller logs. | ||
|
||
## Configuration | ||
|
||
Currently, the agent has a hardcoded dependency to Scalyr as a provider. This means that the agent will look for the `SCALYR_WRITE_TOKEN` Environment variable to be set. Other than that, `stories` can be configured with the following flags at startup. | ||
|
||
### `--buffer=int` | ||
_default: 1000_ | ||
The buffer size is how many stories that the agent can store before it sends it in a batch to the provider. | ||
|
||
### `--interval=int` | ||
_default: 1_ | ||
The interval, in seconds, before the agent batch the stories that it has buffered. | ||
|
||
|
||
### `--socket=string` | ||
_default: /tmp/stories.sock_ | ||
The path where the unix socket will be created. This is used by libraries to send over events. | ||
|
||
#### Batching against an interval | ||
|
||
The way the agent works is that there is a runloop set to the `interval` set at runtime that will send in batch any stories that were collected during the interval. | ||
|
||
If, during the interval, the buffer reach its limit, the agent will trigger a batch send to the provider. If all default settings are set and you send twice the size of the buffer over the interval period, 2 batch will be sent to the provider. |
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 |
---|---|---|
@@ -1,9 +1,79 @@ | ||
package scalyr | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/convertkit/stories/stories" | ||
"testing" | ||
) | ||
|
||
func TestEventJSONIsAcceptable(t *testing.T) { | ||
func story(t *testing.T) *stories.Story { | ||
story, err := stories.NewStory([]byte(`{ | ||
"severity": 4, | ||
"timestamp": "1541354132811", | ||
"message": "Hello world!", | ||
"data": { | ||
"foo": { | ||
"bar": "Something", | ||
"yolo": true | ||
}, | ||
"object_id": 1234, | ||
"boolean": true, | ||
"content": "Stuff" | ||
} | ||
}`)) | ||
|
||
if err != nil { | ||
t.Fail() | ||
} | ||
|
||
return story | ||
} | ||
|
||
func payloadForEventTest(story *stories.Story, t *testing.T) map[string]interface{} { | ||
event := Event(*story) | ||
content, err := json.Marshal(&event) | ||
|
||
if err != nil { | ||
t.Fail() | ||
} | ||
|
||
var payload map[string]interface{} | ||
|
||
err = json.Unmarshal(content, &payload) | ||
|
||
if err != nil { | ||
t.Error(err) | ||
t.Fail() | ||
} | ||
|
||
return payload | ||
} | ||
|
||
func TestTimestampInJSON(t *testing.T) { | ||
story := story(t) | ||
payload := payloadForEventTest(story, t) | ||
|
||
if payload["ts"] != string("1541354132811") { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestSevInJSON(t *testing.T) { | ||
story := story(t) | ||
payload := payloadForEventTest(story, t) | ||
|
||
if payload["sev"].(float64) != float64(4) { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestMessageInAttributesJSON(t *testing.T) { | ||
story := story(t) | ||
payload := payloadForEventTest(story, t) | ||
|
||
attributes := payload["attrs"].(map[string]interface{}) | ||
|
||
if attributes["message"] != string("Hello world!") { | ||
t.Fail() | ||
} | ||
} |
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,71 @@ | ||
package scalyr | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/convertkit/stories/stories" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func instanceForInstanceTest(t *testing.T) *Instance { | ||
os.Setenv("SCALYR_WRITE_TOKEN", "test") | ||
|
||
instance := &Instance{} | ||
err := instance.Configure() | ||
|
||
if err != nil { | ||
t.Error(err) | ||
t.Fail() | ||
} | ||
|
||
return instance | ||
} | ||
|
||
func payloadForInstanceTest(t *testing.T) *Payload { | ||
story, err := stories.NewStory([]byte(`{ | ||
"severity": 4, | ||
"timestamp": "1541354132811", | ||
"message": "Hello world!", | ||
"data": { | ||
"foo": { | ||
"bar": "Something", | ||
"yolo": true | ||
}, | ||
"object_id": 1234, | ||
"boolean": true, | ||
"content": "Stuff" | ||
} | ||
}`)) | ||
|
||
if err != nil { | ||
t.Fail() | ||
} | ||
|
||
stories := []*stories.Story{story} | ||
return NewPayload(instanceForInstanceTest(t), stories) | ||
} | ||
|
||
func TestTokenPresentInJSON(t *testing.T) { | ||
payload := payloadForInstanceTest(t) | ||
body, err := json.Marshal(&payload) | ||
|
||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
var data map[string]interface{} | ||
|
||
err = json.Unmarshal(body, &data) | ||
|
||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if data["token"] == nil { | ||
t.Fail() | ||
} | ||
|
||
if data["token"] != payload.Token { | ||
t.Fail() | ||
} | ||
} |
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
Oops, something went wrong.