mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 07:11:51 +08:00
dasboard_history: fixed json diff so only dashbord is compared and not the whole dashboard revision object (message and restoreFrom etc was showing up in json diff)
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
|
"github.com/grafana/grafana/pkg/log"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
diff "github.com/yudai/gojsondiff"
|
diff "github.com/yudai/gojsondiff"
|
||||||
deltaFormatter "github.com/yudai/gojsondiff/formatter"
|
deltaFormatter "github.com/yudai/gojsondiff/formatter"
|
||||||
@ -17,6 +18,8 @@ var (
|
|||||||
|
|
||||||
// ErrNilDiff occurs when two compared interfaces are identical.
|
// ErrNilDiff occurs when two compared interfaces are identical.
|
||||||
ErrNilDiff = errors.New("dashdiff: diff is nil")
|
ErrNilDiff = errors.New("dashdiff: diff is nil")
|
||||||
|
|
||||||
|
diffLogger = log.New("dashdiffs")
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiffType int
|
type DiffType int
|
||||||
@ -77,7 +80,10 @@ func CalculateDiff(options *Options) (*Result, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
left, jsonDiff, err := getDiff(baseVersionQuery.Result, newVersionQuery.Result)
|
baseData := baseVersionQuery.Result.Data
|
||||||
|
newData := newVersionQuery.Result.Data
|
||||||
|
|
||||||
|
left, jsonDiff, err := getDiff(baseData, newData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -115,13 +121,13 @@ func CalculateDiff(options *Options) (*Result, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getDiff computes the diff of two dashboard versions.
|
// getDiff computes the diff of two dashboard versions.
|
||||||
func getDiff(originalDash, newDash *models.DashboardVersion) (interface{}, diff.Diff, error) {
|
func getDiff(baseData, newData *simplejson.Json) (interface{}, diff.Diff, error) {
|
||||||
leftBytes, err := simplejson.NewFromAny(originalDash).Encode()
|
leftBytes, err := baseData.Encode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rightBytes, err := simplejson.NewFromAny(newDash).Encode()
|
rightBytes, err := newData.Encode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -97,14 +97,17 @@ func (b *BasicDiff) Basic(lines []*JSONLine) []*BasicBlock {
|
|||||||
|
|
||||||
// iterate through each line
|
// iterate through each line
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
if b.LastIndent == 3 && line.Indent == 2 && line.Change == ChangeNil {
|
// TODO: this condition needs an explaination? what does it mean?
|
||||||
|
if b.LastIndent == 2 && line.Indent == 1 && line.Change == ChangeNil {
|
||||||
if b.Block != nil {
|
if b.Block != nil {
|
||||||
blocks = append(blocks, b.Block)
|
blocks = append(blocks, b.Block)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b.LastIndent = line.Indent
|
b.LastIndent = line.Indent
|
||||||
|
|
||||||
if line.Indent == 2 {
|
// TODO: why special handling for indent 2?
|
||||||
|
if line.Indent == 1 {
|
||||||
switch line.Change {
|
switch line.Change {
|
||||||
case ChangeNil:
|
case ChangeNil:
|
||||||
if line.Change == ChangeNil {
|
if line.Change == ChangeNil {
|
||||||
@ -143,12 +146,14 @@ func (b *BasicDiff) Basic(lines []*JSONLine) []*BasicBlock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: why special handling for indent > 2 ?
|
||||||
// Other Lines
|
// Other Lines
|
||||||
if line.Indent > 2 {
|
if line.Indent > 1 {
|
||||||
// Ensure single line change
|
// Ensure single line change
|
||||||
if line.Key != "" && line.Val != nil && !b.writing {
|
if line.Key != "" && line.Val != nil && !b.writing {
|
||||||
switch line.Change {
|
switch line.Change {
|
||||||
case ChangeAdded, ChangeDeleted:
|
case ChangeAdded, ChangeDeleted:
|
||||||
|
|
||||||
b.Block.Changes = append(b.Block.Changes, &BasicChange{
|
b.Block.Changes = append(b.Block.Changes, &BasicChange{
|
||||||
Key: line.Key,
|
Key: line.Key,
|
||||||
Change: line.Change,
|
Change: line.Change,
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="gf-tabs-item" ng-show="ctrl.mode === 'compare'">
|
<li class="gf-tabs-item" ng-show="ctrl.mode === 'compare'">
|
||||||
<span class="active gf-tabs-link">
|
<span class="active gf-tabs-link">
|
||||||
Version {{ctrl.baseInfo.version}} <i class="fa fa-arrows-h"></i> Version {{ctrl.newInfo.version}}
|
Version Comparison
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -123,7 +123,7 @@
|
|||||||
Version {{ctrl.newInfo.version}}
|
Version {{ctrl.newInfo.version}}
|
||||||
<cite class="muted" ng-if="ctrl.isNewLatest">(Latest)</cite>
|
<cite class="muted" ng-if="ctrl.isNewLatest">(Latest)</cite>
|
||||||
</h4>
|
</h4>
|
||||||
<section ng-if="ctrl.diff === 'basic'">
|
<section>
|
||||||
<p class="small muted">
|
<p class="small muted">
|
||||||
<strong>Version {{ctrl.newInfo.version}}</strong> updated by
|
<strong>Version {{ctrl.newInfo.version}}</strong> updated by
|
||||||
<span>{{ctrl.newInfo.createdBy}} </span>
|
<span>{{ctrl.newInfo.createdBy}} </span>
|
||||||
|
Reference in New Issue
Block a user