-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release/0.9.0 - all changes #2
Merged
Merged
Changes from 36 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
fa8a3ef
Update tests to pass with a default token
ae08451
Add utils.whilst + tests, rename utils.chain tests
1a55810
Add utils.expBackoff for exponential backoff timeout
76e3a43
Add retry on error logic, via exponential backoff.
e2d9342
Merge branch 'develop' into feature/retry
2042e05
Add retry example & update readme
3f4f3bd
Update examples
d598fb0
Add support for automatic interval batching.
3870937
Clean up batch interval implementation
fc98ed9
Add another config test for autoflush
566c3cb
Update doc datatype for batch interval
fa7f3b6
Add configuration setting for batch size
e5ded8d
Moved complicated logic from _sendEvents() to flush()
2f4bb81
Optimize calculateBatchSize, add additional test coverage
806b220
Add configuration setting for batch count
bdc30ac
Add comments to timer initialization logic
9949cdc
API changes based on feedback from #1
d50f1bd
Add units for _enableTimer()
ae5d79b
Disable maxBatchSize and maxBatchCount by default.
331143c
Rename utils.validatePositiveInt() to validateNonNegativeInt()
974187f
Renamed batching example to manual_batching
d50f926
Add all batching settings example
0644497
remove middleware and all references to it
bd45dfa
Update tests for 100% coverage
1a0c5bb
Added new example for custom event format
d9ce2d6
Correct the payload comment in the basic example
e2f9881
Correct comment in all batching example
8fa15ab
Refactor contextQueue to serializedContextQueue
4faf827
Remove the config.autoFlush property.
dab006b
Update examples following refactor
a157135
Update version number, readme, changelog
700a932
Update all batching token placeholder
5052a73
Fix grammar in changelog
5fbeba8
Correct config settings in custom_format example
f49155a
alphabetize examples in readme
ba786a8
Fix typos in readme
e566ac1
Remove "beta" phrasing
bacfb44
Editorial changes.
mtevenan-splunk 5f02cb3
Tweaks
mtevenan-splunk 1d1ff48
Editorial updates.
mtevenan-splunk 65e6b86
Editorial updates.
mtevenan-splunk 94eab46
Editorial updates.
mtevenan-splunk 93853fd
Editorial updates.
mtevenan-splunk 2411218
Editorial updates.
mtevenan-splunk 812e0b2
Editorial updates.
mtevenan-splunk a1cf6d6
Fix typo in utils doc comment
0d3ea9f
Change retry example to retry 10 times
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
# Splunk Logging Library for JavaScript (beta) | ||
|
||
## v0.9.0 - beta | ||
|
||
### New Features & APIs | ||
|
||
* Added the ability to configure automated batching with 3 settings: `batchInterval`, `maxBatchCount`, & `maxBatchSize`. | ||
* Added the ability to retry sending to Splunk in the case of network errors with the `maxRetries` configuration setting. | ||
* Added the ability to configure a custom Splunk event format by overriding `eventFormatter(message, severity)`. | ||
|
||
### Breaking Changes | ||
|
||
* Removed the `autoFlush` configuration setting. To achieve the same effect, set `config.maxBatchCount` to `0`. | ||
* Removed support for middleware functions. | ||
* The `context` object has been simplified, `config` and `requestOptions` can no longer be specified there - please use those settings directly on the logger. | ||
|
||
### Examples | ||
|
||
* Removed the `middleware.js` example. | ||
* Renamed the `batching.js` example to `manual_batching`. | ||
* Added the `all_batching.js`, `custom_format.js`, `retry.js` examples. | ||
|
||
### Minor changes | ||
|
||
* Significant refactor of internal functions. | ||
|
||
## v0.8.0 - beta | ||
|
||
* Beta release. |
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,95 @@ | ||
/* | ||
* Copyright 2015 Splunk, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"): you may | ||
* not use this file except in compliance with the License. You may obtain | ||
* a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/** | ||
* This example shows how to batch events with the | ||
* SplunkLogger with all available settings: | ||
* batchInterval, maxBatchCount, & maxBatchSize. | ||
*/ | ||
|
||
// Change to require("splunk-logging").Logger; | ||
var SplunkLogger = require("../index").Logger; | ||
|
||
/** | ||
* Only the token property is required. | ||
* | ||
* Here, batchInterval is set to flush every 1 second, when | ||
* 10 events are queued, or when the size of queued events totals | ||
* more than 1kb. | ||
*/ | ||
var config = { | ||
token: "your-token-here", | ||
url: "https://localhost:8088", | ||
batchInterval: 1000, | ||
maxBatchCount: 10, | ||
maxBatchSize: 1024 // 1kb | ||
}; | ||
|
||
// Create a new logger | ||
var Logger = new SplunkLogger(config); | ||
|
||
Logger.error = function(err, context) { | ||
// Handle errors here | ||
console.log("error", err, "context", context); | ||
}; | ||
|
||
// Define the payload to send to Splunk's Event Collector | ||
var payload = { | ||
// Message can be anything, doesn't have to be an object | ||
message: { | ||
temperature: "70F", | ||
chickenCount: 500 | ||
}, | ||
// Metadata is optional | ||
metadata: { | ||
source: "chicken coop", | ||
sourcetype: "httpevent", | ||
index: "main", | ||
host: "farm.local", | ||
}, | ||
// Severity is also optional | ||
severity: "info" | ||
}; | ||
|
||
console.log("Queuing payload", payload); | ||
// Don't need a callback here | ||
Logger.send(payload); | ||
|
||
var payload2 = { | ||
message: { | ||
temperature: "75F", | ||
chickenCount: 600, | ||
note: "New chickens have arrived" | ||
}, | ||
metadata: payload.metadata | ||
}; | ||
|
||
console.log("Queuing second payload", payload2); | ||
// Don't need a callback here | ||
Logger.send(payload2); | ||
|
||
/** | ||
* Since we've configured batching, we don't need | ||
* to do anything at this point. Events will | ||
* will be sent to Splunk automatically based | ||
* on the batching settings above. | ||
*/ | ||
|
||
// Kill the process | ||
setTimeout(function() { | ||
console.log("Events should be in Splunk! Exiting..."); | ||
process.exit(); | ||
}, 2000); |
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,113 @@ | ||
/* | ||
* Copyright 2015 Splunk, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"): you may | ||
* not use this file except in compliance with the License. You may obtain | ||
* a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/** | ||
* This example shows how to use a custom event format for SplunkLogger. | ||
*/ | ||
|
||
// Change to require("splunk-logging").Logger; | ||
var SplunkLogger = require("../index").Logger; | ||
|
||
/** | ||
* Only the token property is required. | ||
*/ | ||
var config = { | ||
token: "your-token-here", | ||
url: "https://localhost:8088" | ||
}; | ||
|
||
// Create a new logger | ||
var Logger = new SplunkLogger(config); | ||
|
||
Logger.error = function(err, context) { | ||
// Handle errors here | ||
console.log("error", err, "context", context); | ||
}; | ||
|
||
/** | ||
* Override the default eventFormatter() function, | ||
* which takes a message and severity, returning | ||
* any type - string or object are recommended. | ||
* | ||
* The message parameter can be any type. It will | ||
* be whatever was passed to Logger.send(). | ||
* Severity will always be a string. | ||
* | ||
* In this example, we're building up a string | ||
* of key=value pairs if message is an object, | ||
* otherwise the message value is as value for | ||
* the message key. | ||
* This string is prefixed with the event | ||
* severity in square brackets. | ||
*/ | ||
Logger.eventFormatter = function(message, severity) { | ||
var event = "[" + severity + "]"; | ||
|
||
if (typeof message === "object") { | ||
for (var key in message) { | ||
event += key + "=" + message[key] + " "; | ||
} | ||
} | ||
else { | ||
event += "message=" + message; | ||
} | ||
|
||
return event; | ||
}; | ||
|
||
// Define the payload to send to Splunk's Event Collector | ||
var payload = { | ||
// Message can be anything, it doesn't have to be an object | ||
message: { | ||
temperature: "70F", | ||
chickenCount: 500 | ||
}, | ||
// Metadata is optional | ||
metadata: { | ||
source: "chicken coop", | ||
sourcetype: "httpevent", | ||
index: "main", | ||
host: "farm.local" | ||
}, | ||
// Severity is also optional | ||
severity: "info" | ||
}; | ||
|
||
console.log("Sending payload", payload); | ||
|
||
/** | ||
* Since maxBatchCount is set to 1 by default, | ||
* calling send will immediately send the payload. | ||
* | ||
* The underlying HTTP POST request is made to | ||
* | ||
* https://localhost:8088/services/collector/event/1.0 | ||
* | ||
* with the following body | ||
* | ||
* { | ||
* "source": "chicken coop", | ||
* "sourcetype": "httpevent", | ||
* "index": "main", | ||
* "host": "farm.local", | ||
* "event": "[info]temperature=70F chickenCount=500 " | ||
* } | ||
* | ||
*/ | ||
Logger.send(payload, function(err, resp, body) { | ||
// If successful, body will be { text: 'Success', code: 0 } | ||
console.log("Response from Splunk", body); | ||
}); |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's drop using beta here as well.