Skip to content

Commit

Permalink
feat: Rename module to resources and look for all resources (#118)
Browse files Browse the repository at this point in the history
Co-authored-by: Nina Hingerl <[email protected]>
  • Loading branch information
rakesh-garimella and NHingerl authored Sep 10, 2024
1 parent 826f856 commit e1ffe70
Show file tree
Hide file tree
Showing 17 changed files with 478 additions and 241 deletions.
3 changes: 2 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ linters:
# Depreacted linters
- gomnd
- execinquery
- exportloopref
# Linters to be enabled after fixing the issues
- intrange
- cyclop
Expand Down Expand Up @@ -55,7 +56,7 @@ linters-settings:
- pkg: "k8s.io/apimachinery/pkg/apis/meta/v1"
alias: metav1
- pkg: "k8s.io/client-go/dynamic/fake"
alias: dynamicfake
alias: dynamicfake
- pkg: "k8s.io/client-go/testing"
alias: clienttesting

Expand Down
12 changes: 6 additions & 6 deletions receiver/kymastatsreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| stability | alpha: metrics |
| Code Owners | kyma-project/observability |

The Kyma Stats Receiver pulls Kyma modules from the API server, creates status metrics, and sends them down the metric pipeline for further processing.
The Kyma Stats Receiver pulls Kyma resources from the API server, creates status metrics, and sends them down the metric pipeline for further processing.

## Metrics

Expand All @@ -18,7 +18,7 @@ The following settings are required:

- `auth_type` (default = `serviceAccount`): Specifies the authentication method for accessing the Kubernetes API server.
Options include `none` (no authentication), `serviceAccount` (uses the default service account token assigned to the Pod), or `kubeConfig` (uses credentials from `~/.kube/config`).
- `modules`: A list of API group-version-resources of Kyma modules. For each group-version-resource, the status metrics are generated for the first resource instance found.
- `resources`: A list of API group-version-resources of Kyma resources. Status metrics are generated for each group-version-resource.

The following settings are optional:

Expand All @@ -33,18 +33,18 @@ Example:
auth_type: seviceAccount
collection_interval: 30s
metrics:
kyma.module.status.state:
kyma.resource.status.state:
enabled: true
kyma.module.status.conditions:
kyma.resource.status.conditions:
enabled: true
modules:
resources:
- group: operator.kyma-project.io
version: v1alpha1
resource: telemetries
resource_attributes:
k8s.namespace.name:
enabled: true
kyma.module.name:
kyma.resource.name:
enabled: true
```
Expand Down
10 changes: 5 additions & 5 deletions receiver/kymastatsreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ type Config struct {
k8sconfig.APIConfig `mapstructure:",squash"`
scraperhelper.ControllerConfig `mapstructure:",squash"`
metadata.MetricsBuilderConfig `mapstructure:",squash"`
Modules []ModuleConfig `mapstructure:"modules"`
Resources []ResourceConfig `mapstructure:"resources"`

// Used for unit testing only
makeDynamicClient func() (dynamic.Interface, error)
}

type ModuleConfig struct {
type ResourceConfig struct {
Group string `mapstructure:"group"`
Version string `mapstructure:"version"`
Resource string `mapstructure:"resource"`
}

var errEmptyModules = errors.New("empty modules")
var errEmptyResources = errors.New("empty resources")

func (cfg *Config) Validate() error {
if err := cfg.APIConfig.Validate(); err != nil {
Expand All @@ -38,8 +38,8 @@ func (cfg *Config) Validate() error {
return err
}

if len(cfg.Modules) == 0 {
return errEmptyModules
if len(cfg.Resources) == 0 {
return errEmptyResources
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions receiver/kymastatsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestLoadConfig(t *testing.T) {
},
ControllerConfig: scraperhelper.ControllerConfig{CollectionInterval: duration, InitialDelay: delay},
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Modules: []ModuleConfig{
Resources: []ResourceConfig{
{
Group: "operator.kyma-project.io",
Version: "v1alpha1",
Expand All @@ -55,7 +55,7 @@ func TestLoadConfig(t *testing.T) {
},
ControllerConfig: scraperhelper.ControllerConfig{CollectionInterval: 30 * time.Second, InitialDelay: delay},
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Modules: []ModuleConfig{
Resources: []ResourceConfig{
{
Group: "operator.kyma-project.io",
Version: "v1alpha1",
Expand All @@ -72,7 +72,7 @@ func TestLoadConfig(t *testing.T) {
},
ControllerConfig: scraperhelper.ControllerConfig{CollectionInterval: 10 * time.Second, InitialDelay: delay},
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Modules: []ModuleConfig{
Resources: []ResourceConfig{
{
Group: "operator.kyma-project.io",
Version: "v1alpha1",
Expand All @@ -97,7 +97,7 @@ func TestLoadConfig(t *testing.T) {
},
ControllerConfig: scraperhelper.ControllerConfig{CollectionInterval: duration, InitialDelay: delay},
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Modules: []ModuleConfig{
Resources: []ResourceConfig{
{
Group: "operator.kyma-project.io",
Version: "v1alpha1",
Expand All @@ -107,7 +107,7 @@ func TestLoadConfig(t *testing.T) {
},
},
{
id: component.NewIDWithName(metadata.Type, "nomodulegroups"),
id: component.NewIDWithName(metadata.Type, "noresourcegroups"),
expectErr: true,
},
}
Expand Down
21 changes: 12 additions & 9 deletions receiver/kymastatsreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ metrics:
enabled: false
```
### kyma.module.status.conditions
### kyma.resource.status.conditions
The module status conditions. Possible metric values for condition status are 'True' => 1, 'False' => 0, and -1 for other status values.
The resource status conditions. Possible metric values for condition status are 'True' => 1, 'False' => 0, and -1 for other status values.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
Expand All @@ -24,13 +24,13 @@ The module status conditions. Possible metric values for condition status are 'T
| Name | Description | Values |
| ---- | ----------- | ------ |
| reason | The reason of the module condition status. | Any Str |
| status | The status of the module condition. | Any Str |
| type | The type of the module condition. | Any Str |
| reason | The reason of the resource condition status. | Any Str |
| status | The status of the resource condition. | Any Str |
| type | The type of the resource condition. | Any Str |
### kyma.module.status.state
### kyma.resource.status.state
The module status state, metric value is 1 for last scraped module status state, including state as metric attribute.
The resource status state, metric value is 1 for last scraped resource status state, including state as metric attribute.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
Expand All @@ -40,11 +40,14 @@ The module status state, metric value is 1 for last scraped module status state,
| Name | Description | Values |
| ---- | ----------- | ------ |
| state | The state of the module status. | Any Str |
| state | The state of the resource status. | Any Str |
## Resource Attributes
| Name | Description | Values | Enabled |
| ---- | ----------- | ------ | ------- |
| k8s.namespace.name | The name of the namespace that the resource is running in | Any Str | true |
| kyma.module.name | The module kind | Any Str | true |
| k8s.resource.group | The resource group | Any Str | true |
| k8s.resource.kind | The resource kind | Any Str | true |
| k8s.resource.name | The resource name | Any Str | true |
| k8s.resource.version | The resource version | Any Str | true |
26 changes: 19 additions & 7 deletions receiver/kymastatsreceiver/internal/metadata/generated_config.go

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

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

Loading

0 comments on commit e1ffe70

Please sign in to comment.