github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/metadata/v1/metadata.go (about)

     1  // Copyright 2024 The Inspektor Gadget authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package metadatav1
    16  
    17  import "github.com/inspektor-gadget/inspektor-gadget/pkg/params"
    18  
    19  // Tracer describes the behavior of a gadget that collects and sends events to user space
    20  // TODO: We need to rename this concept not to collide with the opentelemetry concept
    21  type Tracer struct {
    22  	// Name of the perf event array or ring buffer that the gadget uses to send events
    23  	MapName string `yaml:"mapName"`
    24  	// Name of the structure generated by this tracer
    25  	StructName string `yaml:"structName"`
    26  }
    27  
    28  // Topper describes the behavior of a gadget that shows the current activity
    29  // sorted by the highest to the lowest in the resource being observed.
    30  type Topper struct {
    31  	// Name of the hash map that the gadget uses to send statistics
    32  	MapName string `yaml:"mapName"`
    33  	// Name of the structure generated by this topper
    34  	StructName string `yaml:"structName"`
    35  }
    36  
    37  // Snapshotter describes the behavior of a gadget that collects the state of a subsystem
    38  type Snapshotter struct {
    39  	StructName string `yaml:"structName"`
    40  }
    41  
    42  const (
    43  	DefaultColumnWidth = 16
    44  )
    45  
    46  type Alignment string
    47  
    48  const (
    49  	AlignmenNone   Alignment = ""
    50  	AlignmentLeft  Alignment = "left"
    51  	AlignmentRight Alignment = "right"
    52  )
    53  
    54  type EllipsisType string
    55  
    56  const (
    57  	EllipsisNone   EllipsisType = ""
    58  	EllipsisStart  EllipsisType = "start"
    59  	EllipsisMiddle EllipsisType = "middle"
    60  	EllipsisEnd    EllipsisType = "end"
    61  )
    62  
    63  // FieldAttributes describes how to format a field. It's almost 1:1 mapping with columns.Attributes,
    64  // however we are keeping this separated because we don't want to create a strong coupling with the
    65  // columns library now. Later on we can consider merging both of them.
    66  type FieldAttributes struct {
    67  	// Width to reserve for this field
    68  	Width uint `yaml:"width,omitempty"`
    69  	// MinWidth is the minimum width for this field
    70  	MinWidth uint `yaml:"minWidth,omitempty"`
    71  	// MaxWidth is the maximum width for this field
    72  	MaxWidth uint `yaml:"maxWidth,omitempty"`
    73  	// Alignment of this column (left or right)
    74  	Alignment Alignment `yaml:"alignment,omitempty"`
    75  	// Hidden defines whether a column is to be hid by default
    76  	Hidden bool `yaml:"hidden,omitempty"`
    77  	// EllipsisType defines how to abbreviate this column if the value needs more space than is
    78  	// available. (start, middle or end)
    79  	Ellipsis EllipsisType `yaml:"ellipsis,omitempty"`
    80  	// Template defines the template that will be used.
    81  	// TODO: add a link to existing templates
    82  	Template string `yaml:"template,omitempty"`
    83  }
    84  
    85  type Field struct {
    86  	// Field name
    87  	Name string `yaml:"name"`
    88  	// Field description
    89  	Description string `yaml:"description,omitempty"`
    90  	// Attributes defines how the field should be formatted
    91  	Attributes FieldAttributes `yaml:"attributes"`
    92  	// Annotations represents extra information that is not relevant to Inspektor Gadget, but
    93  	// for other applications, like color font for instance.
    94  	Annotations map[string]interface{} `yaml:"annotations,omitempty"`
    95  }
    96  
    97  // Struct describes a type generated by the gadget
    98  type Struct struct {
    99  	Fields []Field `yaml:"fields"`
   100  }
   101  
   102  type EBPFParam struct {
   103  	params.ParamDesc `yaml:",inline"`
   104  }
   105  
   106  type GadgetMetadata struct {
   107  	// Gadget name
   108  	Name string `yaml:"name"`
   109  	// Gadget description
   110  	Description string `yaml:"description,omitempty"`
   111  	// HomepageURL is the URL to the gadget's homepage
   112  	HomepageURL string `yaml:"homepageURL,omitempty"`
   113  	// DocumentationURL is the URL to the gadget's documentation
   114  	DocumentationURL string `yaml:"documentationURL,omitempty"`
   115  	// SourceURL is the URL to the gadget's source code repository
   116  	SourceURL string `yaml:"sourceURL,omitempty"`
   117  	// Annotations is a map of key-value pairs that provide additional information about the gadget
   118  	Annotations map[string]string `yaml:"annotations,omitempty"`
   119  
   120  	// Tracers implemented by the gadget
   121  	// TODO: Rename this field to something that doesn't collide with the opentelemetry concept
   122  	Tracers map[string]Tracer `yaml:"tracers,omitempty"`
   123  	// Toppers implemented by the gadget
   124  	Toppers map[string]Topper `yaml:"toppers,omitempty"`
   125  	// Snapshotters implemented by the gadget
   126  	Snapshotters map[string]Snapshotter `yaml:"snapshotters,omitempty"`
   127  	// Types generated by the gadget
   128  	Structs map[string]Struct `yaml:"structs,omitempty"`
   129  	// Params exposed by the gadget through eBPF constants
   130  	EBPFParams map[string]EBPFParam `yaml:"ebpfParams,omitempty"`
   131  	// Other params exposed by the gadget
   132  	GadgetParams map[string]params.ParamDesc `yaml:"gadgetParams,omitempty"`
   133  }