Skip to content

Commit

Permalink
Merge pull request #18216 from influxdata/chore/merge-master
Browse files Browse the repository at this point in the history
chore: merge master into algo-w branch
  • Loading branch information
jlapacik authored May 26, 2020
2 parents 53165bf + 7db9f4c commit de1b1b3
Show file tree
Hide file tree
Showing 84 changed files with 4,489 additions and 499 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
## v2.0.0-beta.11 [unreleased]
## v2.0.0-beta.11 [2020-05-26]

### Features

1. [18011](https://github.com/influxdata/influxdb/pull/18011): Integrate UTC dropdown when making custom time range query
1. [18040](https://github.com/influxdata/influxdb/pull/18040): Allow for min OR max y-axis visualization settings rather than min AND max
1. [17764](https://github.com/influxdata/influxdb/pull/17764): Add CSV to line protocol conversion library
1. [18059](https://github.com/influxdata/influxdb/pull/18059): Make the dropdown width adjustable
1. [18173](https://github.com/influxdata/influxdb/pull/18173): Add version to /health response

### Bug Fixes

1. [18066](https://github.com/influxdata/influxdb/pull/18066): Fixed bug that wasn't persisting timeFormat for Graph + Single Stat selections
1. [17959](https://github.com/influxdata/influxdb/pull/17959): Authorizer now exposes full permission set
1. [18071](https://github.com/influxdata/influxdb/pull/18071): Fixed issue that was causing variable selections to hydrate all variable values

### UI Improvements
1. [18016](https://github.com/influxdata/influxdb/pull/18016): Remove the fancy scrollbars
1. [18171](https://github.com/influxdata/influxdb/pull/18171): Check status now displaying warning if loading a large amount

## v2.0.0-beta.10 [2020-05-07]

Expand Down
41 changes: 3 additions & 38 deletions authorization/middleware_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package authorization

import (
"context"
"fmt"

"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/metric"
Expand All @@ -18,10 +17,10 @@ type AuthMetrics struct {

var _ influxdb.AuthorizationService = (*AuthMetrics)(nil)

func NewAuthMetrics(reg prometheus.Registerer, s influxdb.AuthorizationService, opts ...MetricsOption) *AuthMetrics {
o := applyOpts(opts...)
func NewAuthMetrics(reg prometheus.Registerer, s influxdb.AuthorizationService, opts ...metric.MetricsOption) *AuthMetrics {
o := metric.ApplyMetricOpts(opts...)
return &AuthMetrics{
rec: metric.New(reg, o.applySuffix("token")),
rec: metric.New(reg, o.ApplySuffix("token")),
authService: s,
}
}
Expand Down Expand Up @@ -59,37 +58,3 @@ func (m *AuthMetrics) DeleteAuthorization(ctx context.Context, id influxdb.ID) e
err := m.authService.DeleteAuthorization(ctx, id)
return rec(err)
}

// Metrics options
type metricOpts struct {
serviceSuffix string
}

func defaultOpts() *metricOpts {
return &metricOpts{}
}

func (o *metricOpts) applySuffix(prefix string) string {
if o.serviceSuffix != "" {
return fmt.Sprintf("%s_%s", prefix, o.serviceSuffix)
}
return prefix
}

// MetricsOption is an option used by a metric middleware.
type MetricsOption func(*metricOpts)

// WithSuffix returns a metric option that applies a suffix to the service name of the metric.
func WithSuffix(suffix string) MetricsOption {
return func(opts *metricOpts) {
opts.serviceSuffix = suffix
}
}

func applyOpts(opts ...MetricsOption) *metricOpts {
o := defaultOpts()
for _, opt := range opts {
opt(o)
}
return o
}
2 changes: 1 addition & 1 deletion authorization/storage_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"

"github.com/buger/jsonparser"
influxdb "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kv"
jsonp "github.com/influxdata/influxdb/v2/pkg/jsonparser"
)
Expand Down
4 changes: 4 additions & 0 deletions cmd/influx/ping.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
Expand All @@ -18,6 +19,9 @@ func cmdPing(f *globalFlags, opts genericCLIOpts) *cobra.Command {

c := http.Client{
Timeout: 5 * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: flags.skipVerify},
},
}
url := flags.Host + "/health"
resp, err := c.Get(url)
Expand Down
13 changes: 7 additions & 6 deletions cmd/influxd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/influxdata/influxdb/v2/kit/cli"
"github.com/influxdata/influxdb/v2/kit/feature"
overrideflagger "github.com/influxdata/influxdb/v2/kit/feature/override"
"github.com/influxdata/influxdb/v2/kit/metric"
"github.com/influxdata/influxdb/v2/kit/prom"
"github.com/influxdata/influxdb/v2/kit/signals"
"github.com/influxdata/influxdb/v2/kit/tracing"
Expand Down Expand Up @@ -619,11 +620,11 @@ func (m *Launcher) run(ctx context.Context) (err error) {

if m.enableNewMetaStore {
ts := tenant.NewService(store)
userSvc = tenant.NewUserLogger(m.log.With(zap.String("store", "new")), tenant.NewUserMetrics(m.reg, ts, tenant.WithSuffix("new")))
orgSvc = tenant.NewOrgLogger(m.log.With(zap.String("store", "new")), tenant.NewOrgMetrics(m.reg, ts, tenant.WithSuffix("new")))
userResourceSvc = tenant.NewURMLogger(m.log.With(zap.String("store", "new")), tenant.NewUrmMetrics(m.reg, ts, tenant.WithSuffix("new")))
bucketSvc = tenant.NewBucketLogger(m.log.With(zap.String("store", "new")), tenant.NewBucketMetrics(m.reg, ts, tenant.WithSuffix("new")))
passwdsSvc = tenant.NewPasswordLogger(m.log.With(zap.String("store", "new")), tenant.NewPasswordMetrics(m.reg, ts, tenant.WithSuffix("new")))
userSvc = tenant.NewUserLogger(m.log.With(zap.String("store", "new")), tenant.NewUserMetrics(m.reg, ts, metric.WithSuffix("new")))
orgSvc = tenant.NewOrgLogger(m.log.With(zap.String("store", "new")), tenant.NewOrgMetrics(m.reg, ts, metric.WithSuffix("new")))
userResourceSvc = tenant.NewURMLogger(m.log.With(zap.String("store", "new")), tenant.NewUrmMetrics(m.reg, ts, metric.WithSuffix("new")))
bucketSvc = tenant.NewBucketLogger(m.log.With(zap.String("store", "new")), tenant.NewBucketMetrics(m.reg, ts, metric.WithSuffix("new")))
passwdsSvc = tenant.NewPasswordLogger(m.log.With(zap.String("store", "new")), tenant.NewPasswordMetrics(m.reg, ts, metric.WithSuffix("new")))
}

switch m.secretStore {
Expand Down Expand Up @@ -972,7 +973,7 @@ func (m *Launcher) run(ctx context.Context) (err error) {
{
onboardSvc := tenant.NewOnboardService(store, authSvc) // basic service
onboardSvc = tenant.NewAuthedOnboardSvc(onboardSvc) // with auth
onboardSvc = tenant.NewOnboardingMetrics(m.reg, onboardSvc, tenant.WithSuffix("new")) // with metrics
onboardSvc = tenant.NewOnboardingMetrics(m.reg, onboardSvc, metric.WithSuffix("new")) // with metrics
onboardSvc = tenant.NewOnboardingLogger(m.log.With(zap.String("handler", "onboard")), onboardSvc) // with logging

onboardHTTPServer = tenant.NewHTTPOnboardHandler(m.log, onboardSvc)
Expand Down
4 changes: 3 additions & 1 deletion dbrp/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (s *Service) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilte
}
}

return ms, len(ms), s.store.View(ctx, func(tx kv.Tx) error {
err := s.store.View(ctx, func(tx kv.Tx) error {
// Optimized path, use index.
if orgID := filter.OrgID; orgID != nil {
// The index performs a prefix search.
Expand Down Expand Up @@ -338,6 +338,8 @@ func (s *Service) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilte
}
return nil
})

return ms, len(ms), err
}

// Create creates a new mapping.
Expand Down
4 changes: 3 additions & 1 deletion http/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package http
import (
"fmt"
"net/http"

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

// HealthHandler returns the status of the process.
func HealthHandler(w http.ResponseWriter, r *http.Request) {
msg := `{"name":"influxdb", "message":"ready for queries and writes", "status":"pass", "checks":[]}`
msg := fmt.Sprintf(`{"name":"influxdb", "message":"ready for queries and writes", "status":"pass", "checks":[], "version": %q, "commit": %q}`, platform.GetBuildInfo().Version, platform.GetBuildInfo().Commit)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, msg)
Expand Down
39 changes: 28 additions & 11 deletions http/health_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package http

import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
Expand All @@ -11,7 +12,7 @@ func TestHealthHandler(t *testing.T) {
type wants struct {
statusCode int
contentType string
body string
status string
}
tests := []struct {
name string
Expand All @@ -26,29 +27,45 @@ func TestHealthHandler(t *testing.T) {
wants: wants{
statusCode: http.StatusOK,
contentType: "application/json; charset=utf-8",
body: `{"name":"influxdb", "message":"ready for queries and writes", "status":"pass", "checks":[]}`,
status: "pass",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
HealthHandler(tt.w, tt.r)
res := tt.w.Result()
content := res.Header.Get("Content-Type")
contentType := res.Header.Get("Content-Type")
body, _ := ioutil.ReadAll(res.Body)

if res.StatusCode != tt.wants.statusCode {
t.Errorf("%q. HealthHandler() = %v, want %v", tt.name, res.StatusCode, tt.wants.statusCode)
}
if tt.wants.contentType != "" && content != tt.wants.contentType {
t.Errorf("%q. HealthHandler() = %v, want %v", tt.name, content, tt.wants.contentType)
if tt.wants.contentType != "" && contentType != tt.wants.contentType {
t.Errorf("%q. HealthHandler() = %v, want %v", tt.name, contentType, tt.wants.contentType)
}
if tt.wants.body != "" {
if eq, diff, err := jsonEqual(string(body), tt.wants.body); err != nil {
t.Errorf("%q, HealthHandler(). error unmarshaling json %v", tt.name, err)
} else if !eq {
t.Errorf("%q. HealthHandler() = ***%s***", tt.name, diff)
}
var content map[string]interface{}
if err := json.Unmarshal(body, &content); err != nil {
t.Errorf("%q, HealthHandler(). error unmarshaling json %v", tt.name, err)
return
}
if _, found := content["name"]; !found {
t.Errorf("%q. HealthHandler() no name reported", tt.name)
}
if content["status"] != tt.wants.status {
t.Errorf("%q. HealthHandler() status= %v, want %v", tt.name, content["status"], tt.wants.status)
}
if _, found := content["message"]; !found {
t.Errorf("%q. HealthHandler() no message reported", tt.name)
}
if _, found := content["checks"]; !found {
t.Errorf("%q. HealthHandler() no checks reported", tt.name)
}
if _, found := content["version"]; !found {
t.Errorf("%q. HealthHandler() no version reported", tt.name)
}
if _, found := content["commit"]; !found {
t.Errorf("%q. HealthHandler() no commit reported", tt.name)
}
})
}
Expand Down
4 changes: 4 additions & 0 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10893,6 +10893,10 @@ components:
enum:
- pass
- fail
version:
type: string
commit:
type: string
Labels:
type: array
items:
Expand Down
9 changes: 9 additions & 0 deletions id.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ var (
}
)

// ErrCorruptID means the ID stored in the Store is corrupt.
func ErrCorruptID(err error) *Error {
return &Error{
Code: EInvalid,
Msg: "corrupt ID provided",
Err: err,
}
}

// ID is a unique identifier.
//
// Its zero value is not a valid ID.
Expand Down
6 changes: 3 additions & 3 deletions tenant/metrics_options.go → kit/metric/metrics_options.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tenant
package metric

import "fmt"

Expand All @@ -10,7 +10,7 @@ func defaultOpts() *metricOpts {
return &metricOpts{}
}

func (o *metricOpts) applySuffix(prefix string) string {
func (o *metricOpts) ApplySuffix(prefix string) string {
if o.serviceSuffix != "" {
return fmt.Sprintf("%s_%s", prefix, o.serviceSuffix)
}
Expand All @@ -27,7 +27,7 @@ func WithSuffix(suffix string) MetricsOption {
}
}

func applyOpts(opts ...MetricsOption) *metricOpts {
func ApplyMetricOpts(opts ...MetricsOption) *metricOpts {
o := defaultOpts()
for _, opt := range opts {
opt(o)
Expand Down
42 changes: 42 additions & 0 deletions kit/transport/http/middleware.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package http

import (
"context"
"net/http"
"path"
"strings"
"time"

"github.com/go-chi/chi"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/tracing"
ua "github.com/mileusna/useragent"
Expand Down Expand Up @@ -130,3 +132,43 @@ func shiftPath(p string) (head, tail string) {
}
return p[1:i], p[i:]
}

type OrgContext string

const CtxOrgKey OrgContext = "orgID"

// ValidResource make sure a resource exists when a sub system needs to be mounted to an api
func ValidResource(api *API, lookupOrgByResourceID func(context.Context, influxdb.ID) (influxdb.ID, error)) Middleware {
return func(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
statusW := NewStatusResponseWriter(w)
id, err := influxdb.IDFromString(chi.URLParam(r, "id"))
if err != nil {
api.Err(w, r, influxdb.ErrCorruptID(err))
return
}

ctx := r.Context()

orgID, err := lookupOrgByResourceID(ctx, *id)
if err != nil {
api.Err(w, r, err)
return
}

// embed OrgID into context
next.ServeHTTP(statusW, r.WithContext(context.WithValue(ctx, CtxOrgKey, orgID)))
}
return http.HandlerFunc(fn)
}
}

// OrgIDFromContext ....
func OrgIDFromContext(ctx context.Context) *influxdb.ID {
v := ctx.Value(CtxOrgKey)
if v == nil {
return nil
}
id := v.(influxdb.ID)
return &id
}
8 changes: 8 additions & 0 deletions kv/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ func (s *Service) PutLabel(ctx context.Context, l *influxdb.Label) error {
})
}

// CreateUserResourceMappingForOrg is a public function that calls createUserResourceMappingForOrg used only for the label service
// it can be removed when URMs are removed from the label service
func (s *Service) CreateUserResourceMappingForOrg(ctx context.Context, tx Tx, orgID influxdb.ID, resID influxdb.ID, resType influxdb.ResourceType) error {
err := s.createUserResourceMappingForOrg(ctx, tx, orgID, resID, resType)

return err
}

func (s *Service) createUserResourceMappingForOrg(ctx context.Context, tx Tx, orgID influxdb.ID, resID influxdb.ID, resType influxdb.ResourceType) error {
span, ctx := tracing.StartSpanFromContext(ctx)
defer span.Finish()
Expand Down
Loading

0 comments on commit de1b1b3

Please sign in to comment.