inspektor-gadget / inspektor-gadget

Inspektor Gadget is a set of tools and framework for data collection and system inspection on Kubernetes clusters and Linux hosts using eBPF
https://www.inspektor-gadget.io
Apache License 2.0
2.16k stars 225 forks source link

Golang API: Improve the parameters handling #2893

Open mauriciovasquezbernal opened 3 months ago

mauriciovasquezbernal commented 3 months ago

Some examples of the usage of the Golang API to run image-based gadgets were introduced in #2753. I think we way to specify parameters is confusing for users. See https://github.com/inspektor-gadget/inspektor-gadget/pull/2753#discussion_r1575262388

Issue

Currently the parameters are passed using a map[string]string:

    // Before running the gadget, let's set some parameters.
    // TODO: link to documentation with the parameters supported by this gadgert
    params := map[string]string{
        // Filter only events from the root user
        "operator.oci.ebpf.uid": "0",
    }

It's impossible for the users to understand what parameters a gadget or operator support. One solution could be to document the parameters (as #2374), but I still fear that many users won't read it.

Possible solutions

I believe we can improve it by implement Golang structures that define the parameters an operator / gadget / runtime supports.

For operators and runtimes it's not so critical as they're implemented in Go, hence we can expose those structures and use then. For instance, the grpc runtime could expose this:

type GlobalParams struct {
    Namespace            string
    RemoteAddresses      []string
    ConnectionTimeout    uint16
    GadgetServiceTCPPort uint16
}

For gadgets it's a bit more difficult as they don't have a Golang implementation. One solution could be to generate them at build time from the eBPF code or allow the user to manually specify them, however this still requires more exploration.

Another challenge is how to transport those parameters over the wire, currently those are encoded as map<string,string>:

https://github.com/inspektor-gadget/inspektor-gadget/blob/582ab8df8caf64a22753018b891e2f143889ba3a/pkg/gadget-service/api/api.proto#L28-L31

hence we'll need a way to marshal and unmarshal from the struct to and from map[string]string. I think some reflection-based magic could help.

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

github-actions[bot] commented 1 month ago

This issue has been automatically closed due to inactivity. If you believe this was closed in error, please feel free to reopen it.