Skip to content
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

fix: remove operation log system #18459

Merged
merged 1 commit into from Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 0 additions & 40 deletions http/bucket_service.go
Expand Up @@ -62,7 +62,6 @@ type BucketHandler struct {
const (
prefixBuckets = "/api/v2/buckets"
bucketsIDPath = "/api/v2/buckets/:id"
bucketsIDLogPath = "/api/v2/buckets/:id/logs"
bucketsIDMembersPath = "/api/v2/buckets/:id/members"
bucketsIDMembersIDPath = "/api/v2/buckets/:id/members/:userID"
bucketsIDOwnersPath = "/api/v2/buckets/:id/owners"
Expand All @@ -89,7 +88,6 @@ func NewBucketHandler(log *zap.Logger, b *BucketBackend) *BucketHandler {
h.HandlerFunc("POST", prefixBuckets, h.handlePostBucket)
h.HandlerFunc("GET", prefixBuckets, h.handleGetBuckets)
h.HandlerFunc("GET", bucketsIDPath, h.handleGetBucket)
h.HandlerFunc("GET", bucketsIDLogPath, h.handleGetBucketLog)
h.HandlerFunc("PATCH", bucketsIDPath, h.handlePatchBucket)
h.HandlerFunc("DELETE", bucketsIDPath, h.handleDeleteBucket)

Expand Down Expand Up @@ -420,44 +418,6 @@ func bucketIDPath(id influxdb.ID) string {
return path.Join(prefixBuckets, id.String())
}

// handleGetBucketLog retrieves a bucket log by the buckets ID.
func (h *BucketHandler) handleGetBucketLog(w http.ResponseWriter, r *http.Request) {
id, err := decodeIDFromCtx(r.Context(), "id")
if err != nil {
h.api.Err(w, r, err)
return
}

opts, err := influxdb.DecodeFindOptions(r)
if err != nil {
h.api.Err(w, r, err)
return
}

log, _, err := h.BucketOperationLogService.GetBucketOperationLog(r.Context(), id, *opts)
if err != nil {
h.api.Err(w, r, err)
return
}

h.log.Debug("Bucket log retrived", zap.String("bucket", fmt.Sprint(log)))

h.api.Respond(w, r, http.StatusOK, newBucketLogResponse(id, log))
}

func newBucketLogResponse(id influxdb.ID, es []*influxdb.OperationLogEntry) *operationLogResponse {
logs := make([]*operationLogEntryResponse, 0, len(es))
for _, e := range es {
logs = append(logs, newOperationLogEntryResponse(e))
}
return &operationLogResponse{
Links: map[string]string{
"self": fmt.Sprintf("/api/v2/buckets/%s/logs", id),
},
Logs: logs,
}
}

// handleDeleteBucket is the HTTP handler for the DELETE /api/v2/buckets/:id route.
func (h *BucketHandler) handleDeleteBucket(w http.ResponseWriter, r *http.Request) {
id, err := decodeIDFromCtx(r.Context(), "id")
Expand Down
92 changes: 0 additions & 92 deletions http/dashboard_service.go
Expand Up @@ -61,7 +61,6 @@ const (
dashboardsIDCellsIDPath = "/api/v2/dashboards/:id/cells/:cellID"
dashboardsIDCellsIDViewPath = "/api/v2/dashboards/:id/cells/:cellID/view"
dashboardsIDMembersPath = "/api/v2/dashboards/:id/members"
dashboardsIDLogPath = "/api/v2/dashboards/:id/logs"
dashboardsIDMembersIDPath = "/api/v2/dashboards/:id/members/:userID"
dashboardsIDOwnersPath = "/api/v2/dashboards/:id/owners"
dashboardsIDOwnersIDPath = "/api/v2/dashboards/:id/owners/:userID"
Expand All @@ -86,7 +85,6 @@ func NewDashboardHandler(log *zap.Logger, b *DashboardBackend) *DashboardHandler
h.HandlerFunc("POST", prefixDashboards, h.handlePostDashboard)
h.HandlerFunc("GET", prefixDashboards, h.handleGetDashboards)
h.HandlerFunc("GET", dashboardsIDPath, h.handleGetDashboard)
h.HandlerFunc("GET", dashboardsIDLogPath, h.handleGetDashboardLog)
h.HandlerFunc("DELETE", dashboardsIDPath, h.handleDeleteDashboard)
h.HandlerFunc("PATCH", dashboardsIDPath, h.handlePatchDashboard)

Expand Down Expand Up @@ -140,7 +138,6 @@ type dashboardLinks struct {
Members string `json:"members"`
Owners string `json:"owners"`
Cells string `json:"cells"`
Logs string `json:"logs"`
Labels string `json:"labels"`
Organization string `json:"org"`
}
Expand Down Expand Up @@ -181,7 +178,6 @@ func newDashboardResponse(d *influxdb.Dashboard, labels []*influxdb.Label) dashb
Members: fmt.Sprintf("/api/v2/dashboards/%s/members", d.ID),
Owners: fmt.Sprintf("/api/v2/dashboards/%s/owners", d.ID),
Cells: fmt.Sprintf("/api/v2/dashboards/%s/cells", d.ID),
Logs: fmt.Sprintf("/api/v2/dashboards/%s/logs", d.ID),
Labels: fmt.Sprintf("/api/v2/dashboards/%s/labels", d.ID),
Organization: fmt.Sprintf("/api/v2/orgs/%s", d.OrganizationID),
},
Expand Down Expand Up @@ -310,40 +306,6 @@ func newDashboardCellViewResponse(dashID, cellID influxdb.ID, v *influxdb.View)
}
}

type operationLogResponse struct {
Links map[string]string `json:"links"`
Logs []*operationLogEntryResponse `json:"logs"`
}

func newDashboardLogResponse(id influxdb.ID, es []*influxdb.OperationLogEntry) *operationLogResponse {
logs := make([]*operationLogEntryResponse, 0, len(es))
for _, e := range es {
logs = append(logs, newOperationLogEntryResponse(e))
}
return &operationLogResponse{
Links: map[string]string{
"self": fmt.Sprintf("/api/v2/dashboards/%s/logs", id),
},
Logs: logs,
}
}

type operationLogEntryResponse struct {
Links map[string]string `json:"links"`
*influxdb.OperationLogEntry
}

func newOperationLogEntryResponse(e *influxdb.OperationLogEntry) *operationLogEntryResponse {
links := map[string]string{}
if e.UserID.Valid() {
links["user"] = fmt.Sprintf("/api/v2/users/%s", e.UserID)
}
return &operationLogEntryResponse{
Links: links,
OperationLogEntry: e,
}
}

// handleGetDashboards returns all dashboards within the store.
func (h *DashboardHandler) handleGetDashboards(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
Expand Down Expand Up @@ -548,60 +510,6 @@ func decodeGetDashboardRequest(ctx context.Context, r *http.Request) (*getDashbo
}, nil
}

// hanldeGetDashboardLog retrieves a dashboard log by the dashboards ID.
func (h *DashboardHandler) handleGetDashboardLog(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := decodeGetDashboardLogRequest(ctx, r)
if err != nil {
h.HandleHTTPError(ctx, err, w)
return
}

log, _, err := h.DashboardOperationLogService.GetDashboardOperationLog(ctx, req.DashboardID, req.opts)
if err != nil {
h.HandleHTTPError(ctx, err, w)
return
}

h.log.Debug("Dashboard log retrieved", zap.String("log", fmt.Sprint(log)))

if err := encodeResponse(ctx, w, http.StatusOK, newDashboardLogResponse(req.DashboardID, log)); err != nil {
logEncodingError(h.log, r, err)
return
}
}

type getDashboardLogRequest struct {
DashboardID influxdb.ID
opts influxdb.FindOptions
}

func decodeGetDashboardLogRequest(ctx context.Context, r *http.Request) (*getDashboardLogRequest, error) {
params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id")
if id == "" {
return nil, &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "url missing id",
}
}

var i influxdb.ID
if err := i.DecodeFromString(id); err != nil {
return nil, err
}

opts, err := influxdb.DecodeFindOptions(r)
if err != nil {
return nil, err
}

return &getDashboardLogRequest{
DashboardID: i,
opts: *opts,
}, nil
}

// handleDeleteDashboard removes a dashboard by ID.
func (h *DashboardHandler) handleDeleteDashboard(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
Expand Down
10 changes: 0 additions & 10 deletions http/dashboard_test.go
Expand Up @@ -158,7 +158,6 @@ func TestService_handleGetDashboards(t *testing.T) {
"members": "/api/v2/dashboards/da7aba5e5d81e550/members",
"owners": "/api/v2/dashboards/da7aba5e5d81e550/owners",
"cells": "/api/v2/dashboards/da7aba5e5d81e550/cells",
"logs": "/api/v2/dashboards/da7aba5e5d81e550/logs",
"labels": "/api/v2/dashboards/da7aba5e5d81e550/labels"
}
},
Expand Down Expand Up @@ -186,7 +185,6 @@ func TestService_handleGetDashboards(t *testing.T) {
"org": "/api/v2/orgs/0000000000000001",
"members": "/api/v2/dashboards/0ca2204eca2204e0/members",
"owners": "/api/v2/dashboards/0ca2204eca2204e0/owners",
"logs": "/api/v2/dashboards/0ca2204eca2204e0/logs",
"cells": "/api/v2/dashboards/0ca2204eca2204e0/cells",
"labels": "/api/v2/dashboards/0ca2204eca2204e0/labels"
}
Expand Down Expand Up @@ -319,7 +317,6 @@ func TestService_handleGetDashboards(t *testing.T) {
"members": "/api/v2/dashboards/da7aba5e5d81e550/members",
"owners": "/api/v2/dashboards/da7aba5e5d81e550/owners",
"cells": "/api/v2/dashboards/da7aba5e5d81e550/cells",
"logs": "/api/v2/dashboards/da7aba5e5d81e550/logs",
"labels": "/api/v2/dashboards/da7aba5e5d81e550/labels"
}
}
Expand Down Expand Up @@ -481,7 +478,6 @@ func TestService_handleGetDashboard(t *testing.T) {
"org": "/api/v2/orgs/0000000000000001",
"members": "/api/v2/dashboards/020f755c3c082000/members",
"owners": "/api/v2/dashboards/020f755c3c082000/owners",
"logs": "/api/v2/dashboards/020f755c3c082000/logs",
"cells": "/api/v2/dashboards/020f755c3c082000/cells",
"labels": "/api/v2/dashboards/020f755c3c082000/labels"
}
Expand Down Expand Up @@ -562,7 +558,6 @@ func TestService_handleGetDashboard(t *testing.T) {
"org": "/api/v2/orgs/0000000000000001",
"members": "/api/v2/dashboards/020f755c3c082000/members",
"owners": "/api/v2/dashboards/020f755c3c082000/owners",
"logs": "/api/v2/dashboards/020f755c3c082000/logs",
"cells": "/api/v2/dashboards/020f755c3c082000/cells",
"labels": "/api/v2/dashboards/020f755c3c082000/labels"
}
Expand Down Expand Up @@ -641,7 +636,6 @@ func TestService_handleGetDashboard(t *testing.T) {
"org": "/api/v2/orgs/0000000000000001",
"members": "/api/v2/dashboards/020f755c3c082000/members",
"owners": "/api/v2/dashboards/020f755c3c082000/owners",
"logs": "/api/v2/dashboards/020f755c3c082000/logs",
"cells": "/api/v2/dashboards/020f755c3c082000/cells",
"labels": "/api/v2/dashboards/020f755c3c082000/labels"
}
Expand Down Expand Up @@ -716,7 +710,6 @@ func TestService_handleGetDashboard(t *testing.T) {
"org": "/api/v2/orgs/0000000000000001",
"members": "/api/v2/dashboards/020f755c3c082000/members",
"owners": "/api/v2/dashboards/020f755c3c082000/owners",
"logs": "/api/v2/dashboards/020f755c3c082000/logs",
"cells": "/api/v2/dashboards/020f755c3c082000/cells",
"labels": "/api/v2/dashboards/020f755c3c082000/labels"
}
Expand Down Expand Up @@ -878,7 +871,6 @@ func TestService_handlePostDashboard(t *testing.T) {
"org": "/api/v2/orgs/0000000000000001",
"members": "/api/v2/dashboards/020f755c3c082000/members",
"owners": "/api/v2/dashboards/020f755c3c082000/owners",
"logs": "/api/v2/dashboards/020f755c3c082000/logs",
"cells": "/api/v2/dashboards/020f755c3c082000/cells",
"labels": "/api/v2/dashboards/020f755c3c082000/labels"
}
Expand Down Expand Up @@ -1003,7 +995,6 @@ func TestService_handlePostDashboard(t *testing.T) {
"org": "/api/v2/orgs/0000000000000001",
"members": "/api/v2/dashboards/020f755c3c082000/members",
"owners": "/api/v2/dashboards/020f755c3c082000/owners",
"logs": "/api/v2/dashboards/020f755c3c082000/logs",
"cells": "/api/v2/dashboards/020f755c3c082000/cells",
"labels": "/api/v2/dashboards/020f755c3c082000/labels"
}
Expand Down Expand Up @@ -1246,7 +1237,6 @@ func TestService_handlePatchDashboard(t *testing.T) {
"org": "/api/v2/orgs/0000000000000001",
"members": "/api/v2/dashboards/020f755c3c082000/members",
"owners": "/api/v2/dashboards/020f755c3c082000/owners",
"logs": "/api/v2/dashboards/020f755c3c082000/logs",
"cells": "/api/v2/dashboards/020f755c3c082000/cells",
"labels": "/api/v2/dashboards/020f755c3c082000/labels"
}
Expand Down
39 changes: 0 additions & 39 deletions http/org_service.go
Expand Up @@ -61,7 +61,6 @@ type OrgHandler struct {
const (
prefixOrganizations = "/api/v2/orgs"
organizationsIDPath = "/api/v2/orgs/:id"
organizationsIDLogPath = "/api/v2/orgs/:id/logs"
organizationsIDMembersPath = "/api/v2/orgs/:id/members"
organizationsIDMembersIDPath = "/api/v2/orgs/:id/members/:userID"
organizationsIDOwnersPath = "/api/v2/orgs/:id/owners"
Expand Down Expand Up @@ -112,7 +111,6 @@ func NewOrgHandler(log *zap.Logger, b *OrgBackend) *OrgHandler {
h.HandlerFunc("POST", prefixOrganizations, h.handlePostOrg)
h.HandlerFunc("GET", prefixOrganizations, h.handleGetOrgs)
h.HandlerFunc("GET", organizationsIDPath, h.handleGetOrg)
h.HandlerFunc("GET", organizationsIDLogPath, h.handleGetOrgLog)
h.HandlerFunc("PATCH", organizationsIDPath, h.handlePatchOrg)
h.HandlerFunc("DELETE", organizationsIDPath, h.handleDeleteOrg)

Expand Down Expand Up @@ -402,43 +400,6 @@ func (h *OrgHandler) handleDeleteSecrets(w http.ResponseWriter, r *http.Request)
h.API.Respond(w, r, http.StatusNoContent, nil)
}

// hanldeGetOrganizationLog retrieves a organization log by the organizations ID.
func (h *OrgHandler) handleGetOrgLog(w http.ResponseWriter, r *http.Request) {
orgID, err := decodeIDFromCtx(r.Context(), "id")
if err != nil {
h.API.Err(w, r, err)
return
}

opts, err := influxdb.DecodeFindOptions(r)
if err != nil {
h.API.Err(w, r, err)
return
}

log, _, err := h.OrganizationOperationLogService.GetOrganizationOperationLog(r.Context(), orgID, *opts)
if err != nil {
h.API.Err(w, r, err)
return
}
h.log.Debug("Org logs retrieved", zap.String("log", fmt.Sprint(log)))

h.API.Respond(w, r, http.StatusOK, newOrganizationLogResponse(orgID, log))
}

func newOrganizationLogResponse(id influxdb.ID, es []*influxdb.OperationLogEntry) *operationLogResponse {
logs := make([]*operationLogEntryResponse, 0, len(es))
for _, e := range es {
logs = append(logs, newOperationLogEntryResponse(e))
}
return &operationLogResponse{
Links: map[string]string{
"self": fmt.Sprintf("/api/v2/orgs/%s/logs", id),
},
Logs: logs,
}
}

// SecretService connects to Influx via HTTP using tokens to manage secrets.
type SecretService struct {
Client *httpc.Client
Expand Down