-
Notifications
You must be signed in to change notification settings - Fork 712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove MappedNode & generalise render logic #233
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package render | ||
|
||
import ( | ||
"github.com/weaveworks/scope/report" | ||
) | ||
|
||
// Renderer is something that can render a report to a set of RenderableNodes | ||
type Renderer interface { | ||
Render(report.Report) report.RenderableNodes | ||
AggregateMetadata(rpt report.Report, localID, remoteID string) report.AggregateMetadata | ||
} | ||
|
||
// Reduce renderer is a Renderer which merges together the output of several | ||
// other renderers | ||
type Reduce []Renderer | ||
|
||
// Render produces a set of RenderableNodes given a Report | ||
func (r Reduce) Render(rpt report.Report) report.RenderableNodes { | ||
result := report.RenderableNodes{} | ||
for _, renderer := range r { | ||
result.Merge(renderer.Render(rpt)) | ||
} | ||
return result | ||
} | ||
|
||
// AggregateMetadata produces an AggregateMetadata for a given edge | ||
func (r Reduce) AggregateMetadata(rpt report.Report, localID, remoteID string) report.AggregateMetadata { | ||
metadata := report.AggregateMetadata{} | ||
for _, renderer := range r { | ||
metadata.Merge(renderer.AggregateMetadata(rpt, localID, remoteID)) | ||
} | ||
return metadata | ||
} | ||
|
||
// Map is a Renderer which produces a set of RendererNodes by using a | ||
// Mapper functions and topology selector. | ||
type Map struct { | ||
Selector report.TopologySelector | ||
Mapper report.MapFunc | ||
Pseudo report.PseudoFunc | ||
} | ||
|
||
// Render produces a set of RenderableNodes given a Report | ||
func (m Map) Render(rpt report.Report) report.RenderableNodes { | ||
return m.Selector(rpt).RenderBy(m.Mapper, m.Pseudo) | ||
} | ||
|
||
// AggregateMetadata produces an AggregateMetadata for a given edge | ||
func (m Map) AggregateMetadata(rpt report.Report, localID, remoteID string) report.AggregateMetadata { | ||
return m.Selector(rpt).EdgeMetadata(m.Mapper, localID, remoteID).Transform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package render_test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/weaveworks/scope/render" | ||
"github.com/weaveworks/scope/report" | ||
) | ||
|
||
type mockRenderer struct { | ||
report.RenderableNodes | ||
aggregateMetadata report.AggregateMetadata | ||
} | ||
|
||
func (m mockRenderer) Render(rpt report.Report) report.RenderableNodes { | ||
return m.RenderableNodes | ||
} | ||
func (m mockRenderer) AggregateMetadata(rpt report.Report, localID, remoteID string) report.AggregateMetadata { | ||
return m.aggregateMetadata | ||
} | ||
|
||
func TestReduceRender(t *testing.T) { | ||
renderer := render.Reduce([]render.Renderer{ | ||
mockRenderer{RenderableNodes: report.RenderableNodes{"foo": {ID: "foo"}}}, | ||
mockRenderer{RenderableNodes: report.RenderableNodes{"bar": {ID: "bar"}}}, | ||
}) | ||
|
||
want := report.RenderableNodes{"foo": {ID: "foo"}, "bar": {ID: "bar"}} | ||
have := renderer.Render(report.MakeReport()) | ||
|
||
if !reflect.DeepEqual(want, have) { | ||
t.Errorf("want %+v, have %+v", want, have) | ||
} | ||
} | ||
|
||
func TestReduceEdge(t *testing.T) { | ||
renderer := render.Reduce([]render.Renderer{ | ||
mockRenderer{aggregateMetadata: report.AggregateMetadata{"foo": 1}}, | ||
mockRenderer{aggregateMetadata: report.AggregateMetadata{"bar": 2}}, | ||
}) | ||
|
||
want := report.AggregateMetadata{"foo": 1, "bar": 2} | ||
have := renderer.AggregateMetadata(report.MakeReport(), "", "") | ||
|
||
if !reflect.DeepEqual(want, have) { | ||
t.Errorf("want %+v, have %+v", want, have) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
Sorry, something went wrong.