-
Notifications
You must be signed in to change notification settings - Fork 27
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
Update Flow aggregate field httpVals #334
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
import ( | ||
"container/heap" | ||
"encoding/json" | ||
"fmt" | ||
"net" | ||
"strings" | ||
|
@@ -542,6 +543,16 @@ | |
incomingVal := ieWithValue.GetStringValue() | ||
existingIeWithValue.SetStringValue(incomingVal) | ||
} | ||
case "httpVals": | ||
incomingVal := ieWithValue.GetStringValue() | ||
existingVal := existingIeWithValue.GetStringValue() | ||
updatedHttpVals, err := fillHttpVals(incomingVal, existingVal) | ||
if err != nil { | ||
klog.Errorf("httpVals could not be updated, err: %v", err) | ||
existingIeWithValue.SetStringValue(incomingVal) | ||
} else { | ||
existingIeWithValue.SetStringValue(updatedHttpVals) | ||
} | ||
default: | ||
klog.Errorf("Fields with name %v is not supported in aggregation fields list.", element) | ||
} | ||
|
@@ -984,3 +995,27 @@ | |
} | ||
return false | ||
} | ||
|
||
func fillHttpVals(incomingHttpVals, existingHttpVals string) (string, error) { | ||
incomingHttpValsJson := make(map[int32]string) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgive me if it is a dumb question. Transaction iD should be the same for the same event in different nodes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes transaction ID should be same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's a key point, and the commit message should probably mention it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not able to reproduce it in my local setup, but the thought behind this design is if multiple exporters send the httpvals with different or overlapping TxIDs, we should deduplicate it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we won't be able to use the "latest" record in the current design. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @yuntanghsu, that makes sense. |
||
existingHttpValsJson := make(map[int32]string) | ||
|
||
if incomingHttpVals != "" { | ||
if err := json.Unmarshal([]byte(incomingHttpVals), &incomingHttpValsJson); err != nil { | ||
return "", fmt.Errorf("error parsing JSON: %v", err) | ||
} | ||
} | ||
if existingHttpVals != "" { | ||
if err := json.Unmarshal([]byte(existingHttpVals), &existingHttpValsJson); err != nil { | ||
return "", fmt.Errorf("error parsing JSON: %v", err) | ||
} | ||
} | ||
for key, value := range existingHttpValsJson { | ||
incomingHttpValsJson[key] = value | ||
} | ||
updatedHttpVals, err := json.Marshal(incomingHttpValsJson) | ||
if err != nil { | ||
return "", fmt.Errorf("error converting JSON to string: %v", err) | ||
} | ||
return string(updatedHttpVals), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a unit test for this function to make sure we correlate two HttpVals correctly?