Skip to content

Commit

Permalink
Merge branch 'master' into bugfix-check-saving
Browse files Browse the repository at this point in the history
  • Loading branch information
ebb-tide authored Oct 8, 2019
2 parents dab60b7 + 5a546d5 commit bc80436
Show file tree
Hide file tree
Showing 20 changed files with 451 additions and 108 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ vendor
.vs
.tern-project
.DS_Store
.idea

# binary databases
influxd.bolt
Expand Down
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
## v2.0.0-alpha.19 [unreleased]

### Features

### UI Improvements
1. [15313](https://github.com/influxdata/influxdb/pull/15313): Add shortcut for toggling comments in script editor

### Bug Fixes

1. [15295](https://github.com/influxdata/influxdb/pull/15295): Ensures users are created with an active status
2. [15306](https://github.com/influxdata/influxdb/pull/15306): Added missing string values for CacheStatus type
1. [15348](https://github.com/influxdata/influxdb/pull/15348): Disable saving for threshold check if not threshold defined

## v2.0.0-alpha.18 [2019-09-26]
Expand Down
2 changes: 2 additions & 0 deletions bolt/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

bolt "github.com/coreos/bbolt"
influxdb "github.com/influxdata/influxdb"
platform "github.com/influxdata/influxdb"
platformcontext "github.com/influxdata/influxdb/context"
)
Expand Down Expand Up @@ -226,6 +227,7 @@ func (c *Client) CreateUser(ctx context.Context, u *platform.User) error {
}

u.ID = c.IDGenerator.ID()
u.Status = influxdb.Active

if err := c.appendUserEventToLog(ctx, tx, u.ID, userCreatedEvent); err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions cmd/influxd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ func (m *Launcher) run(ctx context.Context) (err error) {

h := http.NewHandlerFromRegistry("platform", m.reg)
h.Handler = platformHandler
if logconf.Level == zap.DebugLevel {
h.Handler = http.HTTPLoggingMW(httpLogger)(h.Handler)
}
h.Logger = httpLogger

m.httpServer.Handler = h
Expand Down
4 changes: 2 additions & 2 deletions http/api_handler.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package http

import (
http "net/http"
"net/http"
"strings"

influxdb "github.com/influxdata/influxdb"
"github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/authorizer"
"github.com/influxdata/influxdb/chronograf/server"
"github.com/influxdata/influxdb/http/metric"
Expand Down
22 changes: 0 additions & 22 deletions http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package http
import (
"context"
"encoding/json"
"errors"
"net/http"
_ "net/http/pprof" // used for debug pprof at the default path.
"strings"
Expand Down Expand Up @@ -101,7 +100,6 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer func(start time.Time) {
duration := time.Since(start)
statusClass := statusW.statusCodeClass()
statusCode := statusW.code()
h.requests.With(prometheus.Labels{
"handler": h.name,
"method": r.Method,
Expand All @@ -116,26 +114,6 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
"status": statusClass,
"user_agent": userAgent,
}).Observe(duration.Seconds())
if h.Logger != nil {
errField := zap.Skip()
if errStr := w.Header().Get(PlatformErrorCodeHeader); errStr != "" {
errField = zap.Error(errors.New(errStr))
}
errReferenceField := zap.Skip()
if errReference := w.Header().Get(PlatformErrorCodeHeader); errReference != "" {
errReferenceField = zap.String("error_code", PlatformErrorCodeHeader)
}

h.Logger.Debug("Request",
zap.String("handler", h.name),
zap.String("method", r.Method),
zap.String("path", r.URL.Path),
zap.Int("status", statusCode),
zap.Int("duration_ns", int(duration)),
errField,
errReferenceField,
)
}
}(time.Now())

switch {
Expand Down
2 changes: 1 addition & 1 deletion http/notification_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func NewNotificationRuleHandler(b *NotificationRuleBackend) *NotificationRuleHan
LabelService: b.LabelService,
ResourceType: influxdb.TelegrafsResourceType,
}
h.HandlerFunc("GET", notificationRulesIDLabelsIDPath, newGetLabelsHandler(labelBackend))
h.HandlerFunc("GET", notificationRulesIDLabelsPath, newGetLabelsHandler(labelBackend))
h.HandlerFunc("POST", notificationRulesIDLabelsPath, newPostLabelHandler(labelBackend))
h.HandlerFunc("DELETE", notificationRulesIDLabelsIDPath, newDeleteLabelHandler(labelBackend))

Expand Down
67 changes: 67 additions & 0 deletions http/platform_handler.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package http

import (
"bytes"
"errors"
"io"
"net/http"
"strings"
"time"

"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
)

// PlatformHandler is a collection of all the service handlers.
Expand All @@ -22,6 +27,68 @@ func setCORSResponseHeaders(w http.ResponseWriter, r *http.Request) {
}
}

type bodyEchoer struct {
rc io.ReadCloser
teedR io.Reader
}

func (b *bodyEchoer) Read(p []byte) (int, error) {
return b.teedR.Read(p)
}

func (b *bodyEchoer) Close() error {
return b.rc.Close()
}

func HTTPLoggingMW(logger *zap.Logger) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
srw := &statusResponseWriter{
ResponseWriter: w,
}

var buf bytes.Buffer
r.Body = &bodyEchoer{
rc: r.Body,
teedR: io.TeeReader(r.Body, &buf),
}

defer func(start time.Time) {
errField := zap.Skip()
if errStr := w.Header().Get(PlatformErrorCodeHeader); errStr != "" {
errField = zap.Error(errors.New(errStr))
}

errReferenceField := zap.Skip()
if errReference := w.Header().Get(PlatformErrorCodeHeader); errReference != "" {
errReferenceField = zap.String("error_code", PlatformErrorCodeHeader)
}

logger.Debug(
"Request",
zap.String("method", r.Method),
zap.String("host", r.Host),
zap.String("path", r.URL.Path),
zap.String("query", r.URL.Query().Encode()),
zap.String("proto", r.Proto),
zap.Int("status_code", srw.code()),
zap.Int("response_size", srw.responseBytes),
zap.Int64("content_length", r.ContentLength),
zap.String("referrer", r.Referer()),
zap.String("remote", r.RemoteAddr),
zap.String("user_agent", r.UserAgent()),
zap.ByteString("body", buf.Bytes()),
zap.Duration("took", time.Since(start)),
errField,
errReferenceField,
)
}(time.Now())
next.ServeHTTP(srw, r)
}
return http.HandlerFunc(fn)
}
}

// NewPlatformHandler returns a platform handler that serves the API and associated assets.
func NewPlatformHandler(b *APIBackend) *PlatformHandler {
h := NewAuthenticationHandler(b.HTTPErrorHandler)
Expand Down
2 changes: 2 additions & 0 deletions inmem/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/influxdata/influxdb"
platform "github.com/influxdata/influxdb"
)

Expand Down Expand Up @@ -157,6 +158,7 @@ func (s *Service) CreateUser(ctx context.Context, u *platform.User) error {
}
}
u.ID = s.IDGenerator.ID()
u.Status = influxdb.Active
s.PutUser(ctx, u)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion kv/notification_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (s *Service) findNotificationRuleByID(ctx context.Context, tx Tx, id influx
// Additional options provide pagination & sorting.
func (s *Service) FindNotificationRules(ctx context.Context, filter influxdb.NotificationRuleFilter, opt ...influxdb.FindOptions) (nrs []influxdb.NotificationRule, n int, err error) {
err = s.kv.View(ctx, func(tx Tx) error {
nrs, n, err = s.findNotificationRules(ctx, tx, filter)
nrs, n, err = s.findNotificationRules(ctx, tx, filter, opt...)
return err
})
return nrs, n, err
Expand Down
1 change: 1 addition & 0 deletions kv/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (s *Service) createUser(ctx context.Context, tx Tx, u *influxdb.User) error
}

u.ID = s.IDGenerator.ID()
u.Status = influxdb.Active
if err := s.appendUserEventToLog(ctx, tx, u.ID, userCreatedEvent); err != nil {
return err
}
Expand Down
Loading

0 comments on commit bc80436

Please sign in to comment.