Skip to content

Commit

Permalink
Fix traffic graph (#794)
Browse files Browse the repository at this point in the history
* Fix traffic graph

After we introduced system components (weavelet control and deployment
control), the traffic graph doesn't display anything in the weaver multi
dashboard.

This is because when we display the graph, we look at the components
of the application and then we try to match them to the traffic between
them. However, the edges show traffic for components that are missing from the
status (e.g., the system components). Hence, when we display the graph
there is no 1:1 mapping between components and the traffic between
them.

This PR fixes this issue by not displaying traffic for system
components (in fact the user shouldn't care about that). Maybe a better
fix would be to do this in the javascript itself, but we can do that in
the future if needed.

* Fix linter issues
  • Loading branch information
rgrandl authored Aug 23, 2024
1 parent d613ffe commit 3f55afa
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ jobs:
uses: actions/cache@v3
with:
path: ~/go/bin/staticcheck
key: staticcheck-v0.4.6
key: staticcheck-v0.5.0
if: ${{ matrix.command == 'lint' }}

- name: Install linter
run: go install honnef.co/go/tools/cmd/staticcheck@v0.4.6
run: go install honnef.co/go/tools/cmd/staticcheck@v0.5.0
if: ${{ matrix.command == 'lint' }}

- name: Build the weaver binary
Expand Down
2 changes: 1 addition & 1 deletion cmd/weaver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func run(deployer string, args []string) (int, error) {
binary := "weaver-" + deployer
if _, err := exec.LookPath(binary); err != nil {
msg := fmt.Sprintf(`"weaver %s" is not a weaver command. See "weaver --help". If you're trying to invoke a custom deployer, the %q binary was not found. You may need to install the %q binary or add it to your PATH.`, deployer, binary, binary)
return 1, fmt.Errorf(wrap(msg, 80))
return 1, fmt.Errorf("%s", wrap(msg, 80))
}
cmd := exec.Command(binary, args...)
cmd.Stdin = os.Stdin
Expand Down
2 changes: 1 addition & 1 deletion dev/build_and_test
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function cmd_vet() {

function cmd_lint() {
if ! exists staticcheck; then
printf "staticcheck not found; install via\ngo install honnef.co/go/tools/cmd/staticcheck@v0.4.6\n" >&2
printf "staticcheck not found; install via\ngo install honnef.co/go/tools/cmd/staticcheck@v0.5.0\n" >&2
exit 1
fi

Expand Down
1 change: 1 addition & 0 deletions godeps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ github.com/ServiceWeaver/weaver/internal/status
errors
flag
fmt
github.com/ServiceWeaver/weaver/internal/control
github.com/ServiceWeaver/weaver/internal/files
github.com/ServiceWeaver/weaver/internal/metrics
github.com/ServiceWeaver/weaver/internal/traceio
Expand Down
2 changes: 1 addition & 1 deletion internal/net/call/stub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestErrorArgsNotEncoded(t *testing.T) {
})

if !strings.Contains(err.Error(), "decoder: unable to read") {
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
}

Expand Down
14 changes: 12 additions & 2 deletions internal/status/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strings"
"time"

"github.com/ServiceWeaver/weaver/internal/control"
metrics2 "github.com/ServiceWeaver/weaver/internal/metrics"
"github.com/ServiceWeaver/weaver/internal/traceio"
"github.com/ServiceWeaver/weaver/runtime/logging"
Expand Down Expand Up @@ -265,14 +266,23 @@ func computeTraffic(status *Status, metrics []*protos.MetricSnapshot) []edge {
caller string
component string
}
isSystemComponentFn := func(name string) bool {
return name == control.WeaveletPath || name == control.DeployerPath
}
byPair := map[pair]int{}
for _, metric := range metrics {
if metric.Name != metrics2.MethodCountsName {
continue
}
caller := metric.Labels["caller"]
component := metric.Labels["component"]
if isSystemComponentFn(caller) || isSystemComponentFn(component) {
// Don't display traffic information for the internal system components.
continue
}
call := pair{
caller: metric.Labels["caller"],
component: metric.Labels["component"],
caller: caller,
component: component,
}
byPair[call] += int(metric.Value)
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/codegen/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestErrorDecUnableToRead(t *testing.T) {
dec.Bool()
})
if !strings.Contains(err.Error(), "unable to read #bytes") {
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
}

Expand All @@ -160,7 +160,7 @@ func TestErrorUnableToDecBool(t *testing.T) {
dec.Bool()
})
if !strings.Contains(err.Error(), "unable to decode bool") {
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
}

Expand All @@ -176,7 +176,7 @@ func TestErrorUnableToDecBytes(t *testing.T) {
dec.Bytes()
})
if !strings.Contains(err.Error(), "unable to decode bytes; expected length") {
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
}

Expand Down

0 comments on commit 3f55afa

Please sign in to comment.