-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NETOBSERV-1974: use ovnk-lib to get net event messages (#647)
* get net events messages - web reimpl * add ovnk deps * Use ovnk-lib to get event string * Revert "get net events messages - web reimpl" This reverts commit 8efee4c. * fix test and feature name * use released ovnk * fix test
- Loading branch information
Showing
480 changed files
with
103,242 additions
and
146 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package decoders | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/netobserv/network-observability-console-plugin/pkg/model/fields" | ||
ovnmodel "github.com/ovn-org/ovn-kubernetes/go-controller/observability-lib/model" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var dlog = logrus.WithField("module", "decoders") | ||
|
||
func NetworkEventsToString(in string) string { | ||
line := make(map[string]any) | ||
if err := json.Unmarshal([]byte(in), &line); err != nil { | ||
dlog.Errorf("Could not decode NetworkEvent: %v", err) | ||
return in | ||
} | ||
if ne, found := line[fields.NetworkEvents]; found { | ||
if neList, isList := ne.([]any); isList { | ||
var messages []string | ||
for _, item := range neList { | ||
if neItem, isMap := item.(map[string]any); isMap { | ||
messages = append(messages, networkEventItemToString(neItem)) | ||
} | ||
} | ||
line[fields.NetworkEvents] = messages | ||
b, err := json.Marshal(line) | ||
if err != nil { | ||
dlog.Errorf("Could not reencode NetworkEvent: %v", err) | ||
return in | ||
} | ||
return string(b) | ||
} | ||
} | ||
return in | ||
} | ||
|
||
func networkEventItemToString(in map[string]any) string { | ||
if msg := getAsString(in, "Message"); msg != "" { | ||
return msg | ||
} | ||
if feat := getAsString(in, "Feature"); feat == "acl" { | ||
aclObj := ovnmodel.ACLEvent{ | ||
Action: getAsString(in, "Action"), | ||
Actor: getAsString(in, "Type"), | ||
Name: getAsString(in, "Name"), | ||
Namespace: getAsString(in, "Namespace"), | ||
Direction: getAsString(in, "Direction"), | ||
} | ||
return aclObj.String() | ||
} | ||
return "" | ||
} | ||
|
||
func getAsString(in map[string]any, key string) string { | ||
if anyV, hasKey := in[key]; hasKey { | ||
if v, isStr := anyV.(string); isStr { | ||
return v | ||
} | ||
} | ||
return "" | ||
} |
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,31 @@ | ||
package decoders | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestReencode_NoChange(t *testing.T) { | ||
js := `{"SrcK8S_Name":"ip-10-0-1-7.ec2.internal","Bytes":66,"Packets":1,"Interfaces":["br-ex"]}` | ||
out := NetworkEventsToString(js) | ||
assert.Equal(t, js, out) | ||
} | ||
|
||
func TestReencode_UpdateEvent(t *testing.T) { | ||
js := `{"SrcK8S_Name":"ip-10-0-1-7.ec2.internal","Bytes":66,"Packets":1,"Interfaces":["br-ex"],"NetworkEvents":[{"Feature":"acl","Type":"NetpolNode","Action":"allow","Direction":"Ingress"}]}` | ||
out := NetworkEventsToString(js) | ||
assert.Equal( | ||
t, | ||
`{"Bytes":66,"Interfaces":["br-ex"],"NetworkEvents":["Allowed by default allow from local node policy, direction Ingress"],"Packets":1,"SrcK8S_Name":"ip-10-0-1-7.ec2.internal"}`, | ||
out, | ||
) | ||
|
||
js = `{"SrcK8S_Name":"ip-10-0-1-7.ec2.internal","Bytes":66,"Packets":1,"Interfaces":["br-ex"],"NetworkEvents":[{"Message":"custom message"}]}` | ||
out = NetworkEventsToString(js) | ||
assert.Equal( | ||
t, | ||
`{"Bytes":66,"Interfaces":["br-ex"],"NetworkEvents":["custom message"],"Packets":1,"SrcK8S_Name":"ip-10-0-1-7.ec2.internal"}`, | ||
out, | ||
) | ||
} |
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
25 changes: 25 additions & 0 deletions
25
vendor/github.com/cenkalti/backoff/v4/.gitignore
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.