Skip to content

Commit

Permalink
wire in the otel converter and create a migration guide (#6790)
Browse files Browse the repository at this point in the history
* wire in the otel converter and create a migration guide

Signed-off-by: erikbaranowski <[email protected]>

* Apply suggestions from code review

Co-authored-by: Clayton Cornell <[email protected]>

---------

Signed-off-by: erikbaranowski <[email protected]>
Co-authored-by: Clayton Cornell <[email protected]>
  • Loading branch information
erikbaranowski and clayton-cornell authored Mar 29, 2024
1 parent 5e037eb commit 88780b8
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Main (unreleased)

- Add ability to convert static mode positions file to `loki.source.file` compatible via `legacy_positions_file` argument. (@mattdurham)

- Added support for `otelcol` configuration conversion in `grafana-agent convert` and `grafana-agent run` commands. (@rfratto, @erikbaranowski, @tpaschalis, @hainenber)

### Features

- Added a new CLI flag `--stability.level` which defines the minimum stability
Expand Down
33 changes: 26 additions & 7 deletions docs/sources/flow/reference/cli/convert.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ The following flags are supported:

* `--report`, `-r`: The filepath and filename where the report is written.

* `--source-format`, `-f`: Required. The format of the source file. Supported formats: [prometheus], [promtail], [static].
* `--source-format`, `-f`: Required. The format of the source file. Supported formats: [otelcol], [prometheus], [promtail], [static].

* `--bypass-errors`, `-b`: Enable bypassing errors when converting.

* `--extra-args`, `e`: Extra arguments from the original format used by the converter.

[otelcol]: #opentelemetry-collector
[prometheus]: #prometheus
[promtail]: #promtail
[static]: #static
Expand All @@ -72,6 +73,17 @@ Errors are defined as non-critical issues identified during the conversion
where an output can still be generated. These can be bypassed using the
`--bypass-errors` flag.

### OpenTelemetry Collector

You can use the `--source-format=otelcol` to convert the source configuration from an [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/configuration/) to a {{< param "PRODUCT_NAME" >}} configuration.

Many OpenTelemetry Collector components are supported.
Review the `otelcol.*` component information in the [Component Reference][] for more information about `otelcol` components that you can convert.
If a source configuration has unsupported features, you will receive [errors] when you convert it to a flow configuration.
The converter raises warnings for configuration options that may require your attention.

Refer to [Migrate from OpenTelemetry Collector to {{< param "PRODUCT_NAME" >}}][migrate-otelcol] for a detailed migration guide.

### Prometheus

Using the `--source-format=prometheus` will convert the source configuration from
Expand All @@ -86,7 +98,7 @@ This includes Prometheus features such as
and many supported *_sd_configs. Unsupported features in a source configuration result
in [errors].

Refer to [Migrate from Prometheus to {{< param "PRODUCT_NAME" >}}]({{< relref "../../tasks/migrate/from-prometheus/" >}}) for a detailed migration guide.
Refer to [Migrate from Prometheus to {{< param "PRODUCT_NAME" >}}][migrate-prometheus] for a detailed migration guide.

### Promtail

Expand All @@ -100,21 +112,28 @@ are supported and can be converted to {{< param "PRODUCT_NAME" >}} configuration
If you have unsupported features in a source configuration, you will receive [errors] when you convert to a flow configuration. The converter will
also raise warnings for configuration options that may require your attention.

Refer to [Migrate from Promtail to {{< param "PRODUCT_NAME" >}}]({{< relref "../../tasks/migrate/from-promtail/" >}}) for a detailed migration guide.
Refer to [Migrate from Promtail to {{< param "PRODUCT_NAME" >}}][migrate-promtail] for a detailed migration guide.

### Static

Using the `--source-format=static` will convert the source configuration from a
[Grafana Agent Static]({{< relref "../../../static" >}}) configuration to a {{< param "PRODUCT_NAME" >}} configuration.
[Grafana Agent Static][] configuration to a {{< param "PRODUCT_NAME" >}} configuration.

Include `--extra-args` for passing additional command line flags from the original format.
For example, `--extra-args="-enable-features=integrations-next"` will convert a Grafana Agent Static
[integrations-next]({{< relref "../../../static/configuration/integrations/integrations-next/" >}})
configuration to a {{< param "PRODUCT_NAME" >}} configuration. You can also
[integrations-next][] configuration to a {{< param "PRODUCT_NAME" >}} configuration. You can also
expand environment variables with `--extra-args="-config.expand-env"`. You can combine multiple command line
flags with a space between each flag, for example `--extra-args="-enable-features=integrations-next -config.expand-env"`.

If you have unsupported features in a Static mode source configuration, you will receive [errors][] when you convert to a Flow mode configuration. The converter will
also raise warnings for configuration options that may require your attention.

Refer to [Migrate from Grafana Agent Static to {{< param "PRODUCT_NAME" >}}]({{< relref "../../tasks/migrate/from-static/" >}}) for a detailed migration guide.
Refer to [Migrate from Grafana Agent Static to {{< param "PRODUCT_NAME" >}}][migrate-static] for a detailed migration guide.

[Component Reference]: ../../components/
[migrate-otelcol]: ../../../tasks/migrate/from-otelcol/
[migrate-prometheus]: ../../../tasks/migrate/from-prometheus/
[migrate-promtail]: ../../../tasks/migrate/from-promtail/
[migrate-static]: ../../../tasks/migrate/from-static/
[Grafana Agent Static]: ../../../../static/
[integrations-next]: ../../../../static/configuration/integrations/integrations-next/
2 changes: 1 addition & 1 deletion docs/sources/flow/reference/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The following flags are supported:
* `--cluster.advertise-interfaces`: List of interfaces used to infer an address to advertise. Set to `all` to use all available network interfaces on the system. (default `"eth0,en0"`).
* `--cluster.max-join-peers`: Number of peers to join from the discovered set (default `5`).
* `--cluster.name`: Name to prevent nodes without this identifier from joining the cluster (default `""`).
* `--config.format`: The format of the source file. Supported formats: `flow`, `prometheus`, `promtail`, `static` (default `"flow"`).
* `--config.format`: The format of the source file. Supported formats: `flow`, `otelcol`, `prometheus`, `promtail`, `static` (default `"flow"`).
* `--config.bypass-conversion-errors`: Enable bypassing errors when converting (default `false`).
* `--config.extra-args`: Extra arguments from the original format used by the converter.

Expand Down
2 changes: 1 addition & 1 deletion docs/sources/flow/tasks/migrate/from-operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ canonical: https://grafana.com/docs/agent/latest/flow/tasks/migrate/from-operato
description: Migrate from Grafana Agent Operator to Grafana Agent Flow
menuTitle: Migrate from Operator
title: Migrate from Grafana Agent Operator to Grafana Agent Flow
weight: 320
weight: 300
---

# Migrate from Grafana Agent Operator to {{% param "PRODUCT_NAME" %}}
Expand Down
274 changes: 274 additions & 0 deletions docs/sources/flow/tasks/migrate/from-otelcol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
---
canonical: https://grafana.com/docs/agent/latest/flow/tasks/migrate/from-otelcol/
description: Learn how to migrate from OpenTelemetry Collector to Grafana Agent Flow
menuTitle: Migrate from OpenTelemetry Collector
title: Migrate from OpenTelemetry Collector to Grafana Agent Flow
weight: 310
---

# Migrate from OpenTelemetry Collector to {{% param "PRODUCT_NAME" %}}

The built-in {{< param "PRODUCT_ROOT_NAME" >}} convert command can migrate your [OpenTelemetry Collector][] configuration to a {{< param "PRODUCT_NAME" >}} configuration.

This topic describes how to:

* Convert an OpenTelemetry Collector configuration to a {{< param "PRODUCT_NAME" >}} configuration.
* Run an OpenTelemetry Collector configuration natively using {{< param "PRODUCT_NAME" >}}.

## Components used in this topic

* [otelcol.receiver.otlp][]
* [otelcol.processor.memory_limiter][]
* [otelcol.exporter.otlp][]

## Before you begin

* You must have an existing OpenTelemetry Collector configuration.
* You must have a set of OpenTelemetry Collector applications ready to push telemetry data to {{< param "PRODUCT_NAME" >}}.
* You must be familiar with the concept of [Components][] in {{< param "PRODUCT_NAME" >}}.

## Convert an OpenTelemetry Collector configuration

To fully migrate your configuration from [OpenTelemetry Collector] to {{< param "PRODUCT_NAME" >}}, you must convert your OpenTelemetry Collector configuration into a {{< param "PRODUCT_NAME" >}} configuration.
This conversion will enable you to take full advantage of the many additional features available in {{< param "PRODUCT_NAME" >}}.

> In this task, you will use the [convert][] CLI command to output a {{< param "PRODUCT_NAME" >}}
> configuration from a OpenTelemetry Collector configuration.
1. Open a terminal window and run the following command.

{{< code >}}

```static-binary
AGENT_MODE=flow grafana-agent convert --source-format=otelcol --output=<OUTPUT_CONFIG_PATH> <INPUT_CONFIG_PATH>
```

```flow-binary
grafana-agent-flow convert --source-format=otelcol --output=<OUTPUT_CONFIG_PATH> <INPUT_CONFIG_PATH>
```

{{< /code >}}

Replace the following:

- _`<INPUT_CONFIG_PATH>`_: The full path to the OpenTelemetry Collector configuration.
- _`<OUTPUT_CONFIG_PATH>`_: The full path to output the {{< param "PRODUCT_NAME" >}} configuration.

1. [Run][] {{< param "PRODUCT_NAME" >}} using the new {{< param "PRODUCT_NAME" >}} configuration from _`<OUTPUT_CONFIG_PATH>`_:

### Debugging

1. If the `convert` command can't convert an OpenTelemetry Collector configuration, diagnostic information is sent to `stderr`.\
You can bypass any non-critical issues and output the {{< param "PRODUCT_NAME" >}} configuration using a best-effort conversion by including the `--bypass-errors` flag.

{{< admonition type="caution" >}}
If you bypass the errors, the behavior of the converted configuration may not match the original OpenTelemetry Collector configuration.
Make sure you fully test the converted configuration before using it in a production environment.
{{< /admonition >}}

{{< code >}}

```static-binary
AGENT_MODE=flow grafana-agent convert --source-format=otelcol --bypass-errors --output=<OUTPUT_CONFIG_PATH> <INPUT_CONFIG_PATH>
```

```flow-binary
grafana-agent-flow convert --source-format=otelcol --bypass-errors --output=<OUTPUT_CONFIG_PATH> <INPUT_CONFIG_PATH>
```

{{< /code >}}

Replace the following:

- _`<INPUT_CONFIG_PATH>`_: The full path to the OpenTelemetry Collector configuration.
- _`<OUTPUT_CONFIG_PATH>`_: The full path to output the {{< param "PRODUCT_NAME" >}} configuration.

1. You can also output a diagnostic report by including the `--report` flag.

{{< code >}}

```static-binary
AGENT_MODE=flow grafana-agent convert --source-format=otelcol --report=<OUTPUT_REPORT_PATH> --output=<OUTPUT_CONFIG_PATH> <INPUT_CONFIG_PATH>
```

```flow-binary
grafana-agent-flow convert --source-format=otelcol --report=<OUTPUT_REPORT_PATH> --output=<OUTPUT_CONFIG_PATH> <INPUT_CONFIG_PATH>
```

{{< /code >}}

Replace the following:

- _`<INPUT_CONFIG_PATH>`_: The full path to the OpenTelemetry Collector configuration.
- _`<OUTPUT_CONFIG_PATH>`_: The full path to output the {{< param "PRODUCT_NAME" >}} configuration.
- _`<OUTPUT_REPORT_PATH>`_: The output path for the report.

Using the [example][] OpenTelemetry Collector configuration below, the diagnostic report provides the following information:

```plaintext
(Info) Converted receiver/otlp into otelcol.receiver.otlp.default
(Info) Converted processor/memory_limiter into otelcol.processor.memory_limiter.default
(Info) Converted exporter/otlp into otelcol.exporter.otlp.default
A configuration file was generated successfully.
```

## Run an OpenTelemetry Collector configuration

If you’re not ready to completely switch to a {{< param "PRODUCT_NAME" >}} configuration, you can run {{< param "PRODUCT_ROOT_NAME" >}} using your existing OpenTelemetry Collector configuration.
The `--config.format=otelcol` flag tells {{< param "PRODUCT_ROOT_NAME" >}} to convert your OpenTelemetry Collector configuration to a {{< param "PRODUCT_NAME" >}} configuration and load it directly without saving the new configuration.
This allows you to try {{< param "PRODUCT_NAME" >}} without modifying your existing OpenTelemetry Collector configuration infrastructure.

> In this task, you will use the [run][] CLI command to run {{< param "PRODUCT_NAME" >}}
> using an OpenTelemetry Collector configuration.
[Run][] {{< param "PRODUCT_NAME" >}} and include the command line flag `--config.format=otelcol`.
Your configuration file must be a valid OpenTelemetry Collector configuration file rather than a {{< param "PRODUCT_NAME" >}} configuration file.

### Debugging

1. You can follow the convert CLI command [debugging][] instructions to generate a diagnostic report.

1. Refer to the {{< param "PRODUCT_NAME" >}} [Debugging][DebuggingUI] for more information about a running {{< param "PRODUCT_NAME" >}}.

1. If your OpenTelemetry Collector configuration can't be converted and loaded directly into {{< param "PRODUCT_NAME" >}}, diagnostic information is sent to `stderr`.
You can bypass any non-critical issues and start the Agent by including the `--config.bypass-conversion-errors` flag in addition to `--config.format=otelcol`.

{{< admonition type="caution" >}}
If you bypass the errors, the behavior of the converted configuration may not match the original Prometheus configuration.
Do not use this flag in a production environment.
{{< /admonition >}}

## Example

This example demonstrates converting an OpenTelemetry Collector configuration file to a {{< param "PRODUCT_NAME" >}} configuration file.

The following OpenTelemetry Collector configuration file provides the input for the conversion.

```yaml
receivers:
otlp:
protocols:
grpc:
http:

exporters:
otlp:
endpoint: database:4317

processors:
memory_limiter:
limit_percentage: 90
check_interval: 1s


service:
pipelines:
metrics:
receivers: [otlp]
processors: [memory_limiter]
exporters: [otlp]
logs:
receivers: [otlp]
processors: [memory_limiter]
exporters: [otlp]
traces:
receivers: [otlp]
processors: [memory_limiter]
exporters: [otlp]
```
The convert command takes the YAML file as input and outputs a [River][] file.
{{< code >}}
```static-binary
AGENT_MODE=flow grafana-agent convert --source-format=otelcol --output=<OUTPUT_CONFIG_PATH> <INPUT_CONFIG_PATH>
```

```flow-binary
grafana-agent-flow convert --source-format=otelcol --output=<OUTPUT_CONFIG_PATH> <INPUT_CONFIG_PATH>
```

{{< /code >}}

Replace the following:

- _`<INPUT_CONFIG_PATH>`_: The full path to the OpenTelemetry Collector configuration.
- _`<OUTPUT_CONFIG_PATH>`_: The full path to output the {{< param "PRODUCT_NAME" >}} configuration.

The new {{< param "PRODUCT_NAME" >}} configuration file looks like this:

```river
otelcol.receiver.otlp "default" {
grpc { }
http { }
output {
metrics = [otelcol.processor.memory_limiter.default.input]
logs = [otelcol.processor.memory_limiter.default.input]
traces = [otelcol.processor.memory_limiter.default.input]
}
}
otelcol.processor.memory_limiter "default" {
check_interval = "1s"
limit_percentage = 90
output {
metrics = [otelcol.exporter.otlp.default.input]
logs = [otelcol.exporter.otlp.default.input]
traces = [otelcol.exporter.otlp.default.input]
}
}
otelcol.exporter.otlp "default" {
client {
endpoint = "database:4317"
}
}
```

## Limitations

Configuration conversion is done on a best-effort basis. {{< param "PRODUCT_ROOT_NAME" >}} will issue warnings or errors where the conversion can't be performed.

After the configuration is converted, review the {{< param "PRODUCT_NAME" >}} configuration file created and verify that it's correct before starting to use it in a production environment.

The following list is specific to the convert command and not {{< param "PRODUCT_NAME" >}}:

* Components are supported which directly embed upstream OpenTelemetry Collector features. You can get a general idea of which exist in
{{< param "PRODUCT_NAME" >}} for conversion by reviewing the `otelcol.*` components in the [Component Reference][].
Any additional unsupported features are returned as errors during conversion.
* Check if you are using any extra command line arguments with OpenTelemetry Collector that aren't present in your configuration file.
* Metamonitoring metrics exposed by {{< param "PRODUCT_NAME" >}} usually match OpenTelemetry Collector metamonitoring metrics but will use a different name.
Make sure that you use the new metric names, for example, in your alerts and dashboards queries.
* The logs produced by {{< param "PRODUCT_NAME" >}} differ from those produced by OpenTelemetry Collector.
* {{< param "PRODUCT_ROOT_NAME" >}} exposes the {{< param "PRODUCT_NAME" >}} [UI][].

[OpenTelemetry Collector]: https://opentelemetry.io/docs/collector/configuration/
[debugging]: #debugging
[example]: #example

{{% docs/reference %}}
[otelcol.receiver.otlp]: "/docs/agent/ -> /docs/agent/<AGENT_VERSION>/flow/reference/components/otelcol.receiver.otlp.md"
[otelcol.processor.memory_limiter]: "/docs/agent/ -> /docs/agent/<AGENT_VERSION>/flow/reference/components/otelcol.processor.memory_limiter.md"
[otelcol.exporter.otlp]: "/docs/agent/ -> /docs/agent/<AGENT_VERSION>/flow/reference/components/otelcol.exporter.otlp.md"
[Components]: "/docs/agent/ -> /docs/agent/<AGENT_VERSION>/flow/concepts/components.md"
[Components]: "/docs/grafana-cloud/ -> /docs/grafana-cloud/send-data/agent/flow/concepts/components.md"
[Component Reference]: "/docs/agent/ -> /docs/agent/<AGENT_VERSION>/flow/reference/components/_index.md"
[Component Reference]: "/docs/grafana-cloud/ -> /docs/grafana-cloud/send-data/agent/flow/reference/components/_index.md"
[convert]: "/docs/agent/ -> /docs/agent/<AGENT_VERSION>/flow/reference/cli/convert.md"
[convert]: "/docs/grafana-cloud/ -> /docs/grafana-cloud/send-data/agent/flow/reference/cli/convert.md"
[run]: "/docs/agent/ -> /docs/agent/<AGENT_VERSION>/flow/reference/cli/run.md"
[run]: "/docs/grafana-cloud/ -> /docs/grafana-cloud/send-data/agent/flow/reference/cli/run.md"
[Run]: "/docs/agent/ -> /docs/agent/<AGENT_VERSION>/flow/get-started/run/"
[Run]: "/docs/grafana-cloud/ -> /docs/grafana-cloud/send-data/agent/flow/get-started/run/"
[DebuggingUI]: "/docs/agent/ -> /docs/agent/<AGENT_VERSION>/flow/tasks/debug.md"
[DebuggingUI]: "/docs/grafana-cloud/ -> /docs/grafana-cloud/send-data/agent/flow/tasks/debug.md"
[River]: "/docs/agent/ -> /docs/agent/<AGENT_VERSION>/flow/concepts/config-language/_index.md"
[River]: "/docs/grafana-cloud/ -> /docs/grafana-cloud/send-data/agent/flow/concepts/config-language/_index.md"
[UI]: "/docs/agent/ -> /docs/agent/<AGENT_VERSION>/flow/tasks/debug#grafana-agent-flow-ui"
[UI]: "/docs/grafana-cloud/ -> /docs/grafana-cloud/send-data/agent/flow/tasks/debug#grafana-agent-flow-ui"
{{% /docs/reference %}}
Loading

0 comments on commit 88780b8

Please sign in to comment.