|
@@ -2,7 +2,6 @@ package api
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"strings"
|
|
"strings"
|
|
|
- "time"
|
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/api/dtos"
|
|
"github.com/grafana/grafana/pkg/api/dtos"
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
@@ -15,9 +14,10 @@ import (
|
|
|
func GetAnnotations(c *m.ReqContext) Response {
|
|
func GetAnnotations(c *m.ReqContext) Response {
|
|
|
|
|
|
|
|
query := &annotations.ItemQuery{
|
|
query := &annotations.ItemQuery{
|
|
|
- From: c.QueryInt64("from") / 1000,
|
|
|
|
|
- To: c.QueryInt64("to") / 1000,
|
|
|
|
|
|
|
+ From: c.QueryInt64("from"),
|
|
|
|
|
+ To: c.QueryInt64("to"),
|
|
|
OrgId: c.OrgId,
|
|
OrgId: c.OrgId,
|
|
|
|
|
+ UserId: c.QueryInt64("userId"),
|
|
|
AlertId: c.QueryInt64("alertId"),
|
|
AlertId: c.QueryInt64("alertId"),
|
|
|
DashboardId: c.QueryInt64("dashboardId"),
|
|
DashboardId: c.QueryInt64("dashboardId"),
|
|
|
PanelId: c.QueryInt64("panelId"),
|
|
PanelId: c.QueryInt64("panelId"),
|
|
@@ -37,7 +37,7 @@ func GetAnnotations(c *m.ReqContext) Response {
|
|
|
if item.Email != "" {
|
|
if item.Email != "" {
|
|
|
item.AvatarUrl = dtos.GetGravatarUrl(item.Email)
|
|
item.AvatarUrl = dtos.GetGravatarUrl(item.Email)
|
|
|
}
|
|
}
|
|
|
- item.Time = item.Time * 1000
|
|
|
|
|
|
|
+ item.Time = item.Time
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return JSON(200, items)
|
|
return JSON(200, items)
|
|
@@ -68,16 +68,12 @@ func PostAnnotation(c *m.ReqContext, cmd dtos.PostAnnotationsCmd) Response {
|
|
|
UserId: c.UserId,
|
|
UserId: c.UserId,
|
|
|
DashboardId: cmd.DashboardId,
|
|
DashboardId: cmd.DashboardId,
|
|
|
PanelId: cmd.PanelId,
|
|
PanelId: cmd.PanelId,
|
|
|
- Epoch: cmd.Time / 1000,
|
|
|
|
|
|
|
+ Epoch: cmd.Time,
|
|
|
Text: cmd.Text,
|
|
Text: cmd.Text,
|
|
|
Data: cmd.Data,
|
|
Data: cmd.Data,
|
|
|
Tags: cmd.Tags,
|
|
Tags: cmd.Tags,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if item.Epoch == 0 {
|
|
|
|
|
- item.Epoch = time.Now().Unix()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if err := repo.Save(&item); err != nil {
|
|
if err := repo.Save(&item); err != nil {
|
|
|
return Error(500, "Failed to save annotation", err)
|
|
return Error(500, "Failed to save annotation", err)
|
|
|
}
|
|
}
|
|
@@ -97,7 +93,7 @@ func PostAnnotation(c *m.ReqContext, cmd dtos.PostAnnotationsCmd) Response {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
item.Id = 0
|
|
item.Id = 0
|
|
|
- item.Epoch = cmd.TimeEnd / 1000
|
|
|
|
|
|
|
+ item.Epoch = cmd.TimeEnd
|
|
|
|
|
|
|
|
if err := repo.Save(&item); err != nil {
|
|
if err := repo.Save(&item); err != nil {
|
|
|
return Error(500, "Failed save annotation for region end time", err)
|
|
return Error(500, "Failed save annotation for region end time", err)
|
|
@@ -132,9 +128,6 @@ func PostGraphiteAnnotation(c *m.ReqContext, cmd dtos.PostGraphiteAnnotationsCmd
|
|
|
return Error(500, "Failed to save Graphite annotation", err)
|
|
return Error(500, "Failed to save Graphite annotation", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if cmd.When == 0 {
|
|
|
|
|
- cmd.When = time.Now().Unix()
|
|
|
|
|
- }
|
|
|
|
|
text := formatGraphiteAnnotation(cmd.What, cmd.Data)
|
|
text := formatGraphiteAnnotation(cmd.What, cmd.Data)
|
|
|
|
|
|
|
|
// Support tags in prior to Graphite 0.10.0 format (string of tags separated by space)
|
|
// Support tags in prior to Graphite 0.10.0 format (string of tags separated by space)
|
|
@@ -163,7 +156,7 @@ func PostGraphiteAnnotation(c *m.ReqContext, cmd dtos.PostGraphiteAnnotationsCmd
|
|
|
item := annotations.Item{
|
|
item := annotations.Item{
|
|
|
OrgId: c.OrgId,
|
|
OrgId: c.OrgId,
|
|
|
UserId: c.UserId,
|
|
UserId: c.UserId,
|
|
|
- Epoch: cmd.When,
|
|
|
|
|
|
|
+ Epoch: cmd.When * 1000,
|
|
|
Text: text,
|
|
Text: text,
|
|
|
Tags: tagsArray,
|
|
Tags: tagsArray,
|
|
|
}
|
|
}
|
|
@@ -191,7 +184,7 @@ func UpdateAnnotation(c *m.ReqContext, cmd dtos.UpdateAnnotationsCmd) Response {
|
|
|
OrgId: c.OrgId,
|
|
OrgId: c.OrgId,
|
|
|
UserId: c.UserId,
|
|
UserId: c.UserId,
|
|
|
Id: annotationID,
|
|
Id: annotationID,
|
|
|
- Epoch: cmd.Time / 1000,
|
|
|
|
|
|
|
+ Epoch: cmd.Time,
|
|
|
Text: cmd.Text,
|
|
Text: cmd.Text,
|
|
|
Tags: cmd.Tags,
|
|
Tags: cmd.Tags,
|
|
|
}
|
|
}
|
|
@@ -203,7 +196,7 @@ func UpdateAnnotation(c *m.ReqContext, cmd dtos.UpdateAnnotationsCmd) Response {
|
|
|
if cmd.IsRegion {
|
|
if cmd.IsRegion {
|
|
|
itemRight := item
|
|
itemRight := item
|
|
|
itemRight.RegionId = item.Id
|
|
itemRight.RegionId = item.Id
|
|
|
- itemRight.Epoch = cmd.TimeEnd / 1000
|
|
|
|
|
|
|
+ itemRight.Epoch = cmd.TimeEnd
|
|
|
|
|
|
|
|
// We don't know id of region right event, so set it to 0 and find then using query like
|
|
// We don't know id of region right event, so set it to 0 and find then using query like
|
|
|
// ... WHERE region_id = <item.RegionId> AND id != <item.RegionId> ...
|
|
// ... WHERE region_id = <item.RegionId> AND id != <item.RegionId> ...
|