Skip to content

Commit

Permalink
Merge remote-tracking branch 'grafana/master' into more-packages
Browse files Browse the repository at this point in the history
* grafana/master:
  Prometheus: Use overridden panel range as $_range instead of dashboard range (grafana#17352)
  Update latest (grafana#17456)
  NavModel: Fixed page header ui tabs issues for some admin pages (grafana#17444)
  Update changelog for 6.2.2 (grafana#17452)
  PluginConfig: Fixed plugin config page navigation when using subpath (grafana#17364)
  Tracing: allow propagation with Zipkin headers (grafana#17009)
  Perf: Fix slow dashboards ACL query (grafana#17427)
  Explore: Fixes crash when parsing date math string with whitespace (grafana#17446)
  Cloudwatch: Add AWS DocDB metrics (grafana#17241)
  Provisioning: Support folder that doesn't exist yet in dashboard provisioning (grafana#17407)
  Codestyle: Fix govet issues (grafana#17178)
  • Loading branch information
ryantxu committed Jun 6, 2019
2 parents 407d833 + 6068257 commit 3df2661
Show file tree
Hide file tree
Showing 38 changed files with 795 additions and 101 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# 6.3.0 (unreleased)

# 6.2.2 (2019-06-05)

### Features / Enhancements
* **Security**: Prevent CSV formula injection attack when exporting data. [#17363](https://github.com/grafana/grafana/pull/17363), [@DanCech](https://github.com/DanCech)

### Bug Fixes
* **CloudWatch**: Fixes error when hiding/disabling queries . [#17283](https://github.com/grafana/grafana/pull/17283), [@jpiccari](https://github.com/jpiccari)
* **Database**: Fixed slow permission query in folder/dashboard search. [#17427](https://github.com/grafana/grafana/pull/17427), [@aocenas](https://github.com/aocenas)
* **Explore**: Fixed updating time range before running queries. [#17349](https://github.com/grafana/grafana/pull/17349), [@marefr](https://github.com/marefr)
* **Plugins**: Fixed plugin config page navigation when using subpath. [#17364](https://github.com/grafana/grafana/pull/17364), [@torkelo](https://github.com/torkelo)

# 6.2.1 (2019-05-27)

### Features / Enhancements
Expand Down
5 changes: 5 additions & 0 deletions conf/defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,11 @@ sampler_type = const
# and indicates the initial sampling rate before the actual one
# is received from the mothership
sampler_param = 1
# Whether or not to use Zipkin span propagation (x-b3- HTTP headers).
zipkin_propagation = false
# Setting this to true disables shared RPC spans.
# Not disabling is the most common setting when using Zipkin elsewhere in your infrastructure.
disable_shared_zipkin_spans = false

#################################### External Image Storage ##############
[external_image_storage]
Expand Down
6 changes: 5 additions & 1 deletion conf/sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ log_queries =
# and indicates the initial sampling rate before the actual one
# is received from the mothership
;sampler_param = 1
# Whether or not to use Zipkin propagation (x-b3- HTTP headers).
;zipkin_propagation = false
# Setting this to true disables shared RPC spans.
# Not disabling is the most common setting when using Zipkin elsewhere in your infrastructure.
;disable_shared_zipkin_spans = false

#################################### Grafana.com integration ##########################
# Url used to import dashboards directly from Grafana.com
Expand Down Expand Up @@ -530,4 +535,3 @@ log_queries =
[plugins]
;enable_alpha = false
;app_tls_skip_verify_insecure = false

4 changes: 2 additions & 2 deletions latest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"stable": "6.2.1",
"testing": "6.2.1"
"stable": "6.2.2",
"testing": "6.2.2"
}
5 changes: 5 additions & 0 deletions packages/grafana-ui/src/utils/datemath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,10 @@ describe('DateMath', () => {
const date = dateMath.parseDateMath('2', dateTime([2014, 1, 5]));
expect(date).toEqual(undefined);
});

it('should strip whitespace from string', () => {
const date = dateMath.parseDateMath(' - 2d', dateTime([2014, 1, 5]));
expect(date!.valueOf()).toEqual(dateTime([2014, 1, 3]).valueOf());
});
});
});
17 changes: 9 additions & 8 deletions packages/grafana-ui/src/utils/datemath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ export function isValid(text: string | DateTime): boolean {
*/
// TODO: Had to revert Andrejs `time: moment.Moment` to `time: any`
export function parseDateMath(mathString: string, time: any, roundUp?: boolean): DateTime | undefined {
const strippedMathString = mathString.replace(/\s/g, '');
const dateTime = time;
let i = 0;
const len = mathString.length;
const len = strippedMathString.length;

while (i < len) {
const c = mathString.charAt(i++);
const c = strippedMathString.charAt(i++);
let type;
let num;
let unit;
Expand All @@ -107,19 +108,19 @@ export function parseDateMath(mathString: string, time: any, roundUp?: boolean):
return undefined;
}

if (isNaN(parseInt(mathString.charAt(i), 10))) {
if (isNaN(parseInt(strippedMathString.charAt(i), 10))) {
num = 1;
} else if (mathString.length === 2) {
num = mathString.charAt(i);
} else if (strippedMathString.length === 2) {
num = strippedMathString.charAt(i);
} else {
const numFrom = i;
while (!isNaN(parseInt(mathString.charAt(i), 10))) {
while (!isNaN(parseInt(strippedMathString.charAt(i), 10))) {
i++;
if (i > 10) {
return undefined;
}
}
num = parseInt(mathString.substring(numFrom, i), 10);
num = parseInt(strippedMathString.substring(numFrom, i), 10);
}

if (type === 0) {
Expand All @@ -128,7 +129,7 @@ export function parseDateMath(mathString: string, time: any, roundUp?: boolean):
return undefined;
}
}
unit = mathString.charAt(i++);
unit = strippedMathString.charAt(i++);

if (!includes(units, unit)) {
return undefined;
Expand Down
1 change: 1 addition & 0 deletions pkg/api/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func GetTestDataScenarios(c *m.ReqContext) Response {
// Generates a index out of range error
func GenerateError(c *m.ReqContext) Response {
var array []string
// nolint: govet
return JSON(200, array[20])
}

Expand Down
5 changes: 0 additions & 5 deletions pkg/api/pluginproxy/pluginproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ func NewApiPluginProxy(ctx *m.ReqContext, proxyPath string, route *plugins.AppPl
req.URL.Host = targetURL.Host
req.Host = targetURL.Host
req.URL.Path = util.JoinURLFragments(targetURL.Path, proxyPath)

if err != nil {
ctx.JsonApiErr(500, "Could not interpolate plugin route url", err)
return
}
}

// reqBytes, _ := httputil.DumpRequestOut(req, true);
Expand Down
21 changes: 20 additions & 1 deletion pkg/bus/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ import (
"reflect"
)

// HandlerFunc defines a handler function interface.
type HandlerFunc interface{}

// CtxHandlerFunc defines a context handler function.
type CtxHandlerFunc func()

// Msg defines a message interface.
type Msg interface{}

// ErrHandlerNotFound defines an error if a handler is not found
var ErrHandlerNotFound = errors.New("handler not found")

// TransactionManager defines a transaction interface
type TransactionManager interface {
InTransaction(ctx context.Context, fn func(ctx context.Context) error) error
}

// Bus type defines the bus interface structure
type Bus interface {
Dispatch(msg Msg) error
DispatchCtx(ctx context.Context, msg Msg) error
Expand All @@ -38,10 +46,12 @@ type Bus interface {
SetTransactionManager(tm TransactionManager)
}

// InTransaction defines an in transaction function
func (b *InProcBus) InTransaction(ctx context.Context, fn func(ctx context.Context) error) error {
return b.txMng.InTransaction(ctx, fn)
}

// InProcBus defines the bus structure
type InProcBus struct {
handlers map[string]HandlerFunc
handlersWithCtx map[string]HandlerFunc
Expand All @@ -53,6 +63,7 @@ type InProcBus struct {
// temp stuff, not sure how to handle bus instance, and init yet
var globalBus = New()

// New initialize the bus
func New() Bus {
bus := &InProcBus{}
bus.handlers = make(map[string]HandlerFunc)
Expand All @@ -69,10 +80,12 @@ func GetBus() Bus {
return globalBus
}

// SetTransactionManager function assign a transaction manager to the bus.
func (b *InProcBus) SetTransactionManager(tm TransactionManager) {
b.txMng = tm
}

// DispatchCtx function dispatch a message to the bus context.
func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error {
var msgName = reflect.TypeOf(msg).Elem().Name()

Expand All @@ -93,6 +106,7 @@ func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error {
return err.(error)
}

// Dispatch function dispatch a message to the bus.
func (b *InProcBus) Dispatch(msg Msg) error {
var msgName = reflect.TypeOf(msg).Elem().Name()

Expand Down Expand Up @@ -122,6 +136,7 @@ func (b *InProcBus) Dispatch(msg Msg) error {
return err.(error)
}

// Publish function publish a message to the bus listener.
func (b *InProcBus) Publish(msg Msg) error {
var msgName = reflect.TypeOf(msg).Elem().Name()
var listeners = b.listeners[msgName]
Expand Down Expand Up @@ -174,21 +189,25 @@ func (b *InProcBus) AddEventListener(handler HandlerFunc) {
b.listeners[eventName] = append(b.listeners[eventName], handler)
}

// Package level functions
// AddHandler attach a handler function to the global bus
// Package level function
func AddHandler(implName string, handler HandlerFunc) {
globalBus.AddHandler(handler)
}

// AddHandlerCtx attach a handler function to the global bus context
// Package level functions
func AddHandlerCtx(implName string, handler HandlerFunc) {
globalBus.AddHandlerCtx(handler)
}

// AddEventListener attach a handler function to the event listener
// Package level functions
func AddEventListener(handler HandlerFunc) {
globalBus.AddEventListener(handler)
}

// AddWildcardListener attach a handler function to the wildcard listener
func AddWildcardListener(handler HandlerFunc) {
globalBus.AddWildcardListener(handler)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/bus/bus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type testQuery struct {
Id int64
ID int64
Resp string
}

Expand Down Expand Up @@ -64,9 +64,9 @@ func TestQueryHandlerReturnsError(t *testing.T) {
err := bus.Dispatch(&testQuery{})

if err == nil {
t.Fatal("Send query failed " + err.Error())
t.Fatal("Send query failed")
} else {
t.Log("Handler error received ok")
t.Log("Handler error received ok " + err.Error())
}
}

Expand All @@ -93,7 +93,7 @@ func TestEventListeners(t *testing.T) {
count := 0

bus.AddEventListener(func(query *testQuery) error {
count += 1
count++
return nil
})

Expand Down
8 changes: 0 additions & 8 deletions pkg/cmd/grafana-cli/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ func ListAllPlugins(repoUrl string) (m.PluginRepo, error) {
return m.PluginRepo{}, fmt.Errorf("Failed to send request. error: %v", err)
}

if err != nil {
return m.PluginRepo{}, err
}

var data m.PluginRepo
err = json.Unmarshal(body, &data)
if err != nil {
Expand Down Expand Up @@ -137,10 +133,6 @@ func GetPlugin(pluginId, repoUrl string) (m.Plugin, error) {
return m.Plugin{}, fmt.Errorf("Failed to send request. error: %v", err)
}

if err != nil {
return m.Plugin{}, err
}

var data m.Plugin
err = json.Unmarshal(body, &data)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions pkg/components/imguploader/azureblobuploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ func (az *AzureBlobUploader) Upload(ctx context.Context, imageDiskPath string) (
return "", aerr
}

if err != nil {
return "", err
}

url := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", az.account_name, az.container_name, randomFileName)
return url, nil
}
Expand Down
8 changes: 1 addition & 7 deletions pkg/infra/remotecache/redis_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,10 @@ func (s *redisStorage) Get(key string) (interface{}, error) {
if err == nil {
return item.Val, nil
}

if err.Error() == "EOF" {
return nil, ErrCacheItemNotFound
}

if err != nil {
return nil, err
}

return item.Val, nil
return nil, err
}

// Delete delete a key from session.
Expand Down
37 changes: 28 additions & 9 deletions pkg/infra/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tracing

import (
"context"
"fmt"
"io"
"strings"

Expand All @@ -11,20 +12,23 @@ import (

opentracing "github.com/opentracing/opentracing-go"
jaegercfg "github.com/uber/jaeger-client-go/config"
"github.com/uber/jaeger-client-go/zipkin"
)

func init() {
registry.RegisterService(&TracingService{})
}

type TracingService struct {
enabled bool
address string
customTags map[string]string
samplerType string
samplerParam float64
log log.Logger
closer io.Closer
enabled bool
address string
customTags map[string]string
samplerType string
samplerParam float64
log log.Logger
closer io.Closer
zipkinPropagation bool
disableSharedZipkinSpans bool

Cfg *setting.Cfg `inject:""`
}
Expand Down Expand Up @@ -54,6 +58,8 @@ func (ts *TracingService) parseSettings() {
ts.customTags = splitTagSettings(section.Key("always_included_tag").MustString(""))
ts.samplerType = section.Key("sampler_type").MustString("")
ts.samplerParam = section.Key("sampler_param").MustFloat64(1)
ts.zipkinPropagation = section.Key("zipkin_propagation").MustBool(false)
ts.disableSharedZipkinSpans = section.Key("disable_shared_zipkin_spans").MustBool(false)
}

func (ts *TracingService) initGlobalTracer() error {
Expand All @@ -79,6 +85,18 @@ func (ts *TracingService) initGlobalTracer() error {
options = append(options, jaegercfg.Tag(tag, value))
}

if ts.zipkinPropagation {
zipkinPropagator := zipkin.NewZipkinB3HTTPHeaderPropagator()
options = append(options,
jaegercfg.Injector(opentracing.HTTPHeaders, zipkinPropagator),
jaegercfg.Extractor(opentracing.HTTPHeaders, zipkinPropagator),
)

if !ts.disableSharedZipkinSpans {
options = append(options, jaegercfg.ZipkinSharedRPCSpan(true))
}
}

tracer, closer, err := cfg.NewTracer(options...)
if err != nil {
return err
Expand Down Expand Up @@ -124,6 +142,7 @@ func (jlw *jaegerLogWrapper) Error(msg string) {
jlw.logger.Error(msg)
}

func (jlw *jaegerLogWrapper) Infof(msg string, args ...interface{}) {
jlw.logger.Info(msg, args)
func (jlw *jaegerLogWrapper) Infof(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
jlw.logger.Info(msg)
}
Loading

0 comments on commit 3df2661

Please sign in to comment.