Skip to content

Commit

Permalink
api: extend TracingPolicyStatus with dedicated fields
Browse files Browse the repository at this point in the history
Previously, enabled, filter_id and error were bundled into the info
string. We add new dedicated fields and make the new tetra also
retrocompatible with the old API missing those fields by parsing the
info string.

Signed-off-by: Mahe Tardy <[email protected]>
  • Loading branch information
mtardy committed Oct 10, 2023
1 parent 1e31d00 commit 28d5428
Show file tree
Hide file tree
Showing 10 changed files with 515 additions and 373 deletions.
3 changes: 3 additions & 0 deletions api/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,9 @@ Determins the behaviour of a field filter
| namespace | [string](#string) | | namespace is the namespace of the policy (or empty of the policy is global) |
| info | [string](#string) | | info is additional information about the policy |
| sensors | [string](#string) | repeated | sensors loaded in the scope of this policy |
| enabled | [bool](#bool) | | indicating if the policy is enabled |
| filter_id | [uint64](#uint64) | | filter ID of the policy used for k8s filtering |
| error | [string](#string) | | potential error of the policy |



Expand Down
275 changes: 153 additions & 122 deletions api/v1/tetragon/sensors.pb.go

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion api/v1/tetragon/sensors.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ message TracingPolicyStatus {
string info = 4;
// sensors loaded in the scope of this policy
repeated string sensors = 5;

// indicating if the policy is enabled
bool enabled = 6;
// filter ID of the policy used for k8s filtering
uint64 filter_id = 7;
// potential error of the policy
string error = 8;
}

message ListTracingPoliciesResponse {
Expand Down
28 changes: 27 additions & 1 deletion cmd/tetra/tracingpolicy/tracingpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,33 @@ func New() *cobra.Command {
}

sensors := strings.Join(pol.Sensors, ",")
cmd.Printf("%d %s (%s) %s %s\n", pol.Id, pol.Name, pol.Info, namespace, sensors)

// Previously, enabled, filterID and error were bundled in a
// string. To have a retro-compatible tetra command, we scan
// the string. If the scan fails, it means something else
// might be in Info and we print it.
if pol.Info != "" {
var parsedEnabled bool
var parsedFilterID uint64
var parsedError string
var parsedName string
str := strings.NewReader(pol.Info)
_, err := fmt.Fscanf(str, "%253s enabled:%t filterID:%d error:%512s", &parsedName, &parsedEnabled, &parsedFilterID, &parsedError)
if err == nil {
pol.Enabled = parsedEnabled
pol.FilterId = parsedFilterID
pol.Error = parsedError
pol.Info = ""
}
}

cmd.Printf("[%d] %s enabled:%t filterID:%d namespace:%s sensors:%s\n", pol.Id, pol.Name, pol.Enabled, pol.FilterId, namespace, sensors)
if pol.Info != "" {
cmd.Printf("\tinfo: %s\n", pol.Info)
}
if pol.Error != "" && pol.Error != "<nil>" {
cmd.Printf("\terror: %s\n", pol.Error)
}
}
}

Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/content/en/docs/reference/grpc-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,9 @@ Determins the behaviour of a field filter
| namespace | [string](#string) | | namespace is the namespace of the policy (or empty of the policy is global) |
| info | [string](#string) | | info is additional information about the policy |
| sensors | [string](#string) | repeated | sensors loaded in the scope of this policy |
| enabled | [bool](#bool) | | indicating if the policy is enabled |
| filter_id | [uint64](#uint64) | | filter ID of the policy used for k8s filtering |
| error | [string](#string) | | potential error of the policy |

<a name="tetragon-FineGuidanceSensors"></a>

Expand Down
8 changes: 5 additions & 3 deletions pkg/sensors/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ func (h *handler) listTracingPolicies(op *tracingPolicyList) error {
}

pol := tetragon.TracingPolicyStatus{
Id: col.tracingpolicyID,
Name: name,
Info: fmt.Sprintf("%s enabled:%t filterID:%d error:%v", col.tracingpolicy.TpInfo(), col.enabled, col.policyfilterID, col.err),
Id: col.tracingpolicyID,
Name: name,
Enabled: col.enabled,
FilterId: col.policyfilterID,
Error: fmt.Sprint(col.err),
}

pol.Namespace = ""
Expand Down
275 changes: 153 additions & 122 deletions vendor/github.com/cilium/tetragon/api/v1/tetragon/sensors.pb.go

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 28d5428

Please sign in to comment.