Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
fa1b92a1
Unverified
Commit
fa1b92a1
authored
Feb 14, 2018
by
Leonard Gram
Committed by
GitHub
Feb 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioning: uses unix epoch timestamps. (#10907)
* provisioning: uses unix epoch timestamps.
parent
ebbc0798
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
8 deletions
+52
-8
pkg/models/dashboards.go
+1
-1
pkg/services/provisioning/dashboards/file_reader.go
+2
-2
pkg/services/sqlstore/dashboard_provisioning.go
+2
-2
pkg/services/sqlstore/dashboard_provisioning_test.go
+2
-2
pkg/services/sqlstore/migrations/common.go
+20
-0
pkg/services/sqlstore/migrations/dashboard_mig.go
+25
-1
No files found.
pkg/models/dashboards.go
View file @
fa1b92a1
...
@@ -229,7 +229,7 @@ type DashboardProvisioning struct {
...
@@ -229,7 +229,7 @@ type DashboardProvisioning struct {
DashboardId
int64
DashboardId
int64
Name
string
Name
string
ExternalId
string
ExternalId
string
Updated
time
.
Time
Updated
int64
}
}
type
SaveProvisionedDashboardCommand
struct
{
type
SaveProvisionedDashboardCommand
struct
{
...
...
pkg/services/provisioning/dashboards/file_reader.go
View file @
fa1b92a1
...
@@ -147,7 +147,7 @@ func (fr *fileReader) saveDashboard(path string, folderId int64, fileInfo os.Fil
...
@@ -147,7 +147,7 @@ func (fr *fileReader) saveDashboard(path string, folderId int64, fileInfo os.Fil
}
}
provisionedData
,
alreadyProvisioned
:=
provisionedDashboardRefs
[
path
]
provisionedData
,
alreadyProvisioned
:=
provisionedDashboardRefs
[
path
]
upToDate
:=
alreadyProvisioned
&&
provisionedData
.
Updated
.
Unix
()
==
resolvedFileInfo
.
ModTime
()
.
Unix
()
upToDate
:=
alreadyProvisioned
&&
provisionedData
.
Updated
==
resolvedFileInfo
.
ModTime
()
.
Unix
()
dash
,
err
:=
fr
.
readDashboardFromFile
(
path
,
resolvedFileInfo
.
ModTime
(),
folderId
)
dash
,
err
:=
fr
.
readDashboardFromFile
(
path
,
resolvedFileInfo
.
ModTime
(),
folderId
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -173,7 +173,7 @@ func (fr *fileReader) saveDashboard(path string, folderId int64, fileInfo os.Fil
...
@@ -173,7 +173,7 @@ func (fr *fileReader) saveDashboard(path string, folderId int64, fileInfo os.Fil
}
}
fr
.
log
.
Debug
(
"saving new dashboard"
,
"file"
,
path
)
fr
.
log
.
Debug
(
"saving new dashboard"
,
"file"
,
path
)
dp
:=
&
models
.
DashboardProvisioning
{
ExternalId
:
path
,
Name
:
fr
.
Cfg
.
Name
,
Updated
:
resolvedFileInfo
.
ModTime
()}
dp
:=
&
models
.
DashboardProvisioning
{
ExternalId
:
path
,
Name
:
fr
.
Cfg
.
Name
,
Updated
:
resolvedFileInfo
.
ModTime
()
.
Unix
()
}
_
,
err
=
fr
.
dashboardRepo
.
SaveProvisionedDashboard
(
dash
,
dp
)
_
,
err
=
fr
.
dashboardRepo
.
SaveProvisionedDashboard
(
dash
,
dp
)
return
provisioningMetadata
,
err
return
provisioningMetadata
,
err
}
}
...
...
pkg/services/sqlstore/dashboard_provisioning.go
View file @
fa1b92a1
...
@@ -26,8 +26,8 @@ func SaveProvisionedDashboard(cmd *models.SaveProvisionedDashboardCommand) error
...
@@ -26,8 +26,8 @@ func SaveProvisionedDashboard(cmd *models.SaveProvisionedDashboardCommand) error
}
}
cmd
.
Result
=
cmd
.
DashboardCmd
.
Result
cmd
.
Result
=
cmd
.
DashboardCmd
.
Result
if
cmd
.
DashboardProvisioning
.
Updated
.
IsZero
()
{
if
cmd
.
DashboardProvisioning
.
Updated
==
0
{
cmd
.
DashboardProvisioning
.
Updated
=
cmd
.
Result
.
Updated
cmd
.
DashboardProvisioning
.
Updated
=
cmd
.
Result
.
Updated
.
Unix
()
}
}
return
saveProvionedData
(
sess
,
cmd
.
DashboardProvisioning
,
cmd
.
Result
)
return
saveProvionedData
(
sess
,
cmd
.
DashboardProvisioning
,
cmd
.
Result
)
...
...
pkg/services/sqlstore/dashboard_provisioning_test.go
View file @
fa1b92a1
...
@@ -31,7 +31,7 @@ func TestDashboardProvisioningTest(t *testing.T) {
...
@@ -31,7 +31,7 @@ func TestDashboardProvisioningTest(t *testing.T) {
DashboardProvisioning
:
&
models
.
DashboardProvisioning
{
DashboardProvisioning
:
&
models
.
DashboardProvisioning
{
Name
:
"default"
,
Name
:
"default"
,
ExternalId
:
"/var/grafana.json"
,
ExternalId
:
"/var/grafana.json"
,
Updated
:
now
,
Updated
:
now
.
Unix
()
,
},
},
}
}
...
@@ -48,7 +48,7 @@ func TestDashboardProvisioningTest(t *testing.T) {
...
@@ -48,7 +48,7 @@ func TestDashboardProvisioningTest(t *testing.T) {
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
So
(
query
.
Result
[
0
]
.
DashboardId
,
ShouldEqual
,
dashId
)
So
(
query
.
Result
[
0
]
.
DashboardId
,
ShouldEqual
,
dashId
)
So
(
query
.
Result
[
0
]
.
Updated
.
Unix
()
,
ShouldEqual
,
now
.
Unix
())
So
(
query
.
Result
[
0
]
.
Updated
,
ShouldEqual
,
now
.
Unix
())
})
})
})
})
})
})
...
...
pkg/services/sqlstore/migrations/common.go
View file @
fa1b92a1
...
@@ -24,3 +24,23 @@ func addTableRenameMigration(mg *Migrator, oldName string, newName string, versi
...
@@ -24,3 +24,23 @@ func addTableRenameMigration(mg *Migrator, oldName string, newName string, versi
migrationId
:=
fmt
.
Sprintf
(
"Rename table %s to %s - %s"
,
oldName
,
newName
,
versionSuffix
)
migrationId
:=
fmt
.
Sprintf
(
"Rename table %s to %s - %s"
,
oldName
,
newName
,
versionSuffix
)
mg
.
AddMigration
(
migrationId
,
NewRenameTableMigration
(
oldName
,
newName
))
mg
.
AddMigration
(
migrationId
,
NewRenameTableMigration
(
oldName
,
newName
))
}
}
func
addTableReplaceMigrations
(
mg
*
Migrator
,
from
Table
,
to
Table
,
migrationVersion
int64
,
tableDataMigration
map
[
string
]
string
)
{
fromV
:=
version
(
migrationVersion
-
1
)
toV
:=
version
(
migrationVersion
)
tmpTableName
:=
to
.
Name
+
"_tmp_qwerty"
createTable
:=
fmt
.
Sprintf
(
"create %v %v"
,
to
.
Name
,
toV
)
copyTableData
:=
fmt
.
Sprintf
(
"copy %v %v to %v"
,
to
.
Name
,
fromV
,
toV
)
dropTable
:=
fmt
.
Sprintf
(
"drop %v"
,
tmpTableName
)
addTableRenameMigration
(
mg
,
from
.
Name
,
tmpTableName
,
fromV
)
mg
.
AddMigration
(
createTable
,
NewAddTableMigration
(
to
))
addTableIndicesMigrations
(
mg
,
toV
,
to
)
mg
.
AddMigration
(
copyTableData
,
NewCopyTableDataMigration
(
to
.
Name
,
tmpTableName
,
tableDataMigration
))
mg
.
AddMigration
(
dropTable
,
NewDropTableMigration
(
tmpTableName
))
}
func
version
(
v
int64
)
string
{
return
fmt
.
Sprintf
(
"v%v"
,
v
)
}
pkg/services/sqlstore/migrations/dashboard_mig.go
View file @
fa1b92a1
package
migrations
package
migrations
import
.
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
import
(
.
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
)
func
addDashboardMigration
(
mg
*
Migrator
)
{
func
addDashboardMigration
(
mg
*
Migrator
)
{
var
dashboardV1
=
Table
{
var
dashboardV1
=
Table
{
...
@@ -192,4 +194,26 @@ func addDashboardMigration(mg *Migrator) {
...
@@ -192,4 +194,26 @@ func addDashboardMigration(mg *Migrator) {
}
}
mg
.
AddMigration
(
"create dashboard_provisioning"
,
NewAddTableMigration
(
dashboardExtrasTable
))
mg
.
AddMigration
(
"create dashboard_provisioning"
,
NewAddTableMigration
(
dashboardExtrasTable
))
dashboardExtrasTableV2
:=
Table
{
Name
:
"dashboard_provisioning"
,
Columns
:
[]
*
Column
{
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
{
Name
:
"dashboard_id"
,
Type
:
DB_BigInt
,
Nullable
:
true
},
{
Name
:
"name"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"external_id"
,
Type
:
DB_Text
,
Nullable
:
false
},
{
Name
:
"updated"
,
Type
:
DB_Int
,
Default
:
"0"
,
Nullable
:
false
},
},
Indices
:
[]
*
Index
{
{
Cols
:
[]
string
{
"dashboard_id"
}},
{
Cols
:
[]
string
{
"dashboard_id"
,
"name"
},
Type
:
IndexType
},
},
}
addTableReplaceMigrations
(
mg
,
dashboardExtrasTable
,
dashboardExtrasTableV2
,
2
,
map
[
string
]
string
{
"id"
:
"id"
,
"dashboard_id"
:
"dashboard_id"
,
"name"
:
"name"
,
"external_id"
:
"external_id"
,
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment