Skip to content

Commit

Permalink
Add more components examples
Browse files Browse the repository at this point in the history
  • Loading branch information
thampiotr committed Aug 8, 2023
1 parent a8975b6 commit cdd108d
Show file tree
Hide file tree
Showing 25 changed files with 280 additions and 55 deletions.
7 changes: 4 additions & 3 deletions component/discovery/aws/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import (

func init() {
component.Register(component.Registration{
Name: "discovery.ec2",
Args: EC2Arguments{},
Exports: discovery.Exports{},
Name: "discovery.ec2",
Args: EC2Arguments{},
Exports: discovery.Exports{},
Metadata: component.TargetDiscoveryMetadata(),
Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return NewEC2(opts, args.(EC2Arguments))
},
Expand Down
7 changes: 4 additions & 3 deletions component/discovery/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (

func init() {
component.Register(component.Registration{
Name: "discovery.kubernetes",
Args: Arguments{},
Exports: discovery.Exports{},
Name: "discovery.kubernetes",
Args: Arguments{},
Exports: discovery.Exports{},
Metadata: component.TargetDiscoveryMetadata(),

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
Expand Down
7 changes: 4 additions & 3 deletions component/discovery/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import (

func init() {
component.Register(component.Registration{
Name: "discovery.relabel",
Args: Arguments{},
Exports: Exports{},
Name: "discovery.relabel",
Args: Arguments{},
Exports: Exports{},
Metadata: component.TargetsProcessingMetadata(),

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
Expand Down
10 changes: 4 additions & 6 deletions component/loki/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import (

func init() {
component.Register(component.Registration{
Name: "loki.echo",
Args: Arguments{},
Exports: Exports{},
Metadata: component.Metadata{
Accepts: []component.DataType{component.LokiLogs},
},
Name: "loki.echo",
Args: Arguments{},
Exports: Exports{},
Metadata: component.LokiLogsSinkMetadata(),

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
Expand Down
7 changes: 4 additions & 3 deletions component/loki/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (

func init() {
component.Register(component.Registration{
Name: "loki.process",
Args: Arguments{},
Exports: Exports{},
Name: "loki.process",
Args: Arguments{},
Exports: Exports{},
Metadata: component.LokiLogsProcessingMetadata(),
Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
},
Expand Down
7 changes: 4 additions & 3 deletions component/loki/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (

func init() {
component.Register(component.Registration{
Name: "loki.relabel",
Args: Arguments{},
Exports: Exports{},
Name: "loki.relabel",
Args: Arguments{},
Exports: Exports{},
Metadata: component.LokiLogsProcessingMetadata(),
Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
},
Expand Down
8 changes: 3 additions & 5 deletions component/loki/source/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ import (

func init() {
component.Register(component.Registration{
Name: "loki.source.api",
Args: Arguments{},
Metadata: component.Metadata{
Outputs: []component.DataType{component.LokiLogs},
},
Name: "loki.source.api",
Args: Arguments{},
Metadata: component.LokiLogsSourceMetadata(),
Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
},
Expand Down
5 changes: 3 additions & 2 deletions component/loki/source/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (

func init() {
component.Register(component.Registration{
Name: "loki.source.file",
Args: Arguments{},
Name: "loki.source.file",
Args: Arguments{},
Metadata: component.LokiLogsScraperMetadata(),

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
Expand Down
5 changes: 3 additions & 2 deletions component/loki/source/gcplog/gcplog.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (

func init() {
component.Register(component.Registration{
Name: "loki.source.gcplog",
Args: Arguments{},
Name: "loki.source.gcplog",
Args: Arguments{},
Metadata: component.LokiLogsSourceMetadata(),

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
Expand Down
7 changes: 4 additions & 3 deletions component/loki/write/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (

func init() {
component.Register(component.Registration{
Name: "loki.write",
Args: Arguments{},
Exports: Exports{},
Name: "loki.write",
Args: Arguments{},
Exports: Exports{},
Metadata: component.LokiLogsSinkMetadata(),

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
Expand Down
53 changes: 46 additions & 7 deletions component/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,58 @@ package component
type DataType string

var (
// Targets represents things that need to be scraped. These are used by multiple telemetry signals
// DataTypeTargets represents things that need to be scraped. These are used by multiple telemetry signals
// scraping components and often require special labels, e.g. __path__ label is required for scraping
// logs from files using loki.source.file component.
Targets = DataType("Targets")
DataTypeTargets = DataType("Targets")

// LokiLogs represent logs in Loki format
LokiLogs = DataType("Loki Logs")
// DataTypeLokiLogs represent logs in Loki format
DataTypeLokiLogs = DataType("Loki Logs")

OTELTelemetry = DataType("OTEL Telemetry")
PromMetrics = DataType("Prometheus Metrics")
PyroscopeProfiles = DataType("Pyroscope Profiles")
DataTypeOTELTelemetry = DataType("OTEL Telemetry")
DataTypePromMetrics = DataType("Prometheus Metrics")
DataTypePyroscopeProfiles = DataType("Pyroscope Profiles")
)

func TargetDiscoveryMetadata() Metadata {
return Metadata{
Outputs: []DataType{DataTypeTargets},
}
}

func TargetsProcessingMetadata() Metadata {
return Metadata{
Accepts: []DataType{DataTypeTargets},
Outputs: []DataType{DataTypeTargets},
}
}

func LokiLogsProcessingMetadata() Metadata {
return Metadata{
Accepts: []DataType{DataTypeLokiLogs},
Outputs: []DataType{DataTypeLokiLogs},
}
}

func LokiLogsScraperMetadata() Metadata {
return Metadata{
Accepts: []DataType{DataTypeTargets},
Outputs: []DataType{DataTypeLokiLogs},
}
}

func LokiLogsSourceMetadata() Metadata {
return Metadata{
Outputs: []DataType{DataTypeLokiLogs},
}
}

func LokiLogsSinkMetadata() Metadata {
return Metadata{
Accepts: []DataType{DataTypeLokiLogs},
}
}

type Metadata struct {
Accepts []DataType
Outputs []DataType
Expand Down
4 changes: 4 additions & 0 deletions component/otelcol/exporter/loki/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func init() {
Name: "otelcol.exporter.loki",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},
Metadata: component.Metadata{
Accepts: []component.DataType{component.DataTypeOTELTelemetry},
Outputs: []component.DataType{component.DataTypeLokiLogs},
},

Build: func(o component.Options, a component.Arguments) (component.Component, error) {
return New(o, a.(Arguments))
Expand Down
5 changes: 4 additions & 1 deletion component/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"reflect"
"strings"

Expand Down Expand Up @@ -248,5 +249,7 @@ func Get(name string) (Registration, bool) {
}

func AllNames() []string {
return maps.Keys(registered)
keys := maps.Keys(registered)
slices.Sort(keys)
return keys
}
13 changes: 13 additions & 0 deletions docs/sources/flow/reference/components/discovery.ec2.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,16 @@ Replace the following:
- `PROMETHEUS_REMOTE_WRITE_URL`: The URL of the Prometheus remote_write-compatible server to send metrics to.
- `USERNAME`: The username to use for authentication to the remote_write API.
- `PASSWORD`: The password to use for authentication to the remote_write API.
<!-- START GENERATED COMPATIBLE COMPONENTS -->

## Compatible components

`discovery.ec2` can output data to the following components:

- Components that accept Targets:
- [`discovery.relabel`]({{< relref "../components/discovery.relabel.md" >}})
- [`loki.source.file`]({{< relref "../components/loki.source.file.md" >}})

Note that connecting some components may not be feasible or components may require further configuration to make the connection work correctly. Please refer to the linked documentation for more details.

<!-- END GENERATED COMPATIBLE COMPONENTS -->
13 changes: 13 additions & 0 deletions docs/sources/flow/reference/components/discovery.kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,16 @@ Replace the following:
- `PROMETHEUS_REMOTE_WRITE_URL`: The URL of the Prometheus remote_write-compatible server to send metrics to.
- `USERNAME`: The username to use for authentication to the remote_write API.
- `PASSWORD`: The password to use for authentication to the remote_write API.
<!-- START GENERATED COMPATIBLE COMPONENTS -->

## Compatible components

`discovery.kubernetes` can output data to the following components:

- Components that accept Targets:
- [`discovery.relabel`]({{< relref "../components/discovery.relabel.md" >}})
- [`loki.source.file`]({{< relref "../components/loki.source.file.md" >}})

Note that connecting some components may not be feasible or components may require further configuration to make the connection work correctly. Please refer to the linked documentation for more details.

<!-- END GENERATED COMPATIBLE COMPONENTS -->
20 changes: 20 additions & 0 deletions docs/sources/flow/reference/components/discovery.relabel.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,23 @@ discovery.relabel "keep_backend_only" {
```


<!-- START GENERATED COMPATIBLE COMPONENTS -->

## Compatible components

`discovery.relabel` can accept data from the following components:

- Components that output Targets:
- [`discovery.ec2`]({{< relref "../components/discovery.ec2.md" >}})
- [`discovery.kubernetes`]({{< relref "../components/discovery.kubernetes.md" >}})
- [`discovery.relabel`]({{< relref "../components/discovery.relabel.md" >}})

`discovery.relabel` can output data to the following components:

- Components that accept Targets:
- [`discovery.relabel`]({{< relref "../components/discovery.relabel.md" >}})
- [`loki.source.file`]({{< relref "../components/loki.source.file.md" >}})

Note that connecting some components may not be feasible or components may require further configuration to make the connection work correctly. Please refer to the linked documentation for more details.

<!-- END GENERATED COMPATIBLE COMPONENTS -->
32 changes: 19 additions & 13 deletions docs/sources/flow/reference/components/loki.echo.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ Name | Type | Description

`loki.echo` does not expose any component-specific debug information.

<!-- START GENERATED COMPATIBLE COMPONENTS -->

## Compatible components

`loki.echo` can accept data from the following components:

- Components that output Loki Logs:
- [`loki.process`]({{< relref "../components/loki.process.md" >}})
- [`loki.relabel`]({{< relref "../components/loki.relabel.md" >}})
- [`loki.source.api`]({{< relref "../components/loki.source.api.md" >}})
- [`loki.source.file`]({{< relref "../components/loki.source.file.md" >}})
- [`loki.source.gcplog`]({{< relref "../components/loki.source.gcplog.md" >}})
- [`otelcol.exporter.loki`]({{< relref "../components/otelcol.exporter.loki.md" >}})


Note that connecting some components may not be feasible or components may require further configuration to make the connection work correctly. Please refer to the linked documentation for more details.

<!-- END GENERATED COMPATIBLE COMPONENTS -->

## Example

This example creates a pipeline that reads log files from `/var/log` and
Expand All @@ -61,16 +80,3 @@ loki.source.file "logs" {
loki.echo "example" { }
```

<!-- START GENERATED COMPATIBLE COMPONENTS -->

## Compatible components

`loki.echo` can accept data from the following components:

- Components that output Loki Logs:
- [`loki.source.api`]({{< relref "../components/loki.source.api.md" >}})

Note that connecting some components may not be feasible or components may require further configuration to make the connection work correctly. Please refer to the linked documentation for more details.

<!-- END GENERATED COMPATIBLE COMPONENTS -->
25 changes: 25 additions & 0 deletions docs/sources/flow/reference/components/loki.process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1555,3 +1555,28 @@ loki.process "local" {
}
}
```
<!-- START GENERATED COMPATIBLE COMPONENTS -->

## Compatible components

`loki.process` can accept data from the following components:

- Components that output Loki Logs:
- [`loki.process`]({{< relref "../components/loki.process.md" >}})
- [`loki.relabel`]({{< relref "../components/loki.relabel.md" >}})
- [`loki.source.api`]({{< relref "../components/loki.source.api.md" >}})
- [`loki.source.file`]({{< relref "../components/loki.source.file.md" >}})
- [`loki.source.gcplog`]({{< relref "../components/loki.source.gcplog.md" >}})
- [`otelcol.exporter.loki`]({{< relref "../components/otelcol.exporter.loki.md" >}})

`loki.process` can output data to the following components:

- Components that accept Loki Logs:
- [`loki.echo`]({{< relref "../components/loki.echo.md" >}})
- [`loki.process`]({{< relref "../components/loki.process.md" >}})
- [`loki.relabel`]({{< relref "../components/loki.relabel.md" >}})
- [`loki.write`]({{< relref "../components/loki.write.md" >}})

Note that connecting some components may not be feasible or components may require further configuration to make the connection work correctly. Please refer to the linked documentation for more details.

<!-- END GENERATED COMPATIBLE COMPONENTS -->
25 changes: 25 additions & 0 deletions docs/sources/flow/reference/components/loki.relabel.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,28 @@ loki.relabel "keep_error_only" {
}
```

<!-- START GENERATED COMPATIBLE COMPONENTS -->

## Compatible components

`loki.relabel` can accept data from the following components:

- Components that output Loki Logs:
- [`loki.process`]({{< relref "../components/loki.process.md" >}})
- [`loki.relabel`]({{< relref "../components/loki.relabel.md" >}})
- [`loki.source.api`]({{< relref "../components/loki.source.api.md" >}})
- [`loki.source.file`]({{< relref "../components/loki.source.file.md" >}})
- [`loki.source.gcplog`]({{< relref "../components/loki.source.gcplog.md" >}})
- [`otelcol.exporter.loki`]({{< relref "../components/otelcol.exporter.loki.md" >}})

`loki.relabel` can output data to the following components:

- Components that accept Loki Logs:
- [`loki.echo`]({{< relref "../components/loki.echo.md" >}})
- [`loki.process`]({{< relref "../components/loki.process.md" >}})
- [`loki.relabel`]({{< relref "../components/loki.relabel.md" >}})
- [`loki.write`]({{< relref "../components/loki.write.md" >}})

Note that connecting some components may not be feasible or components may require further configuration to make the connection work correctly. Please refer to the linked documentation for more details.

<!-- END GENERATED COMPATIBLE COMPONENTS -->
Loading

0 comments on commit cdd108d

Please sign in to comment.