-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
1,084 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package librato | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
const annotationsURL = "https://metrics-api.librato.com/v1/annotations" | ||
|
||
var ErrNoNameAnnotation = fmt.Errorf("Annotation must have name") | ||
|
||
// Annotation is a representation of librato annotation object | ||
// https://www.librato.com/docs/kb/visualize/annotations/ | ||
type Annotation struct { | ||
Title string `json:"title"` | ||
Source *string `json:"source"` | ||
Description *string `json:"description"` | ||
Links []Link `json:"links"` | ||
|
||
StartTime *int64 `json:"start_time"` | ||
EndTime *int64 `json:"end_time"` | ||
} | ||
|
||
// Link is a representation of link object, that can be used in annotations | ||
// https://www.librato.com/docs/api/#update-an-annotation | ||
type Link struct { | ||
Relationship string `json:"rel"` | ||
URL string `json:"href"` | ||
Label *string `json:"label"` | ||
} | ||
|
||
// PostAnnotation sends annotation to librato API right away | ||
// because Annotation to doesn't seem to support batching | ||
// http://api-docs-archive.librato.com/#create-an-annotation | ||
func (lb *Librato) PostAnnotation(body *Annotation, name string) error { | ||
if name == "" { | ||
return ErrNoNameAnnotation | ||
} | ||
|
||
b, err := json.Marshal(body) | ||
if nil != err { | ||
return err | ||
} | ||
|
||
return lb.makeRequest(bytes.NewBuffer(b), fmt.Sprintf("%s/%s", annotationsURL, name)) | ||
} |
Oops, something went wrong.