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 13, 2023
1 parent d41d6fd commit d85a783
Show file tree
Hide file tree
Showing 10 changed files with 518 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 @@ -1590,6 +1590,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
31 changes: 30 additions & 1 deletion cmd/tetra/tracingpolicy/tracingpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,36 @@ 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)

// From v0.11 and before, 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.
//
// we can drop the following block (and comment) when we
// feel tetra should support only version after v0.11
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 @@ -931,6 +931,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 @@ -158,9 +158,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 d85a783

Please sign in to comment.