From 4bb656b7043cdf156bdf47ded10efafcf87f6237 Mon Sep 17 00:00:00 2001 From: Julien Maitrehenry Date: Thu, 8 Oct 2015 00:22:09 -0400 Subject: [PATCH 01/56] #2834 - follow symlink --- pkg/plugins/plugins.go | 4 +- pkg/util/filepath.go | 98 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 pkg/util/filepath.go diff --git a/pkg/plugins/plugins.go b/pkg/plugins/plugins.go index 2f7e5264e53..a5767c7a70b 100644 --- a/pkg/plugins/plugins.go +++ b/pkg/plugins/plugins.go @@ -5,10 +5,10 @@ import ( "errors" "os" "path" - "path/filepath" "github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/setting" + "github.com/grafana/grafana/pkg/util" ) type PluginMeta struct { @@ -36,7 +36,7 @@ func scan(pluginDir string) error { pluginPath: pluginDir, } - if err := filepath.Walk(pluginDir, scanner.walker); err != nil { + if err := util.Walk(pluginDir, true, true, scanner.walker); err != nil { return err } diff --git a/pkg/util/filepath.go b/pkg/util/filepath.go new file mode 100644 index 00000000000..d0e27926956 --- /dev/null +++ b/pkg/util/filepath.go @@ -0,0 +1,98 @@ +package util + +import ( + "errors" + "fmt" + "io/ioutil" + "os" + "path/filepath" +) + +//WalkSkipDir is the Error returned when we want to skip descending into a directory +var WalkSkipDir = errors.New("skip this directory") + +//WalkFunc is a callback function called for each path as a directory is walked +//If resolvedPath != "", then we are following symbolic links. +type WalkFunc func(resolvedPath string, info os.FileInfo, err error) error + +//Walk walks a path, optionally following symbolic links, and for each path, +//it calls the walkFn passed. +// +//It is similar to filepath.Walk, except that it supports symbolic links and +//can detect infinite loops while following sym links. +//It solves the issue where your WalkFunc needs a path relative to the symbolic link +//(resolving links within walkfunc loses the path to the symbolic link for each traversal). +func Walk(path string, followSymlinks bool, detectSymlinkInfiniteLoop bool, walkFn WalkFunc) error { + info, err := os.Lstat(path) + if err != nil { + return err + } + var symlinkPathsFollowed map[string]bool + var resolvedPath string + if followSymlinks { + resolvedPath = path + if detectSymlinkInfiniteLoop { + symlinkPathsFollowed = make(map[string]bool, 8) + } + } + return walk(path, info, resolvedPath, symlinkPathsFollowed, walkFn) +} + +//walk walks the path. It is a helper/sibling function to Walk. +//It takes a resolvedPath into consideration. This way, paths being walked are +//always relative to the path argument, even if symbolic links were resolved). +// +//If resolvedPath is "", then we are not following symbolic links. +//If symlinkPathsFollowed is not nil, then we need to detect infinite loop. +func walk(path string, info os.FileInfo, resolvedPath string, + symlinkPathsFollowed map[string]bool, walkFn WalkFunc) error { + if info == nil { + return errors.New("Walk: Nil FileInfo passed") + } + err := walkFn(resolvedPath, info, nil) + if err != nil { + if info.IsDir() && err == WalkSkipDir { + err = nil + } + return err + } + if resolvedPath != "" && info.Mode()&os.ModeSymlink == os.ModeSymlink { + path2, err := os.Readlink(resolvedPath) + if err != nil { + return err + } + //vout("SymLink Path: %v, links to: %v", resolvedPath, path2) + if symlinkPathsFollowed != nil { + if _, ok := symlinkPathsFollowed[path2]; ok { + errMsg := "Potential SymLink Infinite Loop. Path: %v, Link To: %v" + return fmt.Errorf(errMsg, resolvedPath, path2) + } else { + symlinkPathsFollowed[path2] = true + } + } + info2, err := os.Lstat(path2) + if err != nil { + return err + } + return walk(path, info2, path2, symlinkPathsFollowed, walkFn) + } + if info.IsDir() { + list, err := ioutil.ReadDir(path) + if err != nil { + return walkFn(resolvedPath, info, err) + } + for _, fileInfo := range list { + path2 := filepath.Join(path, fileInfo.Name()) + var resolvedPath2 string + if resolvedPath != "" { + resolvedPath2 = filepath.Join(resolvedPath, fileInfo.Name()) + } + err = walk(path2, fileInfo, resolvedPath2, symlinkPathsFollowed, walkFn) + if err != nil { + return err + } + } + return nil + } + return nil +} From e4fecb48e37ee0144b198357cf4a3c891dd5cd29 Mon Sep 17 00:00:00 2001 From: Felix Barnsteiner Date: Fri, 23 Oct 2015 09:32:02 +0200 Subject: [PATCH 02/56] Add ability to set a global time interval The interval is configurable in the data source. This commit only adds the ability to Elasticsearch datasources --- public/app/features/panel/panelHelper.js | 4 +++- .../datasource/elasticsearch/datasource.js | 1 + .../elasticsearch/partials/config.html | 19 +++++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/public/app/features/panel/panelHelper.js b/public/app/features/panel/panelHelper.js index c7473692a43..f0d4f98ee9c 100644 --- a/public/app/features/panel/panelHelper.js +++ b/public/app/features/panel/panelHelper.js @@ -59,7 +59,9 @@ function (angular, dateMath, rangeUtil, _, kbn, $) { scope.resolution = Math.ceil($(window).width() * (scope.panel.span / 12)); } - scope.interval = kbn.calculateInterval(scope.range, scope.resolution, scope.panel.interval); + var panelInterval = scope.panel.interval; + var datasourceInterval = (scope.datasource || {}).interval; + scope.interval = kbn.calculateInterval(scope.range, scope.resolution, panelInterval || datasourceInterval); }; this.applyPanelTimeOverrides = function(scope) { diff --git a/public/app/plugins/datasource/elasticsearch/datasource.js b/public/app/plugins/datasource/elasticsearch/datasource.js index 374fc9da90d..21a5f929e89 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.js +++ b/public/app/plugins/datasource/elasticsearch/datasource.js @@ -24,6 +24,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes this.index = datasource.index; this.timeField = datasource.jsonData.timeField; this.indexPattern = new IndexPattern(datasource.index, datasource.jsonData.interval); + this.interval = datasource.jsonData.timeInterval; this.queryBuilder = new ElasticQueryBuilder({ timeField: this.timeField }); diff --git a/public/app/plugins/datasource/elasticsearch/partials/config.html b/public/app/plugins/datasource/elasticsearch/partials/config.html index d1cb05801d6..622d4cbdc86 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/config.html +++ b/public/app/plugins/datasource/elasticsearch/partials/config.html @@ -1,7 +1,7 @@

-
Elastic search details
+
Elasticsearch details
    @@ -20,7 +20,7 @@
-
+
  • Time field name @@ -31,3 +31,18 @@
+
+
    +
  • + Group by time interval +
  • +
  • + +
  • +
  • + +
  • +
+
+
From 2b6df412b7d38c36f49f975c7edb6dcd03ab7c5d Mon Sep 17 00:00:00 2001 From: ubhatnagar Date: Mon, 26 Oct 2015 23:20:47 -0700 Subject: [PATCH 03/56] Removed export/view permission from a dashboard viewer --- public/app/features/dashboard/partials/dashboardTopNav.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/app/features/dashboard/partials/dashboardTopNav.html b/public/app/features/dashboard/partials/dashboardTopNav.html index 8fa6da1ee2f..1aa417c752a 100644 --- a/public/app/features/dashboard/partials/dashboardTopNav.html +++ b/public/app/features/dashboard/partials/dashboardTopNav.html @@ -29,14 +29,14 @@
  • -
  • {{target.datasource}}
  • +
  • + + + +
  • - + + + + -
    +
    From b38dc70c715bc740cc1e179246155a9f82109441 Mon Sep 17 00:00:00 2001 From: addshore Date: Sat, 28 Nov 2015 00:16:42 +0100 Subject: [PATCH 15/56] Add graphtie sortByName natural param Introduced in graphite 0.9.15 Fixes #3360 --- public/app/plugins/datasource/graphite/gfunc.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/graphite/gfunc.js b/public/app/plugins/datasource/graphite/gfunc.js index 234486a3e1e..cc4cdf01bb7 100644 --- a/public/app/plugins/datasource/graphite/gfunc.js +++ b/public/app/plugins/datasource/graphite/gfunc.js @@ -279,7 +279,9 @@ function (_, $) { addFuncDef({ name: 'sortByName', - category: categories.Special + category: categories.Special, + params: [{ name: "natural", type: "select", options: ["true", "false"] }], + defaultParams: ["false"] }); addFuncDef({ From 384292b647de901f3bdc039f5baef15b35174627 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Wed, 2 Dec 2015 04:15:50 -0800 Subject: [PATCH 16/56] Removed metadata from dropdown, included in settings --- public/app/core/directives/dash_edit_link.js | 3 +- .../dashboard/partials/dashboardTopNav.html | 1 - .../features/dashboard/partials/metadata.html | 49 ------------------- .../features/dashboard/partials/settings.html | 32 +++++++++++- 4 files changed, 32 insertions(+), 53 deletions(-) delete mode 100644 public/app/features/dashboard/partials/metadata.html diff --git a/public/app/core/directives/dash_edit_link.js b/public/app/core/directives/dash_edit_link.js index 06c44cc8262..9ab74fe6d74 100644 --- a/public/app/core/directives/dash_edit_link.js +++ b/public/app/core/directives/dash_edit_link.js @@ -8,8 +8,7 @@ function ($, coreModule) { var editViewMap = { 'settings': { src: 'app/features/dashboard/partials/settings.html', title: "Settings" }, 'annotations': { src: 'app/features/annotations/partials/editor.html', title: "Annotations" }, - 'templating': { src: 'app/features/templating/partials/editor.html', title: "Templating" }, - 'metadata': { src: 'app/features/dashboard/partials/metadata.html', title: "Metadata" } + 'templating': { src: 'app/features/templating/partials/editor.html', title: "Templating" } }; coreModule.directive('dashEditorLink', function($timeout) { diff --git a/public/app/features/dashboard/partials/dashboardTopNav.html b/public/app/features/dashboard/partials/dashboardTopNav.html index baf6a9f3a62..8fa6da1ee2f 100644 --- a/public/app/features/dashboard/partials/dashboardTopNav.html +++ b/public/app/features/dashboard/partials/dashboardTopNav.html @@ -39,7 +39,6 @@
  • View JSON
  • Save As...
  • Delete dashboard
  • -
  • Metadata
  • diff --git a/public/app/features/dashboard/partials/metadata.html b/public/app/features/dashboard/partials/metadata.html deleted file mode 100644 index 11eaa6d542a..00000000000 --- a/public/app/features/dashboard/partials/metadata.html +++ /dev/null @@ -1,49 +0,0 @@ -
    -
    - - Metadata -
    - -
    - -
    -
    -
    -
    Dashboard info
    -
    -
      -
    • - Last updated at: -
    • -
    • - {{formatDate(dashboardMeta.updated)}} -
    • -
    -
    -
    -
    -
      -
    • - Created at: -
    • -
    • - {{formatDate(dashboardMeta.created)}} -
    • -
    -
    -
    -
    -
    -
    - - diff --git a/public/app/features/dashboard/partials/settings.html b/public/app/features/dashboard/partials/settings.html index 541ef45e9ab..347265afed4 100644 --- a/public/app/features/dashboard/partials/settings.html +++ b/public/app/features/dashboard/partials/settings.html @@ -5,7 +5,7 @@
    -
    +
    @@ -114,6 +114,36 @@
    +
    +
    +
    +
    Info
    +
    +
      +
    • + Last updated at: +
    • +
    • + {{formatDate(dashboardMeta.updated)}} +
    • +
    +
    +
    +
    +
      +
    • + Created at: +
    • +
    • + {{formatDate(dashboardMeta.created)}} +
    • +
    +
    +
    +
    +
    +
    +
    From a1f103576ac96a139a133500d9e4bd21f935e00c Mon Sep 17 00:00:00 2001 From: Greg Look Date: Wed, 2 Dec 2015 15:13:02 -0800 Subject: [PATCH 17/56] Wait for all panels to render in PhantomJS. --- vendor/phantomjs/render.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vendor/phantomjs/render.js b/vendor/phantomjs/render.js index 33fda200cba..5cd442eb338 100644 --- a/vendor/phantomjs/render.js +++ b/vendor/phantomjs/render.js @@ -36,7 +36,8 @@ page.open(params.url, function (status) { var canvas = page.evaluate(function() { var body = angular.element(document.body); // 1 var rootScope = body.scope().$root; - return rootScope.performance.panelsRendered > 0; + var panels = angular.element('div.panel').length; + return rootScope.performance.panelsRendered >= panels; }); if (canvas || tries === 1000) { From 3d90340446feaf8065b0d44b002021b6d074bd9a Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Sun, 6 Dec 2015 23:51:43 -0800 Subject: [PATCH 18/56] Added new columns to dashboard table --- pkg/services/sqlstore/migrations/dashboard_mig.go | 10 ++++++++++ pkg/services/sqlstore/migrator/migrations.go | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/pkg/services/sqlstore/migrations/dashboard_mig.go b/pkg/services/sqlstore/migrations/dashboard_mig.go index 5d440d85ebc..66ad02ba27d 100644 --- a/pkg/services/sqlstore/migrations/dashboard_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_mig.go @@ -92,4 +92,14 @@ func addDashboardMigration(mg *Migrator) { Sqlite("SELECT 0 WHERE 0;"). Postgres("SELECT 0;"). Mysql("ALTER TABLE dashboard MODIFY data MEDIUMTEXT;")) + + // add column to store creator of a dashboard + mg.AddMigration("Add column created_by", NewAddColumnMigration(dashboardV2, &Column{ + Name: "created_by", Type: DB_BigInt, Nullable: true, + })) + + // add column to store updater of a dashboard + mg.AddMigration("Add column updated_by", NewAddColumnMigration(dashboardV2, &Column{ + Name: "updated_by", Type: DB_BigInt, Nullable: true, + })) } diff --git a/pkg/services/sqlstore/migrator/migrations.go b/pkg/services/sqlstore/migrator/migrations.go index a65c7ec7e81..26387fcb7db 100644 --- a/pkg/services/sqlstore/migrator/migrations.go +++ b/pkg/services/sqlstore/migrator/migrations.go @@ -64,6 +64,10 @@ type AddColumnMigration struct { column *Column } +func NewAddColumnMigration(table Table, col *Column) *AddColumnMigration { + return &AddColumnMigration{tableName: table.Name, column: col} +} + func (m *AddColumnMigration) Table(tableName string) *AddColumnMigration { m.tableName = tableName return m From 42d12052606ef788a7abe8061aa54aade1c40761 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Sun, 6 Dec 2015 23:59:58 -0800 Subject: [PATCH 19/56] Fixed gofmt checks --- .../sqlstore/migrations/dashboard_mig.go | 16 ++++++++-------- pkg/services/sqlstore/migrator/migrations.go | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/services/sqlstore/migrations/dashboard_mig.go b/pkg/services/sqlstore/migrations/dashboard_mig.go index 66ad02ba27d..331dbf0ef2f 100644 --- a/pkg/services/sqlstore/migrations/dashboard_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_mig.go @@ -93,13 +93,13 @@ func addDashboardMigration(mg *Migrator) { Postgres("SELECT 0;"). Mysql("ALTER TABLE dashboard MODIFY data MEDIUMTEXT;")) - // add column to store creator of a dashboard - mg.AddMigration("Add column created_by", NewAddColumnMigration(dashboardV2, &Column{ - Name: "created_by", Type: DB_BigInt, Nullable: true, - })) + // add column to store creator of a dashboard + mg.AddMigration("Add column created_by", NewAddColumnMigration(dashboardV2, &Column{ + Name: "created_by", Type: DB_BigInt, Nullable: true, + })) - // add column to store updater of a dashboard - mg.AddMigration("Add column updated_by", NewAddColumnMigration(dashboardV2, &Column{ - Name: "updated_by", Type: DB_BigInt, Nullable: true, - })) + // add column to store updater of a dashboard + mg.AddMigration("Add column updated_by", NewAddColumnMigration(dashboardV2, &Column{ + Name: "updated_by", Type: DB_BigInt, Nullable: true, + })) } diff --git a/pkg/services/sqlstore/migrator/migrations.go b/pkg/services/sqlstore/migrator/migrations.go index 26387fcb7db..7d97abb6bb9 100644 --- a/pkg/services/sqlstore/migrator/migrations.go +++ b/pkg/services/sqlstore/migrator/migrations.go @@ -65,7 +65,7 @@ type AddColumnMigration struct { } func NewAddColumnMigration(table Table, col *Column) *AddColumnMigration { - return &AddColumnMigration{tableName: table.Name, column: col} + return &AddColumnMigration{tableName: table.Name, column: col} } func (m *AddColumnMigration) Table(tableName string) *AddColumnMigration { From 79d0f47ee70ac62c2d7a62a7d84c5277d3ec5b84 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Mon, 7 Dec 2015 04:24:29 -0800 Subject: [PATCH 20/56] Added columns in dashboard_snapshot --- .../sqlstore/migrations/dashboard_snapshot_mig.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go b/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go index b08cc451e55..26e7cea0a6e 100644 --- a/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go @@ -54,4 +54,15 @@ func addDashboardSnapshotMigrations(mg *Migrator) { Sqlite("SELECT 0 WHERE 0;"). Postgres("SELECT 0;"). Mysql("ALTER TABLE dashboard_snapshot MODIFY dashboard MEDIUMTEXT;")) + + // add column to store creator of a dashboard snapshot + mg.AddMigration("Add column created_by in dashboard_snapshot", NewAddColumnMigration(snapshotV5, &Column{ + Name: "created_by", Type: DB_BigInt, Nullable: true, + })) + + // add column to store updater of a dashboard snapshot + mg.AddMigration("Add column updated_by in dashboard_snapshot", NewAddColumnMigration(snapshotV5, &Column{ + Name: "updated_by", Type: DB_BigInt, Nullable: true, + })) + } From ed16914715fc278b184e60ebeee572e92acf6774 Mon Sep 17 00:00:00 2001 From: Daniel Low Date: Tue, 8 Dec 2015 13:35:09 +0000 Subject: [PATCH 21/56] Add memcache as session provider --- conf/defaults.ini | 4 +++- docs/sources/installation/configuration.md | 3 ++- pkg/middleware/session.go | 1 + pkg/setting/setting.go | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 69d045dc4ae..20b1f67a18b 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -67,7 +67,7 @@ path = grafana.db #################################### Session #################################### [session] -# Either "memory", "file", "redis", "mysql", "postgres", default is "file" +# Either "memory", "file", "redis", "mysql", "postgres", "memcache", default is "file" provider = file # Provider config options @@ -76,6 +76,8 @@ provider = file # redis: config like redis server e.g. `addr=127.0.0.1:6379,pool_size=100,db=grafana` # postgres: user=a password=b host=localhost port=5432 dbname=c sslmode=disable # mysql: go-sql-driver/mysql dsn config string, e.g. `user:password@tcp(127.0.0.1:3306)/database_name` +# memcache: 127.0.0.1:11211 + provider_config = sessions diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index e68edcbca0c..daa2d665e07 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -355,7 +355,7 @@ Set to `true` to enable auto sign up of users who do not exist in Grafana DB. De ### provider -Valid values are `memory`, `file`, `mysql`, `postgres`. Default is `file`. +Valid values are `memory`, `file`, `mysql`, `postgres`, `memcache`. Default is `file`. ### provider_config @@ -365,6 +365,7 @@ session provider you have configured. - **file:** session file path, e.g. `data/sessions` - **mysql:** go-sql-driver/mysql dsn config string, e.g. `user:password@tcp(127.0.0.1:3306)/database_name` - **postgres:** ex: user=a password=b host=localhost port=5432 dbname=c sslmode=disable +- **memcache:** ex: 127.0.0.1:11211 If you use MySQL or Postgres as the session store you need to create the session table manually. diff --git a/pkg/middleware/session.go b/pkg/middleware/session.go index fc1512e5bd6..57027f9bca7 100644 --- a/pkg/middleware/session.go +++ b/pkg/middleware/session.go @@ -8,6 +8,7 @@ import ( _ "github.com/macaron-contrib/session/mysql" _ "github.com/macaron-contrib/session/postgres" _ "github.com/macaron-contrib/session/redis" + _ "github.com/macaron-contrib/session/memcache" ) const ( diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index d6a853a9cdc..f28a7bcd1b3 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -473,7 +473,7 @@ func NewConfigContext(args *CommandLineArgs) error { func readSessionConfig() { sec := Cfg.Section("session") SessionOptions = session.Options{} - SessionOptions.Provider = sec.Key("provider").In("memory", []string{"memory", "file", "redis", "mysql", "postgres"}) + SessionOptions.Provider = sec.Key("provider").In("memory", []string{"memory", "file", "redis", "mysql", "postgres", "memcache"}) SessionOptions.ProviderConfig = strings.Trim(sec.Key("provider_config").String(), "\" ") SessionOptions.CookieName = sec.Key("cookie_name").MustString("grafana_sess") SessionOptions.CookiePath = AppSubUrl From d7f3869959e5596efa3c5e24dbd63168c4f552ff Mon Sep 17 00:00:00 2001 From: Daniel Low Date: Tue, 8 Dec 2015 14:59:54 +0000 Subject: [PATCH 22/56] gofmt --- pkg/middleware/session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/middleware/session.go b/pkg/middleware/session.go index 57027f9bca7..bad912aa46f 100644 --- a/pkg/middleware/session.go +++ b/pkg/middleware/session.go @@ -5,10 +5,10 @@ import ( "github.com/Unknwon/macaron" "github.com/macaron-contrib/session" + _ "github.com/macaron-contrib/session/memcache" _ "github.com/macaron-contrib/session/mysql" _ "github.com/macaron-contrib/session/postgres" _ "github.com/macaron-contrib/session/redis" - _ "github.com/macaron-contrib/session/memcache" ) const ( From 7bdeceff363402a185c3e0c6311a21155e5e7417 Mon Sep 17 00:00:00 2001 From: Daniel Low Date: Tue, 8 Dec 2015 16:18:40 +0000 Subject: [PATCH 23/56] add memcache as godep --- Godeps/Godeps.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 104bff7d5f1..ff7c252a3c8 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -155,6 +155,11 @@ "ImportPath": "gopkg.in/redis.v2", "Comment": "v2.3.2", "Rev": "e6179049628164864e6e84e973cfb56335748dea" - } + }, + { + "ImportPath": "github.com/bradfitz/gomemcache/memcache", + "Comment": "release.r60-40-g72a6864", + "Rev": "72a68649ba712ee7c4b5b4a943a626bcd7d90eb8" + } ] } From b97b23647eb58932179a6af0dae0a2c34c1aeff0 Mon Sep 17 00:00:00 2001 From: Daniel Low Date: Tue, 8 Dec 2015 16:32:27 +0000 Subject: [PATCH 24/56] memcache files in godep --- .../github.com/bradfitz/gomemcache/LICENSE | 202 ++++++ .../bradfitz/gomemcache/memcache/memcache.go | 669 ++++++++++++++++++ .../bradfitz/gomemcache/memcache/selector.go | 114 +++ 3 files changed, 985 insertions(+) create mode 100644 Godeps/_workspace/src/github.com/bradfitz/gomemcache/LICENSE create mode 100644 Godeps/_workspace/src/github.com/bradfitz/gomemcache/memcache/memcache.go create mode 100644 Godeps/_workspace/src/github.com/bradfitz/gomemcache/memcache/selector.go diff --git a/Godeps/_workspace/src/github.com/bradfitz/gomemcache/LICENSE b/Godeps/_workspace/src/github.com/bradfitz/gomemcache/LICENSE new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/Godeps/_workspace/src/github.com/bradfitz/gomemcache/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/Godeps/_workspace/src/github.com/bradfitz/gomemcache/memcache/memcache.go b/Godeps/_workspace/src/github.com/bradfitz/gomemcache/memcache/memcache.go new file mode 100644 index 00000000000..6eed4fbe003 --- /dev/null +++ b/Godeps/_workspace/src/github.com/bradfitz/gomemcache/memcache/memcache.go @@ -0,0 +1,669 @@ +/* +Copyright 2011 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package memcache provides a client for the memcached cache server. +package memcache + +import ( + "bufio" + "bytes" + "errors" + "fmt" + "io" + "io/ioutil" + "net" + + "strconv" + "strings" + "sync" + "time" +) + +// Similar to: +// http://code.google.com/appengine/docs/go/memcache/reference.html + +var ( + // ErrCacheMiss means that a Get failed because the item wasn't present. + ErrCacheMiss = errors.New("memcache: cache miss") + + // ErrCASConflict means that a CompareAndSwap call failed due to the + // cached value being modified between the Get and the CompareAndSwap. + // If the cached value was simply evicted rather than replaced, + // ErrNotStored will be returned instead. + ErrCASConflict = errors.New("memcache: compare-and-swap conflict") + + // ErrNotStored means that a conditional write operation (i.e. Add or + // CompareAndSwap) failed because the condition was not satisfied. + ErrNotStored = errors.New("memcache: item not stored") + + // ErrServer means that a server error occurred. + ErrServerError = errors.New("memcache: server error") + + // ErrNoStats means that no statistics were available. + ErrNoStats = errors.New("memcache: no statistics available") + + // ErrMalformedKey is returned when an invalid key is used. + // Keys must be at maximum 250 bytes long, ASCII, and not + // contain whitespace or control characters. + ErrMalformedKey = errors.New("malformed: key is too long or contains invalid characters") + + // ErrNoServers is returned when no servers are configured or available. + ErrNoServers = errors.New("memcache: no servers configured or available") +) + +// DefaultTimeout is the default socket read/write timeout. +const DefaultTimeout = 100 * time.Millisecond + +const ( + buffered = 8 // arbitrary buffered channel size, for readability + maxIdleConnsPerAddr = 2 // TODO(bradfitz): make this configurable? +) + +// resumableError returns true if err is only a protocol-level cache error. +// This is used to determine whether or not a server connection should +// be re-used or not. If an error occurs, by default we don't reuse the +// connection, unless it was just a cache error. +func resumableError(err error) bool { + switch err { + case ErrCacheMiss, ErrCASConflict, ErrNotStored, ErrMalformedKey: + return true + } + return false +} + +func legalKey(key string) bool { + if len(key) > 250 { + return false + } + for i := 0; i < len(key); i++ { + if key[i] <= ' ' || key[i] > 0x7e { + return false + } + } + return true +} + +var ( + crlf = []byte("\r\n") + space = []byte(" ") + resultOK = []byte("OK\r\n") + resultStored = []byte("STORED\r\n") + resultNotStored = []byte("NOT_STORED\r\n") + resultExists = []byte("EXISTS\r\n") + resultNotFound = []byte("NOT_FOUND\r\n") + resultDeleted = []byte("DELETED\r\n") + resultEnd = []byte("END\r\n") + resultOk = []byte("OK\r\n") + resultTouched = []byte("TOUCHED\r\n") + + resultClientErrorPrefix = []byte("CLIENT_ERROR ") +) + +// New returns a memcache client using the provided server(s) +// with equal weight. If a server is listed multiple times, +// it gets a proportional amount of weight. +func New(server ...string) *Client { + ss := new(ServerList) + ss.SetServers(server...) + return NewFromSelector(ss) +} + +// NewFromSelector returns a new Client using the provided ServerSelector. +func NewFromSelector(ss ServerSelector) *Client { + return &Client{selector: ss} +} + +// Client is a memcache client. +// It is safe for unlocked use by multiple concurrent goroutines. +type Client struct { + // Timeout specifies the socket read/write timeout. + // If zero, DefaultTimeout is used. + Timeout time.Duration + + selector ServerSelector + + lk sync.Mutex + freeconn map[string][]*conn +} + +// Item is an item to be got or stored in a memcached server. +type Item struct { + // Key is the Item's key (250 bytes maximum). + Key string + + // Value is the Item's value. + Value []byte + + // Object is the Item's value for use with a Codec. + Object interface{} + + // Flags are server-opaque flags whose semantics are entirely + // up to the app. + Flags uint32 + + // Expiration is the cache expiration time, in seconds: either a relative + // time from now (up to 1 month), or an absolute Unix epoch time. + // Zero means the Item has no expiration time. + Expiration int32 + + // Compare and swap ID. + casid uint64 +} + +// conn is a connection to a server. +type conn struct { + nc net.Conn + rw *bufio.ReadWriter + addr net.Addr + c *Client +} + +// release returns this connection back to the client's free pool +func (cn *conn) release() { + cn.c.putFreeConn(cn.addr, cn) +} + +func (cn *conn) extendDeadline() { + cn.nc.SetDeadline(time.Now().Add(cn.c.netTimeout())) +} + +// condRelease releases this connection if the error pointed to by err +// is nil (not an error) or is only a protocol level error (e.g. a +// cache miss). The purpose is to not recycle TCP connections that +// are bad. +func (cn *conn) condRelease(err *error) { + if *err == nil || resumableError(*err) { + cn.release() + } else { + cn.nc.Close() + } +} + +func (c *Client) putFreeConn(addr net.Addr, cn *conn) { + c.lk.Lock() + defer c.lk.Unlock() + if c.freeconn == nil { + c.freeconn = make(map[string][]*conn) + } + freelist := c.freeconn[addr.String()] + if len(freelist) >= maxIdleConnsPerAddr { + cn.nc.Close() + return + } + c.freeconn[addr.String()] = append(freelist, cn) +} + +func (c *Client) getFreeConn(addr net.Addr) (cn *conn, ok bool) { + c.lk.Lock() + defer c.lk.Unlock() + if c.freeconn == nil { + return nil, false + } + freelist, ok := c.freeconn[addr.String()] + if !ok || len(freelist) == 0 { + return nil, false + } + cn = freelist[len(freelist)-1] + c.freeconn[addr.String()] = freelist[:len(freelist)-1] + return cn, true +} + +func (c *Client) netTimeout() time.Duration { + if c.Timeout != 0 { + return c.Timeout + } + return DefaultTimeout +} + +// ConnectTimeoutError is the error type used when it takes +// too long to connect to the desired host. This level of +// detail can generally be ignored. +type ConnectTimeoutError struct { + Addr net.Addr +} + +func (cte *ConnectTimeoutError) Error() string { + return "memcache: connect timeout to " + cte.Addr.String() +} + +func (c *Client) dial(addr net.Addr) (net.Conn, error) { + type connError struct { + cn net.Conn + err error + } + + nc, err := net.DialTimeout(addr.Network(), addr.String(), c.netTimeout()) + if err == nil { + return nc, nil + } + + if ne, ok := err.(net.Error); ok && ne.Timeout() { + return nil, &ConnectTimeoutError{addr} + } + + return nil, err +} + +func (c *Client) getConn(addr net.Addr) (*conn, error) { + cn, ok := c.getFreeConn(addr) + if ok { + cn.extendDeadline() + return cn, nil + } + nc, err := c.dial(addr) + if err != nil { + return nil, err + } + cn = &conn{ + nc: nc, + addr: addr, + rw: bufio.NewReadWriter(bufio.NewReader(nc), bufio.NewWriter(nc)), + c: c, + } + cn.extendDeadline() + return cn, nil +} + +func (c *Client) onItem(item *Item, fn func(*Client, *bufio.ReadWriter, *Item) error) error { + addr, err := c.selector.PickServer(item.Key) + if err != nil { + return err + } + cn, err := c.getConn(addr) + if err != nil { + return err + } + defer cn.condRelease(&err) + if err = fn(c, cn.rw, item); err != nil { + return err + } + return nil +} + +func (c *Client) FlushAll() error { + return c.selector.Each(c.flushAllFromAddr) +} + +// Get gets the item for the given key. ErrCacheMiss is returned for a +// memcache cache miss. The key must be at most 250 bytes in length. +func (c *Client) Get(key string) (item *Item, err error) { + err = c.withKeyAddr(key, func(addr net.Addr) error { + return c.getFromAddr(addr, []string{key}, func(it *Item) { item = it }) + }) + if err == nil && item == nil { + err = ErrCacheMiss + } + return +} + +// Touch updates the expiry for the given key. The seconds parameter is either +// a Unix timestamp or, if seconds is less than 1 month, the number of seconds +// into the future at which time the item will expire. ErrCacheMiss is returned if the +// key is not in the cache. The key must be at most 250 bytes in length. +func (c *Client) Touch(key string, seconds int32) (err error) { + return c.withKeyAddr(key, func(addr net.Addr) error { + return c.touchFromAddr(addr, []string{key}, seconds) + }) +} + +func (c *Client) withKeyAddr(key string, fn func(net.Addr) error) (err error) { + if !legalKey(key) { + return ErrMalformedKey + } + addr, err := c.selector.PickServer(key) + if err != nil { + return err + } + return fn(addr) +} + +func (c *Client) withAddrRw(addr net.Addr, fn func(*bufio.ReadWriter) error) (err error) { + cn, err := c.getConn(addr) + if err != nil { + return err + } + defer cn.condRelease(&err) + return fn(cn.rw) +} + +func (c *Client) withKeyRw(key string, fn func(*bufio.ReadWriter) error) error { + return c.withKeyAddr(key, func(addr net.Addr) error { + return c.withAddrRw(addr, fn) + }) +} + +func (c *Client) getFromAddr(addr net.Addr, keys []string, cb func(*Item)) error { + return c.withAddrRw(addr, func(rw *bufio.ReadWriter) error { + if _, err := fmt.Fprintf(rw, "gets %s\r\n", strings.Join(keys, " ")); err != nil { + return err + } + if err := rw.Flush(); err != nil { + return err + } + if err := parseGetResponse(rw.Reader, cb); err != nil { + return err + } + return nil + }) +} + +// flushAllFromAddr send the flush_all command to the given addr +func (c *Client) flushAllFromAddr(addr net.Addr) error { + return c.withAddrRw(addr, func(rw *bufio.ReadWriter) error { + if _, err := fmt.Fprintf(rw, "flush_all\r\n"); err != nil { + return err + } + if err := rw.Flush(); err != nil { + return err + } + line, err := rw.ReadSlice('\n') + if err != nil { + return err + } + switch { + case bytes.Equal(line, resultOk): + break + default: + return fmt.Errorf("memcache: unexpected response line from flush_all: %q", string(line)) + } + return nil + }) +} + +func (c *Client) touchFromAddr(addr net.Addr, keys []string, expiration int32) error { + return c.withAddrRw(addr, func(rw *bufio.ReadWriter) error { + for _, key := range keys { + if _, err := fmt.Fprintf(rw, "touch %s %d\r\n", key, expiration); err != nil { + return err + } + if err := rw.Flush(); err != nil { + return err + } + line, err := rw.ReadSlice('\n') + if err != nil { + return err + } + switch { + case bytes.Equal(line, resultTouched): + break + case bytes.Equal(line, resultNotFound): + return ErrCacheMiss + default: + return fmt.Errorf("memcache: unexpected response line from touch: %q", string(line)) + } + } + return nil + }) +} + +// GetMulti is a batch version of Get. The returned map from keys to +// items may have fewer elements than the input slice, due to memcache +// cache misses. Each key must be at most 250 bytes in length. +// If no error is returned, the returned map will also be non-nil. +func (c *Client) GetMulti(keys []string) (map[string]*Item, error) { + var lk sync.Mutex + m := make(map[string]*Item) + addItemToMap := func(it *Item) { + lk.Lock() + defer lk.Unlock() + m[it.Key] = it + } + + keyMap := make(map[net.Addr][]string) + for _, key := range keys { + if !legalKey(key) { + return nil, ErrMalformedKey + } + addr, err := c.selector.PickServer(key) + if err != nil { + return nil, err + } + keyMap[addr] = append(keyMap[addr], key) + } + + ch := make(chan error, buffered) + for addr, keys := range keyMap { + go func(addr net.Addr, keys []string) { + ch <- c.getFromAddr(addr, keys, addItemToMap) + }(addr, keys) + } + + var err error + for _ = range keyMap { + if ge := <-ch; ge != nil { + err = ge + } + } + return m, err +} + +// parseGetResponse reads a GET response from r and calls cb for each +// read and allocated Item +func parseGetResponse(r *bufio.Reader, cb func(*Item)) error { + for { + line, err := r.ReadSlice('\n') + if err != nil { + return err + } + if bytes.Equal(line, resultEnd) { + return nil + } + it := new(Item) + size, err := scanGetResponseLine(line, it) + if err != nil { + return err + } + it.Value, err = ioutil.ReadAll(io.LimitReader(r, int64(size)+2)) + if err != nil { + return err + } + if !bytes.HasSuffix(it.Value, crlf) { + return fmt.Errorf("memcache: corrupt get result read") + } + it.Value = it.Value[:size] + cb(it) + } +} + +// scanGetResponseLine populates it and returns the declared size of the item. +// It does not read the bytes of the item. +func scanGetResponseLine(line []byte, it *Item) (size int, err error) { + pattern := "VALUE %s %d %d %d\r\n" + dest := []interface{}{&it.Key, &it.Flags, &size, &it.casid} + if bytes.Count(line, space) == 3 { + pattern = "VALUE %s %d %d\r\n" + dest = dest[:3] + } + n, err := fmt.Sscanf(string(line), pattern, dest...) + if err != nil || n != len(dest) { + return -1, fmt.Errorf("memcache: unexpected line in get response: %q", line) + } + return size, nil +} + +// Set writes the given item, unconditionally. +func (c *Client) Set(item *Item) error { + return c.onItem(item, (*Client).set) +} + +func (c *Client) set(rw *bufio.ReadWriter, item *Item) error { + return c.populateOne(rw, "set", item) +} + +// Add writes the given item, if no value already exists for its +// key. ErrNotStored is returned if that condition is not met. +func (c *Client) Add(item *Item) error { + return c.onItem(item, (*Client).add) +} + +func (c *Client) add(rw *bufio.ReadWriter, item *Item) error { + return c.populateOne(rw, "add", item) +} + +// Replace writes the given item, but only if the server *does* +// already hold data for this key +func (c *Client) Replace(item *Item) error { + return c.onItem(item, (*Client).replace) +} + +func (c *Client) replace(rw *bufio.ReadWriter, item *Item) error { + return c.populateOne(rw, "replace", item) +} + +// CompareAndSwap writes the given item that was previously returned +// by Get, if the value was neither modified or evicted between the +// Get and the CompareAndSwap calls. The item's Key should not change +// between calls but all other item fields may differ. ErrCASConflict +// is returned if the value was modified in between the +// calls. ErrNotStored is returned if the value was evicted in between +// the calls. +func (c *Client) CompareAndSwap(item *Item) error { + return c.onItem(item, (*Client).cas) +} + +func (c *Client) cas(rw *bufio.ReadWriter, item *Item) error { + return c.populateOne(rw, "cas", item) +} + +func (c *Client) populateOne(rw *bufio.ReadWriter, verb string, item *Item) error { + if !legalKey(item.Key) { + return ErrMalformedKey + } + var err error + if verb == "cas" { + _, err = fmt.Fprintf(rw, "%s %s %d %d %d %d\r\n", + verb, item.Key, item.Flags, item.Expiration, len(item.Value), item.casid) + } else { + _, err = fmt.Fprintf(rw, "%s %s %d %d %d\r\n", + verb, item.Key, item.Flags, item.Expiration, len(item.Value)) + } + if err != nil { + return err + } + if _, err = rw.Write(item.Value); err != nil { + return err + } + if _, err := rw.Write(crlf); err != nil { + return err + } + if err := rw.Flush(); err != nil { + return err + } + line, err := rw.ReadSlice('\n') + if err != nil { + return err + } + switch { + case bytes.Equal(line, resultStored): + return nil + case bytes.Equal(line, resultNotStored): + return ErrNotStored + case bytes.Equal(line, resultExists): + return ErrCASConflict + case bytes.Equal(line, resultNotFound): + return ErrCacheMiss + } + return fmt.Errorf("memcache: unexpected response line from %q: %q", verb, string(line)) +} + +func writeReadLine(rw *bufio.ReadWriter, format string, args ...interface{}) ([]byte, error) { + _, err := fmt.Fprintf(rw, format, args...) + if err != nil { + return nil, err + } + if err := rw.Flush(); err != nil { + return nil, err + } + line, err := rw.ReadSlice('\n') + return line, err +} + +func writeExpectf(rw *bufio.ReadWriter, expect []byte, format string, args ...interface{}) error { + line, err := writeReadLine(rw, format, args...) + if err != nil { + return err + } + switch { + case bytes.Equal(line, resultOK): + return nil + case bytes.Equal(line, expect): + return nil + case bytes.Equal(line, resultNotStored): + return ErrNotStored + case bytes.Equal(line, resultExists): + return ErrCASConflict + case bytes.Equal(line, resultNotFound): + return ErrCacheMiss + } + return fmt.Errorf("memcache: unexpected response line: %q", string(line)) +} + +// Delete deletes the item with the provided key. The error ErrCacheMiss is +// returned if the item didn't already exist in the cache. +func (c *Client) Delete(key string) error { + return c.withKeyRw(key, func(rw *bufio.ReadWriter) error { + return writeExpectf(rw, resultDeleted, "delete %s\r\n", key) + }) +} + +// DeleteAll deletes all items in the cache. +func (c *Client) DeleteAll() error { + return c.withKeyRw("", func(rw *bufio.ReadWriter) error { + return writeExpectf(rw, resultDeleted, "flush_all\r\n") + }) +} + +// Increment atomically increments key by delta. The return value is +// the new value after being incremented or an error. If the value +// didn't exist in memcached the error is ErrCacheMiss. The value in +// memcached must be an decimal number, or an error will be returned. +// On 64-bit overflow, the new value wraps around. +func (c *Client) Increment(key string, delta uint64) (newValue uint64, err error) { + return c.incrDecr("incr", key, delta) +} + +// Decrement atomically decrements key by delta. The return value is +// the new value after being decremented or an error. If the value +// didn't exist in memcached the error is ErrCacheMiss. The value in +// memcached must be an decimal number, or an error will be returned. +// On underflow, the new value is capped at zero and does not wrap +// around. +func (c *Client) Decrement(key string, delta uint64) (newValue uint64, err error) { + return c.incrDecr("decr", key, delta) +} + +func (c *Client) incrDecr(verb, key string, delta uint64) (uint64, error) { + var val uint64 + err := c.withKeyRw(key, func(rw *bufio.ReadWriter) error { + line, err := writeReadLine(rw, "%s %s %d\r\n", verb, key, delta) + if err != nil { + return err + } + switch { + case bytes.Equal(line, resultNotFound): + return ErrCacheMiss + case bytes.HasPrefix(line, resultClientErrorPrefix): + errMsg := line[len(resultClientErrorPrefix) : len(line)-2] + return errors.New("memcache: client error: " + string(errMsg)) + } + val, err = strconv.ParseUint(string(line[:len(line)-2]), 10, 64) + if err != nil { + return err + } + return nil + }) + return val, err +} diff --git a/Godeps/_workspace/src/github.com/bradfitz/gomemcache/memcache/selector.go b/Godeps/_workspace/src/github.com/bradfitz/gomemcache/memcache/selector.go new file mode 100644 index 00000000000..10b04d349fe --- /dev/null +++ b/Godeps/_workspace/src/github.com/bradfitz/gomemcache/memcache/selector.go @@ -0,0 +1,114 @@ +/* +Copyright 2011 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package memcache + +import ( + "hash/crc32" + "net" + "strings" + "sync" +) + +// ServerSelector is the interface that selects a memcache server +// as a function of the item's key. +// +// All ServerSelector implementations must be safe for concurrent use +// by multiple goroutines. +type ServerSelector interface { + // PickServer returns the server address that a given item + // should be shared onto. + PickServer(key string) (net.Addr, error) + Each(func(net.Addr) error) error +} + +// ServerList is a simple ServerSelector. Its zero value is usable. +type ServerList struct { + mu sync.RWMutex + addrs []net.Addr +} + +// SetServers changes a ServerList's set of servers at runtime and is +// safe for concurrent use by multiple goroutines. +// +// Each server is given equal weight. A server is given more weight +// if it's listed multiple times. +// +// SetServers returns an error if any of the server names fail to +// resolve. No attempt is made to connect to the server. If any error +// is returned, no changes are made to the ServerList. +func (ss *ServerList) SetServers(servers ...string) error { + naddr := make([]net.Addr, len(servers)) + for i, server := range servers { + if strings.Contains(server, "/") { + addr, err := net.ResolveUnixAddr("unix", server) + if err != nil { + return err + } + naddr[i] = addr + } else { + tcpaddr, err := net.ResolveTCPAddr("tcp", server) + if err != nil { + return err + } + naddr[i] = tcpaddr + } + } + + ss.mu.Lock() + defer ss.mu.Unlock() + ss.addrs = naddr + return nil +} + +// Each iterates over each server calling the given function +func (ss *ServerList) Each(f func(net.Addr) error) error { + ss.mu.RLock() + defer ss.mu.RUnlock() + for _, a := range ss.addrs { + if err := f(a); nil != err { + return err + } + } + return nil +} + +// keyBufPool returns []byte buffers for use by PickServer's call to +// crc32.ChecksumIEEE to avoid allocations. (but doesn't avoid the +// copies, which at least are bounded in size and small) +var keyBufPool = sync.Pool{ + New: func() interface{} { + b := make([]byte, 256) + return &b + }, +} + +func (ss *ServerList) PickServer(key string) (net.Addr, error) { + ss.mu.RLock() + defer ss.mu.RUnlock() + if len(ss.addrs) == 0 { + return nil, ErrNoServers + } + if len(ss.addrs) == 1 { + return ss.addrs[0], nil + } + bufp := keyBufPool.Get().(*[]byte) + n := copy(*bufp, key) + cs := crc32.ChecksumIEEE((*bufp)[:n]) + keyBufPool.Put(bufp) + + return ss.addrs[cs%uint32(len(ss.addrs))], nil +} From bf41eb824d24d30e7ae904ee19ce46d84be116ea Mon Sep 17 00:00:00 2001 From: Qtax Date: Sat, 5 Dec 2015 23:56:55 +0100 Subject: [PATCH 25/56] Added ES histogram setting to drop/ignore the first and last datapoints --- .../datasource/elasticsearch/bucket_agg.js | 3 +++ .../elasticsearch/elastic_response.js | 17 ++++++------- .../elasticsearch/partials/bucket_agg.html | 24 +++++++++++++++---- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/bucket_agg.js b/public/app/plugins/datasource/elasticsearch/bucket_agg.js index 2a21bc17960..62cdcb3f59e 100644 --- a/public/app/plugins/datasource/elasticsearch/bucket_agg.js +++ b/public/app/plugins/datasource/elasticsearch/bucket_agg.js @@ -96,6 +96,9 @@ function (angular, _, queryDef) { $scope.agg.field = $scope.target.timeField; settingsLinkText = 'Interval: ' + settings.interval; settingsLinkText += ', Min Doc Count: ' + settings.min_doc_count; + if (settings.dropFirstLast) { + settingsLinkText += ', Drop first & last value'; + } } } diff --git a/public/app/plugins/datasource/elasticsearch/elastic_response.js b/public/app/plugins/datasource/elasticsearch/elastic_response.js index b8405797408..5915578530f 100644 --- a/public/app/plugins/datasource/elasticsearch/elastic_response.js +++ b/public/app/plugins/datasource/elasticsearch/elastic_response.js @@ -10,8 +10,9 @@ function (_, queryDef) { this.response = response; } - ElasticResponse.prototype.processMetrics = function(esAgg, target, seriesList, props) { + ElasticResponse.prototype.processMetrics = function(esAgg, target, seriesList, props, dropFirstLast) { var metric, y, i, newSeries, bucket, value; + dropFirstLast = dropFirstLast ? 1 : 0; for (y = 0; y < target.metrics.length; y++) { metric = target.metrics[y]; @@ -22,7 +23,7 @@ function (_, queryDef) { switch(metric.type) { case 'count': { newSeries = { datapoints: [], metric: 'count', props: props}; - for (i = 0; i < esAgg.buckets.length; i++) { + for (i = dropFirstLast; i < esAgg.buckets.length - dropFirstLast; i++) { bucket = esAgg.buckets[i]; value = bucket.doc_count; newSeries.datapoints.push([value, bucket.key]); @@ -31,17 +32,17 @@ function (_, queryDef) { break; } case 'percentiles': { - if (esAgg.buckets.length === 0) { + if (esAgg.buckets.length - dropFirstLast * 2 <= 0) { break; } - var firstBucket = esAgg.buckets[0]; + var firstBucket = esAgg.buckets[dropFirstLast]; var percentiles = firstBucket[metric.id].values; for (var percentileName in percentiles) { newSeries = {datapoints: [], metric: 'p' + percentileName, props: props, field: metric.field}; - for (i = 0; i < esAgg.buckets.length; i++) { + for (i = dropFirstLast; i < esAgg.buckets.length - dropFirstLast; i++) { bucket = esAgg.buckets[i]; var values = bucket[metric.id].values; newSeries.datapoints.push([values[percentileName], bucket.key]); @@ -59,7 +60,7 @@ function (_, queryDef) { newSeries = {datapoints: [], metric: statName, props: props, field: metric.field}; - for (i = 0; i < esAgg.buckets.length; i++) { + for (i = dropFirstLast; i < esAgg.buckets.length - dropFirstLast; i++) { bucket = esAgg.buckets[i]; var stats = bucket[metric.id]; @@ -77,7 +78,7 @@ function (_, queryDef) { } default: { newSeries = { datapoints: [], metric: metric.type, field: metric.field, props: props}; - for (i = 0; i < esAgg.buckets.length; i++) { + for (i = dropFirstLast; i < esAgg.buckets.length - dropFirstLast; i++) { bucket = esAgg.buckets[i]; value = bucket[metric.id]; @@ -158,7 +159,7 @@ function (_, queryDef) { if (depth === maxDepth) { if (aggDef.type === 'date_histogram') { - this.processMetrics(esAgg, target, seriesList, props); + this.processMetrics(esAgg, target, seriesList, props, aggDef.settings && aggDef.settings.dropFirstLast); } else { this.processAggregationDocs(esAgg, aggDef, target, docs, props); } diff --git a/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html index 5a84ec8f6cd..b4092a0317a 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html @@ -37,7 +37,7 @@
      -
    • +
    • Interval
    • @@ -46,13 +46,29 @@
    -
    +
      -
    • +
    • Min Doc Count
    • - + +
    • +
    +
    +
    +
    +
      +
    • + Drop first & last value +
    • +
    • + + +
    • +
    • +
    From cba471b09ba76a16a70cb823db56c3603c9d3dab Mon Sep 17 00:00:00 2001 From: Pavel Strashkin Date: Thu, 3 Sep 2015 00:55:50 -0700 Subject: [PATCH 26/56] ui(dashboard): delete empty rows without confirm --- public/app/features/dashboard/rowCtrl.js | 12 +++++++++++- public/test/specs/row-ctrl-specs.js | 21 +++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/public/app/features/dashboard/rowCtrl.js b/public/app/features/dashboard/rowCtrl.js index 723481d2d65..7fbf54b5f83 100644 --- a/public/app/features/dashboard/rowCtrl.js +++ b/public/app/features/dashboard/rowCtrl.js @@ -41,13 +41,23 @@ function (angular, _, config) { $scope.dashboard.addPanel(panel, $scope.row); }; + $scope.deleteRow = function() { + function delete_row() { + $scope.dashboard.rows = _.without($scope.dashboard.rows, $scope.row); + } + + if (!$scope.row.panels.length) { + delete_row(); + return; + } + $scope.appEvent('confirm-modal', { title: 'Are you sure you want to delete this row?', icon: 'fa-trash', yesText: 'Delete', onConfirm: function() { - $scope.dashboard.rows = _.without($scope.dashboard.rows, $scope.row); + delete_row(); } }); }; diff --git a/public/test/specs/row-ctrl-specs.js b/public/test/specs/row-ctrl-specs.js index 45a9d23ccfb..33130b93eac 100644 --- a/public/test/specs/row-ctrl-specs.js +++ b/public/test/specs/row-ctrl-specs.js @@ -12,7 +12,24 @@ define([ beforeEach(ctx.providePhase()); beforeEach(ctx.createControllerPhase('RowCtrl')); + describe('delete_row', function () { + describe('when row is empty (has no panels)', function () { + beforeEach(function () { + ctx.scope.dashboard.rows = [{id: 1, panels: []}]; + ctx.scope.row = ctx.scope.dashboard.rows[0]; + ctx.scope.appEvent = sinon.spy(); + + ctx.scope.delete_row(); + }); + + it('should NOT ask for confirmation', function () { + expect(ctx.scope.appEvent.called).to.be(false); + }); + + it('should delete row', function () { + expect(ctx.scope.dashboard.rows).to.not.contain(ctx.scope.row); + }); + }); + }); }); - }); - From c48da9b5cf57f1d9e84a4cad7f392a81bf9ab2f8 Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Tue, 15 Dec 2015 14:03:15 +0100 Subject: [PATCH 27/56] fix(tests): fix broken unittest due to merge conflict --- public/app/features/dashboard/rowCtrl.js | 1 - public/test/specs/row-ctrl-specs.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/public/app/features/dashboard/rowCtrl.js b/public/app/features/dashboard/rowCtrl.js index 7fbf54b5f83..3b178c4de26 100644 --- a/public/app/features/dashboard/rowCtrl.js +++ b/public/app/features/dashboard/rowCtrl.js @@ -41,7 +41,6 @@ function (angular, _, config) { $scope.dashboard.addPanel(panel, $scope.row); }; - $scope.deleteRow = function() { function delete_row() { $scope.dashboard.rows = _.without($scope.dashboard.rows, $scope.row); diff --git a/public/test/specs/row-ctrl-specs.js b/public/test/specs/row-ctrl-specs.js index 33130b93eac..06aa92e783a 100644 --- a/public/test/specs/row-ctrl-specs.js +++ b/public/test/specs/row-ctrl-specs.js @@ -19,7 +19,7 @@ define([ ctx.scope.row = ctx.scope.dashboard.rows[0]; ctx.scope.appEvent = sinon.spy(); - ctx.scope.delete_row(); + ctx.scope.deleteRow(); }); it('should NOT ask for confirmation', function () { From f355f36d09543d9035ef777e0be2168d05f9142c Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Tue, 15 Dec 2015 14:23:37 +0100 Subject: [PATCH 28/56] rename(phantomjs): improve variable naming --- vendor/phantomjs/render.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/phantomjs/render.js b/vendor/phantomjs/render.js index 5cd442eb338..057d464a74c 100644 --- a/vendor/phantomjs/render.js +++ b/vendor/phantomjs/render.js @@ -36,8 +36,8 @@ page.open(params.url, function (status) { var canvas = page.evaluate(function() { var body = angular.element(document.body); // 1 var rootScope = body.scope().$root; - var panels = angular.element('div.panel').length; - return rootScope.performance.panelsRendered >= panels; + var panelsToLoad = angular.element('div.panel').length; + return rootScope.performance.panelsRendered >= panelsToLoad; }); if (canvas || tries === 1000) { From ce2ae31950989fd6bcfeec25d00cc59cac8ec2a3 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Fri, 17 Jul 2015 12:23:30 +0200 Subject: [PATCH 29/56] Use percent-formatter for stack+percentage graph --- public/app/plugins/panels/graph/graph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/panels/graph/graph.js b/public/app/plugins/panels/graph/graph.js index 31c4e541f40..39c1c6707c1 100755 --- a/public/app/plugins/panels/graph/graph.js +++ b/public/app/plugins/panels/graph/graph.js @@ -380,11 +380,11 @@ function (angular, $, moment, _, kbn, GraphTooltip) { options.yaxes.push(secondY); applyLogScale(options.yaxes[1], data); - configureAxisMode(options.yaxes[1], scope.panel.y_formats[1]); + configureAxisMode(options.yaxes[1], scope.panel.percentage && scope.panel.stack ? "percent" : scope.panel.y_formats[1]); } applyLogScale(options.yaxes[0], data); - configureAxisMode(options.yaxes[0], scope.panel.y_formats[0]); + configureAxisMode(options.yaxes[0], scope.panel.percentage && scope.panel.stack ? "percent" : scope.panel.y_formats[0]); } function applyLogScale(axis, data) { From b99ea80b581a582908eae4612a837b6449838069 Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Tue, 15 Dec 2015 17:28:49 +0100 Subject: [PATCH 30/56] test(graph): validates that percentage is shown when using stack and percentage fixes #2379 --- public/test/specs/graph-specs.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/public/test/specs/graph-specs.js b/public/test/specs/graph-specs.js index 60637296564..29fdeeb825e 100644 --- a/public/test/specs/graph-specs.js +++ b/public/test/specs/graph-specs.js @@ -215,6 +215,17 @@ define([ }); }); + graphScenario('when stack and percent', function(ctx) { + ctx.setup(function(scope) { + scope.panel.percentage = true; + scope.panel.stack = true; + }); + + it('should show percentage', function() { + var axis = ctx.plotOptions.yaxes[0]; + expect(axis.tickFormatter(100, axis)).to.be("100%"); + }); + }); }); }); From e44ef7f8230949a3bb0172729bfec52e947cc868 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Wed, 16 Dec 2015 17:01:58 +0900 Subject: [PATCH 31/56] fix cloudwatch query editor --- .../datasource/cloudwatch/partials/query.parameter.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/partials/query.parameter.html b/public/app/plugins/datasource/cloudwatch/partials/query.parameter.html index a182369a1dd..7b0785e808d 100644 --- a/public/app/plugins/datasource/cloudwatch/partials/query.parameter.html +++ b/public/app/plugins/datasource/cloudwatch/partials/query.parameter.html @@ -43,14 +43,14 @@ Interval between points in seconds
  • - +
  • Alias {{metric}} {{stat}} {{namespace}} {{region}} {{DIMENSION_NAME}}
  • - +
  • From c7ba60162b052fc43042814a30f79173215cc280 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Wed, 16 Dec 2015 13:48:33 +0900 Subject: [PATCH 32/56] (cloudwatch) add Divide By Sum option --- public/app/plugins/datasource/cloudwatch/datasource.js | 3 +++ .../datasource/cloudwatch/partials/query.parameter.html | 3 +++ public/app/plugins/datasource/cloudwatch/query_ctrl.js | 1 + 3 files changed, 7 insertions(+) diff --git a/public/app/plugins/datasource/cloudwatch/datasource.js b/public/app/plugins/datasource/cloudwatch/datasource.js index f606b6e3dc8..3d335c90d81 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.js +++ b/public/app/plugins/datasource/cloudwatch/datasource.js @@ -330,6 +330,9 @@ function (angular, _, moment, dateMath) { dps.push([null, lastTimestamp + periodMs]); } lastTimestamp = timestamp; + if (options.divideSumByPeriod && stat === 'Sum') { + dp[stat] = dp[stat] / options.period; + } dps.push([dp[stat], timestamp]); }); diff --git a/public/app/plugins/datasource/cloudwatch/partials/query.parameter.html b/public/app/plugins/datasource/cloudwatch/partials/query.parameter.html index 7b0785e808d..bd5dc9fb6ae 100644 --- a/public/app/plugins/datasource/cloudwatch/partials/query.parameter.html +++ b/public/app/plugins/datasource/cloudwatch/partials/query.parameter.html @@ -52,6 +52,9 @@
  • +
  • + Sum / Period +
  • diff --git a/public/app/plugins/datasource/cloudwatch/query_ctrl.js b/public/app/plugins/datasource/cloudwatch/query_ctrl.js index e24b73cd068..deac54a9b24 100644 --- a/public/app/plugins/datasource/cloudwatch/query_ctrl.js +++ b/public/app/plugins/datasource/cloudwatch/query_ctrl.js @@ -10,6 +10,7 @@ function (angular, _) { module.controller('CloudWatchQueryCtrl', function($scope) { $scope.init = function() { + $scope.target.divideSumByPeriod = $scope.target.divideSumByPeriod || false; $scope.aliasSyntax = '{{metric}} {{stat}} {{namespace}} {{region}} {{}}'; }; From 48539c851edb1fae82e87f2498c1546787c7a3d4 Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Wed, 16 Dec 2015 09:45:28 +0100 Subject: [PATCH 33/56] feat(graphite): adds support for grep function closes #1163 --- public/app/plugins/datasource/graphite/gfunc.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/public/app/plugins/datasource/graphite/gfunc.js b/public/app/plugins/datasource/graphite/gfunc.js index 7cbb456f932..c8fb6ab9918 100644 --- a/public/app/plugins/datasource/graphite/gfunc.js +++ b/public/app/plugins/datasource/graphite/gfunc.js @@ -516,6 +516,13 @@ function (_, $) { defaultParams: ['exclude'] }); + addFuncDef({ + name: "grep", + category: categories.Filter, + params: [{ name: "grep", type: 'string' }], + defaultParams: ['grep'] + }); + addFuncDef({ name: 'highestCurrent', category: categories.Filter, From 3a6e8a535cb636fbc8e92e1b4afec07c0c828044 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Wed, 16 Dec 2015 02:30:53 -0800 Subject: [PATCH 34/56] Fixed typos --- docs/sources/reference/table_panel.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sources/reference/table_panel.md b/docs/sources/reference/table_panel.md index 381d16186a9..65437f85bd7 100644 --- a/docs/sources/reference/table_panel.md +++ b/docs/sources/reference/table_panel.md @@ -9,7 +9,7 @@ page_keywords: grafana, table, panel, documentation The new table panel is very flexible, supporting both multiple modes for time series as well as for -table, annotation and raw JSON data. It also provides date formating and value formating and coloring options. +table, annotation and raw JSON data. It also provides date formatting and value formatting and coloring options. To view table panels in action and test different configurations with sample data, check out the [Table Panel Showcase in the Grafana Playground](http://play.grafana.org/dashboard/db/table-panel-showcase). @@ -21,7 +21,7 @@ The table panel has many ways to manipulate your data for optimal presentation. 1. `Data`: Control how your query is transformed into a table. 2. `Table Display`: Table display options. -3. `Column Styles`: Column value formating and display options. +3. `Column Styles`: Column value formatting and display options. ## Data to Table From 78fe58833065c457440df16860feb2adaba0416e Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Wed, 16 Dec 2015 02:46:20 -0800 Subject: [PATCH 35/56] Removed NewAddColumnMigration via 3473 --- pkg/services/sqlstore/migrator/migrations.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/services/sqlstore/migrator/migrations.go b/pkg/services/sqlstore/migrator/migrations.go index 7d97abb6bb9..a65c7ec7e81 100644 --- a/pkg/services/sqlstore/migrator/migrations.go +++ b/pkg/services/sqlstore/migrator/migrations.go @@ -64,10 +64,6 @@ type AddColumnMigration struct { column *Column } -func NewAddColumnMigration(table Table, col *Column) *AddColumnMigration { - return &AddColumnMigration{tableName: table.Name, column: col} -} - func (m *AddColumnMigration) Table(tableName string) *AddColumnMigration { m.tableName = tableName return m From 26abce647d09a1e9aa88daa745beecaca4a72a99 Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Wed, 16 Dec 2015 13:27:35 +0100 Subject: [PATCH 36/56] feat(elastic): isolate drop first and last logic --- .../elasticsearch/elastic_response.js | 32 +++++++++---- .../specs/elastic_response_specs.ts | 48 +++++++++++++++++++ 2 files changed, 71 insertions(+), 9 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/elastic_response.js b/public/app/plugins/datasource/elasticsearch/elastic_response.js index 5915578530f..f2403c96046 100644 --- a/public/app/plugins/datasource/elasticsearch/elastic_response.js +++ b/public/app/plugins/datasource/elasticsearch/elastic_response.js @@ -10,9 +10,8 @@ function (_, queryDef) { this.response = response; } - ElasticResponse.prototype.processMetrics = function(esAgg, target, seriesList, props, dropFirstLast) { + ElasticResponse.prototype.processMetrics = function(esAgg, target, seriesList, props) { var metric, y, i, newSeries, bucket, value; - dropFirstLast = dropFirstLast ? 1 : 0; for (y = 0; y < target.metrics.length; y++) { metric = target.metrics[y]; @@ -23,7 +22,7 @@ function (_, queryDef) { switch(metric.type) { case 'count': { newSeries = { datapoints: [], metric: 'count', props: props}; - for (i = dropFirstLast; i < esAgg.buckets.length - dropFirstLast; i++) { + for (i = 0; i < esAgg.buckets.length; i++) { bucket = esAgg.buckets[i]; value = bucket.doc_count; newSeries.datapoints.push([value, bucket.key]); @@ -32,17 +31,17 @@ function (_, queryDef) { break; } case 'percentiles': { - if (esAgg.buckets.length - dropFirstLast * 2 <= 0) { + if (esAgg.buckets.length === 0) { break; } - var firstBucket = esAgg.buckets[dropFirstLast]; + var firstBucket = esAgg.buckets[0]; var percentiles = firstBucket[metric.id].values; for (var percentileName in percentiles) { newSeries = {datapoints: [], metric: 'p' + percentileName, props: props, field: metric.field}; - for (i = dropFirstLast; i < esAgg.buckets.length - dropFirstLast; i++) { + for (i = 0; i < esAgg.buckets.length; i++) { bucket = esAgg.buckets[i]; var values = bucket[metric.id].values; newSeries.datapoints.push([values[percentileName], bucket.key]); @@ -60,7 +59,7 @@ function (_, queryDef) { newSeries = {datapoints: [], metric: statName, props: props, field: metric.field}; - for (i = dropFirstLast; i < esAgg.buckets.length - dropFirstLast; i++) { + for (i = 0; i < esAgg.buckets.length; i++) { bucket = esAgg.buckets[i]; var stats = bucket[metric.id]; @@ -78,7 +77,7 @@ function (_, queryDef) { } default: { newSeries = { datapoints: [], metric: metric.type, field: metric.field, props: props}; - for (i = dropFirstLast; i < esAgg.buckets.length - dropFirstLast; i++) { + for (i = 0; i < esAgg.buckets.length; i++) { bucket = esAgg.buckets[i]; value = bucket[metric.id]; @@ -159,7 +158,7 @@ function (_, queryDef) { if (depth === maxDepth) { if (aggDef.type === 'date_histogram') { - this.processMetrics(esAgg, target, seriesList, props, aggDef.settings && aggDef.settings.dropFirstLast); + this.processMetrics(esAgg, target, seriesList, props); } else { this.processAggregationDocs(esAgg, aggDef, target, docs, props); } @@ -270,6 +269,20 @@ function (_, queryDef) { seriesList.push(series); }; + ElasticResponse.prototype.dropFirstLast = function(aggregations, target) { + var histogram = _.findWhere(target.bucketAggs, { type: 'date_histogram'}); + + var shouldDropFirstAndLast = histogram && histogram.settings && histogram.settings.dropFirstLast; + if (shouldDropFirstAndLast) { + for(var prop in aggregations) { + var points = aggregations[prop]; + if (points.datapoints.length > 2) { + points.datapoints = points.datapoints.slice(1, points.datapoints.length-1); + } + } + } + }; + ElasticResponse.prototype.getTimeSeries = function() { var seriesList = []; @@ -290,6 +303,7 @@ function (_, queryDef) { var docs = []; this.processBuckets(aggregations, target, tmpSeriesList, docs, {}, 0); + this.dropFirstLast(tmpSeriesList, target); this.nameSeries(tmpSeriesList, target); for (var y = 0; y < tmpSeriesList.length; y++) { diff --git a/public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts index 5d4c84e01bd..7c266aa0e47 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts @@ -411,6 +411,49 @@ describe('ElasticResponse', function() { }); }); + describe('with dropfirst and last aggregation', function() { + beforeEach(function() { + targets = [{ + refId: 'A', + metrics: [{ type: 'avg', id: '1' }, { type: 'count' }], + bucketAggs: [{ id: '2', type: 'date_histogram', field: 'host', settings: { dropFirstLast: true} }], + }]; + + response = { + responses: [{ + aggregations: { + "2": { + buckets: [ + { + "1": { value: 1000 }, + key: 1, + doc_count: 369, + }, + { + "1": { value: 2000 }, + key: 2, + doc_count: 200, + }, + { + "1": { value: 2000 }, + key: 3, + doc_count: 200, + }, + ] + } + } + }] + }; + + result = new ElasticResponse(targets, response).getTimeSeries(); + }); + + it('should remove first and last value', function() { + expect(result.data.length).to.be(2); + expect(result.data[0].datapoints.length).to.be(1); + }); + }); + describe('No group by time', function() { beforeEach(function() { targets = [{ @@ -456,6 +499,11 @@ describe('ElasticResponse', function() { }); }); + describe('', function() { + + + }); + describe('Raw documents query', function() { beforeEach(function() { targets = [{ refId: 'A', metrics: [{type: 'raw_document', id: '1'}], bucketAggs: [] }]; From 37cfe2a3cbdd350103c4d9e286f27bbce64b54bc Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Wed, 16 Dec 2015 13:29:54 +0100 Subject: [PATCH 37/56] feat(elastic): shorten expression to target input --- .../plugins/datasource/elasticsearch/partials/bucket_agg.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html index 2b996b19e17..b338e5d227f 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html @@ -63,9 +63,9 @@ Drop first & last value
  • - - +
  • From dc30b9d37bfa5874e169fd3b1f310c98121587aa Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Wed, 16 Dec 2015 13:50:14 +0100 Subject: [PATCH 38/56] feat(elastic): change concept to trim edges instead. --- .../datasource/elasticsearch/bucket_agg.js | 9 +++++++-- .../datasource/elasticsearch/elastic_response.js | 11 ++++++----- .../elasticsearch/partials/bucket_agg.html | 16 +++++++--------- .../specs/elastic_response_specs.ts | 2 +- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/bucket_agg.js b/public/app/plugins/datasource/elasticsearch/bucket_agg.js index 62cdcb3f59e..6df01f911d1 100644 --- a/public/app/plugins/datasource/elasticsearch/bucket_agg.js +++ b/public/app/plugins/datasource/elasticsearch/bucket_agg.js @@ -96,8 +96,13 @@ function (angular, _, queryDef) { $scope.agg.field = $scope.target.timeField; settingsLinkText = 'Interval: ' + settings.interval; settingsLinkText += ', Min Doc Count: ' + settings.min_doc_count; - if (settings.dropFirstLast) { - settingsLinkText += ', Drop first & last value'; + + if (settings.trimEdges === undefined || settings.trimEdges < 0) { + settings.trimEdges = 0; + } + + if (settings.trimEdges && settings.trimEdges > 0) { + settingsLinkText += ', Trim edges: ' + settings.trimEdges; } } } diff --git a/public/app/plugins/datasource/elasticsearch/elastic_response.js b/public/app/plugins/datasource/elasticsearch/elastic_response.js index f2403c96046..7ae4c204207 100644 --- a/public/app/plugins/datasource/elasticsearch/elastic_response.js +++ b/public/app/plugins/datasource/elasticsearch/elastic_response.js @@ -269,15 +269,16 @@ function (_, queryDef) { seriesList.push(series); }; - ElasticResponse.prototype.dropFirstLast = function(aggregations, target) { + ElasticResponse.prototype.trimDatapoints = function(aggregations, target) { var histogram = _.findWhere(target.bucketAggs, { type: 'date_histogram'}); - var shouldDropFirstAndLast = histogram && histogram.settings && histogram.settings.dropFirstLast; + var shouldDropFirstAndLast = histogram && histogram.settings && histogram.settings.trimEdges; if (shouldDropFirstAndLast) { + var trim = histogram.settings.trimEdges; for(var prop in aggregations) { var points = aggregations[prop]; - if (points.datapoints.length > 2) { - points.datapoints = points.datapoints.slice(1, points.datapoints.length-1); + if (points.datapoints.length > trim * 2) { + points.datapoints = points.datapoints.slice(trim, points.datapoints.length - trim); } } } @@ -303,7 +304,7 @@ function (_, queryDef) { var docs = []; this.processBuckets(aggregations, target, tmpSeriesList, docs, {}, 0); - this.dropFirstLast(tmpSeriesList, target); + this.trimDatapoints(tmpSeriesList, target); this.nameSeries(tmpSeriesList, target); for (var y = 0; y < tmpSeriesList.length; y++) { diff --git a/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html index b338e5d227f..97c3f591cb2 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html @@ -37,7 +37,7 @@
      -
    • +
    • Interval
    • @@ -48,7 +48,7 @@
      -
    • +
    • Min Doc Count
    • @@ -59,16 +59,14 @@
      -
    • - Drop first & last value +
    • + Trim edges on timeserie
    • -
    • - - +
    • +
    • - +
    diff --git a/public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts index 7c266aa0e47..b8968cc75c3 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts @@ -416,7 +416,7 @@ describe('ElasticResponse', function() { targets = [{ refId: 'A', metrics: [{ type: 'avg', id: '1' }, { type: 'count' }], - bucketAggs: [{ id: '2', type: 'date_histogram', field: 'host', settings: { dropFirstLast: true} }], + bucketAggs: [{ id: '2', type: 'date_histogram', field: 'host', settings: { trimEdges: 1} }], }]; response = { From e320bd025f20cecbeb9e632c42cdcc25b080313a Mon Sep 17 00:00:00 2001 From: Carl Bergquist Date: Wed, 16 Dec 2015 14:35:04 +0100 Subject: [PATCH 39/56] Revert "(cloudwatch) add "Divide Sum By Period" option" --- public/app/plugins/datasource/cloudwatch/datasource.js | 3 --- .../datasource/cloudwatch/partials/query.parameter.html | 3 --- public/app/plugins/datasource/cloudwatch/query_ctrl.js | 1 - 3 files changed, 7 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/datasource.js b/public/app/plugins/datasource/cloudwatch/datasource.js index 3d335c90d81..f606b6e3dc8 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.js +++ b/public/app/plugins/datasource/cloudwatch/datasource.js @@ -330,9 +330,6 @@ function (angular, _, moment, dateMath) { dps.push([null, lastTimestamp + periodMs]); } lastTimestamp = timestamp; - if (options.divideSumByPeriod && stat === 'Sum') { - dp[stat] = dp[stat] / options.period; - } dps.push([dp[stat], timestamp]); }); diff --git a/public/app/plugins/datasource/cloudwatch/partials/query.parameter.html b/public/app/plugins/datasource/cloudwatch/partials/query.parameter.html index bd5dc9fb6ae..7b0785e808d 100644 --- a/public/app/plugins/datasource/cloudwatch/partials/query.parameter.html +++ b/public/app/plugins/datasource/cloudwatch/partials/query.parameter.html @@ -52,9 +52,6 @@
  • -
  • - Sum / Period -
  • diff --git a/public/app/plugins/datasource/cloudwatch/query_ctrl.js b/public/app/plugins/datasource/cloudwatch/query_ctrl.js index deac54a9b24..e24b73cd068 100644 --- a/public/app/plugins/datasource/cloudwatch/query_ctrl.js +++ b/public/app/plugins/datasource/cloudwatch/query_ctrl.js @@ -10,7 +10,6 @@ function (angular, _) { module.controller('CloudWatchQueryCtrl', function($scope) { $scope.init = function() { - $scope.target.divideSumByPeriod = $scope.target.divideSumByPeriod || false; $scope.aliasSyntax = '{{metric}} {{stat}} {{namespace}} {{region}} {{}}'; }; From 2cb83cf19dce67c5191b08b6e9e58f7218ad984a Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Wed, 16 Dec 2015 16:32:55 +0100 Subject: [PATCH 40/56] style(graph.tooltip): moves checkdate logic inside each method. I find it easier to follow and checkdate didnt do much. --- public/app/features/dashboard/dashboardSrv.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/public/app/features/dashboard/dashboardSrv.js b/public/app/features/dashboard/dashboardSrv.js index 7923e1071cb..559adff5c54 100644 --- a/public/app/features/dashboard/dashboardSrv.js +++ b/public/app/features/dashboard/dashboardSrv.js @@ -214,9 +214,7 @@ function (angular, $, _, moment) { }; p.formatDate = function(date, format) { - - date = this.checkDate(date); - + date = moment.isMoment(date) ? date : moment(date); format = format || 'YYYY-MM-DD HH:mm:ss'; return this.timezone === 'browser' ? @@ -225,21 +223,13 @@ function (angular, $, _, moment) { }; p.getRelativeTime = function(date) { - - date = this.checkDate(date); + date = moment.isMoment(date) ? date : moment(date); return this.timezone === 'browser' ? moment(date).fromNow() : moment.utc(date).fromNow(); }; - p.checkDate = function(date) { - if (!moment.isMoment(date)) { - date = moment(date); - } - return date; - }; - p._updateSchema = function(old) { var i, j, k; var oldVersion = this.schemaVersion; From 12889a9509fbdf037f7c43247fc15f10ad40620e Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Thu, 17 Dec 2015 07:17:39 +0100 Subject: [PATCH 41/56] feat(graphite): make sortByName optional fixes #3360 closes #3361 --- public/app/plugins/datasource/graphite/gfunc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/graphite/gfunc.js b/public/app/plugins/datasource/graphite/gfunc.js index cc4cdf01bb7..ec81cda87c5 100644 --- a/public/app/plugins/datasource/graphite/gfunc.js +++ b/public/app/plugins/datasource/graphite/gfunc.js @@ -280,7 +280,7 @@ function (_, $) { addFuncDef({ name: 'sortByName', category: categories.Special, - params: [{ name: "natural", type: "select", options: ["true", "false"] }], + params: [{ name: "natural", type: "select", options: ["true", "false"], optional: true }], defaultParams: ["false"] }); From 26f70a5fd731f6dd6fff9ea218ed317f09c91e50 Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Thu, 17 Dec 2015 09:04:05 +0100 Subject: [PATCH 42/56] fix(settings): make headline more informative --- public/app/features/dashboard/partials/settings.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/features/dashboard/partials/settings.html b/public/app/features/dashboard/partials/settings.html index 347265afed4..9b0e5674fe0 100644 --- a/public/app/features/dashboard/partials/settings.html +++ b/public/app/features/dashboard/partials/settings.html @@ -117,7 +117,7 @@
    -
    Info
    +
    Dashboard info
    • From e49850342871f592b5268066bdced5bd95ef2dfb Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Thu, 17 Dec 2015 09:05:01 +0100 Subject: [PATCH 43/56] fix(elastic): fixed typo --- .../app/plugins/datasource/elasticsearch/partials/config.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/elasticsearch/partials/config.html b/public/app/plugins/datasource/elasticsearch/partials/config.html index 81acd03809c..6e6c00f3bd8 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/config.html +++ b/public/app/plugins/datasource/elasticsearch/partials/config.html @@ -1,7 +1,7 @@

      -
      Elastic search details
      +
      Elasticsearch details
        From 80d757b37142cab4da5229fdc71ff0ece988636c Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Thu, 17 Dec 2015 10:00:53 +0100 Subject: [PATCH 44/56] feat(elasticsearch): move default query parameters to new table --- .../datasource/elasticsearch/partials/config.html | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/partials/config.html b/public/app/plugins/datasource/elasticsearch/partials/config.html index d08a83238ad..595588c1be0 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/config.html +++ b/public/app/plugins/datasource/elasticsearch/partials/config.html @@ -31,7 +31,7 @@
      -
      +
      • Version @@ -42,10 +42,13 @@
      +
      + +
      Default query settings
        -
      • +
      • Group by time interval
      • @@ -53,7 +56,7 @@ spellcheck='false' placeholder="example: >10s">
      • - +
      From 16847fdb41601bda8a1893a01460176210fd7fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 17 Dec 2015 10:13:23 +0100 Subject: [PATCH 45/56] feat(elasticsearch): trim edges, minor refactoring of #3541 --- public/app/plugins/datasource/elasticsearch/bucket_agg.js | 5 ++++- .../datasource/elasticsearch/partials/bucket_agg.html | 2 +- .../datasource/elasticsearch/partials/query.editor.html | 6 +----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/bucket_agg.js b/public/app/plugins/datasource/elasticsearch/bucket_agg.js index 6df01f911d1..8f302d2b136 100644 --- a/public/app/plugins/datasource/elasticsearch/bucket_agg.js +++ b/public/app/plugins/datasource/elasticsearch/bucket_agg.js @@ -95,7 +95,10 @@ function (angular, _, queryDef) { settings.min_doc_count = settings.min_doc_count || 0; $scope.agg.field = $scope.target.timeField; settingsLinkText = 'Interval: ' + settings.interval; - settingsLinkText += ', Min Doc Count: ' + settings.min_doc_count; + + if (settings.min_doc_count > 0) { + settingsLinkText += ', Min Doc Count: ' + settings.min_doc_count; + } if (settings.trimEdges === undefined || settings.trimEdges < 0) { settings.trimEdges = 0; diff --git a/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html index 97c3f591cb2..5c1b538cf9a 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html @@ -60,7 +60,7 @@
      • - Trim edges on timeserie + Trim edges points
      • diff --git a/public/app/plugins/datasource/elasticsearch/partials/query.editor.html b/public/app/plugins/datasource/elasticsearch/partials/query.editor.html index 66058310d0b..99c6aed9aa7 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/query.editor.html +++ b/public/app/plugins/datasource/elasticsearch/partials/query.editor.html @@ -50,14 +50,10 @@ Alias
      • - +
      - -
      - -
      From 746e203f7baddc37d4834c57891cad73c7467957 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Thu, 17 Dec 2015 01:44:05 -0800 Subject: [PATCH 46/56] Admin can toggle editable checkbox --- .../features/dashboard/partials/dashboardTopNav.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/app/features/dashboard/partials/dashboardTopNav.html b/public/app/features/dashboard/partials/dashboardTopNav.html index 1aa417c752a..49fd6f412ac 100644 --- a/public/app/features/dashboard/partials/dashboardTopNav.html +++ b/public/app/features/dashboard/partials/dashboardTopNav.html @@ -29,14 +29,14 @@
    • -
    • -
    -
    +
    @@ -114,6 +114,58 @@
    +
    +
    +
    +
    Info
    +
    +
      +
    • + Last updated at: +
    • +
    • + {{formatDate(dashboardMeta.updated)}} +
    • +
    +
    +
    +
    +
      +
    • + Last updated by: +
    • +
    • + {{dashboardMeta.updatedBy}} +
    • +
    +
    +
    +
    +
      +
    • + Created at: +
    • +
    • + {{formatDate(dashboardMeta.created)}} +
    • +
    +
    +
    +
    +
      +
    • + Created by: +
    • +
    • + {{dashboardMeta.createdBy}} +
    • +
    +
    +
    +
    +
    +
    +
    From 22fd2aed02297e370ee6ad57ed32dea45b661a77 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Fri, 18 Dec 2015 00:30:44 -0800 Subject: [PATCH 52/56] Removed columns from snapshot table --- .../sqlstore/migrations/dashboard_snapshot_mig.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go b/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go index 26e7cea0a6e..0173617bf48 100644 --- a/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go @@ -55,14 +55,4 @@ func addDashboardSnapshotMigrations(mg *Migrator) { Postgres("SELECT 0;"). Mysql("ALTER TABLE dashboard_snapshot MODIFY dashboard MEDIUMTEXT;")) - // add column to store creator of a dashboard snapshot - mg.AddMigration("Add column created_by in dashboard_snapshot", NewAddColumnMigration(snapshotV5, &Column{ - Name: "created_by", Type: DB_BigInt, Nullable: true, - })) - - // add column to store updater of a dashboard snapshot - mg.AddMigration("Add column updated_by in dashboard_snapshot", NewAddColumnMigration(snapshotV5, &Column{ - Name: "updated_by", Type: DB_BigInt, Nullable: true, - })) - } From af371249f9056546807b36dda5d3a0785fe6f1e4 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Fri, 18 Dec 2015 01:52:05 -0800 Subject: [PATCH 53/56] Successfully displayed userdId in UI --- pkg/api/dashboard.go | 5 +++-- pkg/models/dashboards.go | 10 +++------ .../sqlstore/migrations/dashboard_mig.go | 7 +------ .../migrations/dashboard_snapshot_mig.go | 1 - .../features/dashboard/partials/settings.html | 21 +++++-------------- 5 files changed, 12 insertions(+), 32 deletions(-) diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go index 77309a24560..d95f1c71f3e 100644 --- a/pkg/api/dashboard.go +++ b/pkg/api/dashboard.go @@ -4,6 +4,7 @@ import ( "encoding/json" "os" "path" + "strconv" "strings" "github.com/grafana/grafana/pkg/api/dtos" @@ -59,8 +60,7 @@ func GetDashboard(c *middleware.Context) { CanEdit: canEditDashboard(c.OrgRole), Created: dash.Created, Updated: dash.Updated, - CreatedBy: dash.CreatedBy, - UpdatedBy: dash.UpdatedBy, + UpdatedBy: strconv.FormatInt(dash.UpdatedBy, 10), }, } @@ -89,6 +89,7 @@ func DeleteDashboard(c *middleware.Context) { func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) { cmd.OrgId = c.OrgId + cmd.UpdatedBy = c.UserId dash := cmd.GetDashboardModel() if dash.Id == 0 { diff --git a/pkg/models/dashboards.go b/pkg/models/dashboards.go index 9c2350bb7dd..32922213a6a 100644 --- a/pkg/models/dashboards.go +++ b/pkg/models/dashboards.go @@ -33,8 +33,7 @@ type Dashboard struct { Created time.Time Updated time.Time - CreatedBy string - UpdatedBy string + UpdatedBy int64 Title string Data map[string]interface{} @@ -48,8 +47,6 @@ func NewDashboard(title string) *Dashboard { dash.Title = title dash.Created = time.Now() dash.Updated = time.Now() - // TODO:dash.CreatedBy = "Creator" - // TODO:dash.UpdatedBy = "Creator" dash.UpdateSlug() return dash } @@ -81,14 +78,11 @@ func NewDashboardFromJson(data map[string]interface{}) *Dashboard { if dash.Data["version"] != nil { dash.Version = int(dash.Data["version"].(float64)) dash.Updated = time.Now() - // TODO:dash.UpdatedBy = "Updater" } } else { dash.Data["version"] = 0 dash.Created = time.Now() dash.Updated = time.Now() - // TODO:dash.CreatedBy = "Creator" - // TODO:dash.UpdatedBy = "Creator" } return dash @@ -98,6 +92,7 @@ func NewDashboardFromJson(data map[string]interface{}) *Dashboard { func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard { dash := NewDashboardFromJson(cmd.Dashboard) dash.OrgId = cmd.OrgId + dash.UpdatedBy = cmd.UpdatedBy dash.UpdateSlug() return dash } @@ -121,6 +116,7 @@ type SaveDashboardCommand struct { Dashboard map[string]interface{} `json:"dashboard" binding:"Required"` Overwrite bool `json:"overwrite"` OrgId int64 `json:"-"` + UpdatedBy int64 `json:"-"` Result *Dashboard } diff --git a/pkg/services/sqlstore/migrations/dashboard_mig.go b/pkg/services/sqlstore/migrations/dashboard_mig.go index 4994cb0a234..b94f1a7d6ac 100644 --- a/pkg/services/sqlstore/migrations/dashboard_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_mig.go @@ -93,13 +93,8 @@ func addDashboardMigration(mg *Migrator) { Postgres("SELECT 0;"). Mysql("ALTER TABLE dashboard MODIFY data MEDIUMTEXT;")) - // add column to store creator of a dashboard - mg.AddMigration("Add column created_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{ - Name: "created_by", Type: DB_NVarchar, Length: 255, Nullable: false, Default: "Anonymous", - })) - // add column to store updater of a dashboard mg.AddMigration("Add column updated_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{ - Name: "updated_by", Type: DB_NVarchar, Length: 255, Nullable: false, Default: "Anonymous", + Name: "updated_by", Type: DB_Int, Nullable: true, })) } diff --git a/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go b/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go index 0173617bf48..b08cc451e55 100644 --- a/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go @@ -54,5 +54,4 @@ func addDashboardSnapshotMigrations(mg *Migrator) { Sqlite("SELECT 0 WHERE 0;"). Postgres("SELECT 0;"). Mysql("ALTER TABLE dashboard_snapshot MODIFY dashboard MEDIUMTEXT;")) - } diff --git a/public/app/features/dashboard/partials/settings.html b/public/app/features/dashboard/partials/settings.html index 36223f152a0..d9a71655667 100644 --- a/public/app/features/dashboard/partials/settings.html +++ b/public/app/features/dashboard/partials/settings.html @@ -117,7 +117,7 @@
    -
    Info
    +
    Dashboard info
    • @@ -129,17 +129,6 @@
    -
    -
      -
    • - Last updated by: -
    • -
    • - {{dashboardMeta.updatedBy}} -
    • -
    -
    -
    • @@ -151,14 +140,14 @@
    -
    +
    • - Created by: + Last updated by:
    • - {{dashboardMeta.createdBy}} -
    • + {{dashboardMeta.updatedBy}} +
    From cb5c1bd24da97a2952a3e17debcf2b41554c291a Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Fri, 18 Dec 2015 02:30:20 -0800 Subject: [PATCH 54/56] Removed created_by and fixed gofmt --- pkg/api/dtos/models.go | 1 - pkg/models/dashboards.go | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/api/dtos/models.go b/pkg/api/dtos/models.go index a63a45d6695..a7ff9353fa9 100644 --- a/pkg/api/dtos/models.go +++ b/pkg/api/dtos/models.go @@ -41,7 +41,6 @@ type DashboardMeta struct { Expires time.Time `json:"expires"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` - CreatedBy string `json:"createdBy"` UpdatedBy string `json:"updatedBy"` } diff --git a/pkg/models/dashboards.go b/pkg/models/dashboards.go index 32922213a6a..ddf5dd244f5 100644 --- a/pkg/models/dashboards.go +++ b/pkg/models/dashboards.go @@ -92,7 +92,7 @@ func NewDashboardFromJson(data map[string]interface{}) *Dashboard { func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard { dash := NewDashboardFromJson(cmd.Dashboard) dash.OrgId = cmd.OrgId - dash.UpdatedBy = cmd.UpdatedBy + dash.UpdatedBy = cmd.UpdatedBy dash.UpdateSlug() return dash } @@ -116,7 +116,7 @@ type SaveDashboardCommand struct { Dashboard map[string]interface{} `json:"dashboard" binding:"Required"` Overwrite bool `json:"overwrite"` OrgId int64 `json:"-"` - UpdatedBy int64 `json:"-"` + UpdatedBy int64 `json:"-"` Result *Dashboard } From d8b90721b35de087b7c4e9d71193f3e3c0b6d78e Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Fri, 18 Dec 2015 03:38:49 -0800 Subject: [PATCH 55/56] Able to display login Id of the user in Last Updated By --- pkg/api/dashboard.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go index d95f1c71f3e..79485fa8cca 100644 --- a/pkg/api/dashboard.go +++ b/pkg/api/dashboard.go @@ -4,7 +4,6 @@ import ( "encoding/json" "os" "path" - "strconv" "strings" "github.com/grafana/grafana/pkg/api/dtos" @@ -49,6 +48,20 @@ func GetDashboard(c *middleware.Context) { } dash := query.Result + + // Finding the last updater of the dashboard + updater := "Anonymous" + if dash.UpdatedBy != 0 { + userQuery := m.GetUserByIdQuery{Id: dash.UpdatedBy} + userErr := bus.Dispatch(&userQuery) + if userErr != nil { + updater = "Unknown" + } else { + user := userQuery.Result + updater = user.Login + } + } + dto := dtos.DashboardFullWithMeta{ Dashboard: dash.Data, Meta: dtos.DashboardMeta{ @@ -60,7 +73,7 @@ func GetDashboard(c *middleware.Context) { CanEdit: canEditDashboard(c.OrgRole), Created: dash.Created, Updated: dash.Updated, - UpdatedBy: strconv.FormatInt(dash.UpdatedBy, 10), + UpdatedBy: updater, }, } @@ -89,7 +102,12 @@ func DeleteDashboard(c *middleware.Context) { func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) { cmd.OrgId = c.OrgId - cmd.UpdatedBy = c.UserId + + if !c.IsSignedIn { + cmd.UpdatedBy = 0 + } else { + cmd.UpdatedBy = c.UserId + } dash := cmd.GetDashboardModel() if dash.Id == 0 { From 1b341f8000447f7b7c52b99ebe2fe13f4bec7d98 Mon Sep 17 00:00:00 2001 From: carl bergquist Date: Sun, 20 Dec 2015 21:13:44 +0100 Subject: [PATCH 56/56] fix(dashboard_settings): update css for last row --- public/app/features/dashboard/partials/settings.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/app/features/dashboard/partials/settings.html b/public/app/features/dashboard/partials/settings.html index d9a71655667..730d2cadeb8 100644 --- a/public/app/features/dashboard/partials/settings.html +++ b/public/app/features/dashboard/partials/settings.html @@ -129,7 +129,7 @@
    -
    +
    • Created at: @@ -140,7 +140,7 @@
    -
    +
    • Last updated by: