Skip to content

Commit

Permalink
Merge pull request meshery#11695 from MUzairS15/MUzairS15/enhancements
Browse files Browse the repository at this point in the history
[Server] Send `componentsUpdated` as part of `evaluation` in the trace.
  • Loading branch information
MUzairS15 committed Aug 19, 2024
2 parents 8302c38 + 9949450 commit c39c469
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ require (
github.com/jinzhu/copier v0.4.0
github.com/layer5io/gowrk2 v0.6.1
github.com/layer5io/meshery-operator v0.7.0
github.com/layer5io/meshkit v0.7.62
github.com/layer5io/meshkit v0.7.63
github.com/layer5io/meshsync v0.6.24
github.com/layer5io/nighthawk-go v1.0.3
github.com/layer5io/service-mesh-performance v0.6.1
github.com/lib/pq v1.10.9
github.com/manifoldco/promptui v0.9.0
github.com/meshery/schemas v0.7.18
github.com/meshery/schemas v0.7.19
github.com/nsf/termbox-go v1.1.1
github.com/olekukonko/tablewriter v0.0.5
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1616,8 +1616,8 @@ github.com/layer5io/gowrk2 v0.6.1/go.mod h1:ugxQ23+HwQ8dmZYJd1LScw/TLKbdgfN6OOtg
github.com/layer5io/meshery-operator v0.7.0 h1:YXlnsx2Xy5duM+W99vts2fFV4C1KnOCytQi2fxdQTUc=
github.com/layer5io/meshery-operator v0.7.0/go.mod h1:mVMpSrvSH1zgSmcjzk+/astXV5L34NlL/PcZMH6s2IU=
github.com/layer5io/meshkit v0.2.7/go.mod h1:QvEKV8wIEOabiFlUgiu+s78GpJTsRpoRw5pgvEX077Y=
github.com/layer5io/meshkit v0.7.62 h1:lv0GDNlEXD3NKL2BYwDwf3lOtHhVQ+sBwomfjjGXLms=
github.com/layer5io/meshkit v0.7.62/go.mod h1:xPJGKoPDqWKO/7Xnlvcqvbm3us1NUzO5qytUEPyi3Vw=
github.com/layer5io/meshkit v0.7.63 h1:9Qv2J6KSILKRReKzQ8yv/yQkIZwEnLOFDzOvRmoGQsM=
github.com/layer5io/meshkit v0.7.63/go.mod h1:cXNPsHEUwHKHP8WjsmYL1MEXR9URiug7O2T8zWh0GnA=
github.com/layer5io/meshsync v0.6.24 h1:ui/u89NW2yHyCtdVaJuuzrag5a1CbhVB8Lp70/9Y+lw=
github.com/layer5io/meshsync v0.6.24/go.mod h1:0qI6ATBvkVx10C1ymH62NaGPy85ALFF3T9Dx/IEXfy0=
github.com/layer5io/nighthawk-go v1.0.3 h1:AGhip7TM8FjaDJ58jU/7BoPx+O45S7UNImfw7vC2Z0U=
Expand Down Expand Up @@ -1695,8 +1695,8 @@ github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04
github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM=
github.com/meshery/kompose v1.26.2-0.20230425025309-3bb778d54007 h1:JuykLcZhoffc0qkstUou6sFuPvJS+HBmypIFcLDbGkI=
github.com/meshery/kompose v1.26.2-0.20230425025309-3bb778d54007/go.mod h1:UA0RzM2vfEZAW3DDWXy+ozaXBofKFRnyumBksXHz6Nw=
github.com/meshery/schemas v0.7.18 h1:gXHDiPmlLKywfaE3nm5YRdjhWRMTUEsfVvZlJjB93Ug=
github.com/meshery/schemas v0.7.18/go.mod h1:UfiO+zm92yLkaJP0aroNwVnjuozoh793AWDXrKDYmT0=
github.com/meshery/schemas v0.7.19 h1:HS+PCZ3ZXbs7cv0JSUNW3kYnbypt3WqZjQ7fMQPy8uo=
github.com/meshery/schemas v0.7.19/go.mod h1:UfiO+zm92yLkaJP0aroNwVnjuozoh793AWDXrKDYmT0=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM=
github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk=
Expand Down
29 changes: 25 additions & 4 deletions server/handlers/policy_relationship_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/layer5io/meshery/server/models"
"github.com/layer5io/meshery/server/models/pattern/core"
"github.com/meshery/schemas/models/v1alpha3/relationship"
"github.com/meshery/schemas/models/v1beta1/component"
"github.com/meshery/schemas/models/v1beta1/pattern"

"github.com/layer5io/meshkit/models/events"
Expand All @@ -26,7 +27,6 @@ const (
suffix = "_relationship"
)


// swagger:route POST /api/meshmodels/relationships/evaluate EvaluateRelationshipPolicy relationshipPolicyEvalPayloadWrapper
// Handle POST request for evaluating relationships in the provided design file by running a set of provided evaluation queries on the design file
//
Expand Down Expand Up @@ -63,9 +63,7 @@ func (h *Handler) EvaluateRelationshipPolicy(
}
// decode the pattern file

for _, component := range relationshipPolicyEvalPayload.Design.Components {
component.Configuration = core.Format.DePrettify(component.Configuration, false)
}


patternUUID := relationshipPolicyEvalPayload.Design.Id
eventBuilder.ActedUpon(patternUUID)
Expand Down Expand Up @@ -101,6 +99,29 @@ func (h *Handler) EvaluateRelationshipPolicy(
component.Configuration = core.Format.Prettify(component.Configuration, false)
}

if relationshipPolicyEvalPayload.Options.ReturnDiffOnly != nil && *relationshipPolicyEvalPayload.Options.ReturnDiffOnly {
evaluationResponse.Design.Components = []*component.ComponentDefinition{}
evaluationResponse.Design.Relationships = []*relationship.RelationshipDefinition{}
for _, component := range evaluationResponse.Trace.ComponentsUpdated {
_c := component
evaluationResponse.Design.Components = append(evaluationResponse.Design.Components, &_c)
}

for _, relationship := range evaluationResponse.Trace.RelationshipsAdded {
_r := relationship
evaluationResponse.Design.Relationships = append(evaluationResponse.Design.Relationships, &_r)
}
for _, relationship := range evaluationResponse.Trace.RelationshipsRemoved {
_r := relationship
evaluationResponse.Design.Relationships = append(evaluationResponse.Design.Relationships, &_r)
}

}

for _, component := range relationshipPolicyEvalPayload.Design.Components {
component.Configuration = core.Format.DePrettify(component.Configuration, false)
}

// write the response
ec := json.NewEncoder(rw)
err = ec.Encode(evaluationResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ evaluate := eval_results if {
declaration := filter_updated_declaration(val, result)
]

updated_declarations := [decl |
some obj in result
decl := obj.declaration
]
# all pending relationships are now resolved.
updated_design_file := json.patch(input, [{
"op": "replace",
Expand Down Expand Up @@ -108,6 +112,7 @@ evaluate := eval_results if {
eval_results := {
"design": final_design_file,
"trace": {
"componentsUpdated": updated_declarations,
"relationshipsAdded": relationships_added,
"relationshipsRemoved": relationships_deleted,
},
Expand Down

0 comments on commit c39c469

Please sign in to comment.