-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(converter/otelcol): support converting
sigv4authextension
(#6713)
Signed-off-by: hainenber <[email protected]>
- Loading branch information
Showing
6 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
internal/converter/internal/otelcolconvert/converter_sigv4authextension.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package otelcolconvert | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/grafana/agent/internal/component/otelcol/auth/sigv4" | ||
"github.com/grafana/agent/internal/converter/diag" | ||
"github.com/grafana/agent/internal/converter/internal/common" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/sigv4authextension" | ||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
func init() { | ||
converters = append(converters, sigV4AuthExtensionConverter{}) | ||
} | ||
|
||
type sigV4AuthExtensionConverter struct{} | ||
|
||
func (sigV4AuthExtensionConverter) Factory() component.Factory { | ||
return sigv4authextension.NewFactory() | ||
} | ||
|
||
func (sigV4AuthExtensionConverter) InputComponentName() string { | ||
return "otelcol.auth.sigv4" | ||
} | ||
|
||
func (sigV4AuthExtensionConverter) ConvertAndAppend(state *state, id component.InstanceID, cfg component.Config) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
|
||
label := state.FlowComponentLabel() | ||
|
||
args := toSigV4AuthExtension(cfg.(*sigv4authextension.Config)) | ||
block := common.NewBlockWithOverride([]string{"otelcol", "auth", "sigv4"}, label, args) | ||
|
||
diags.Add( | ||
diag.SeverityLevelInfo, | ||
fmt.Sprintf("Converted %s into %s", stringifyInstanceID(id), stringifyBlock(block)), | ||
) | ||
|
||
state.Body().AppendBlock(block) | ||
|
||
return diags | ||
} | ||
|
||
func toSigV4AuthExtension(cfg *sigv4authextension.Config) *sigv4.Arguments { | ||
return &sigv4.Arguments{ | ||
Region: cfg.Region, | ||
Service: cfg.Service, | ||
AssumeRole: sigv4.AssumeRole{ | ||
ARN: cfg.AssumeRole.ARN, | ||
SessionName: cfg.AssumeRole.SessionName, | ||
STSRegion: cfg.AssumeRole.STSRegion, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...nal/converter/internal/otelcolconvert/testdata/otelcol_without_validation/sigv4auth.river
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
otelcol.auth.sigv4 "default" { | ||
region = "ap-southeast-1" | ||
service = "s3" | ||
|
||
assume_role { | ||
arn = "arn:aws:iam::123456789012:role/aws-service-role/access" | ||
sts_region = "us-east-1" | ||
} | ||
} | ||
|
||
otelcol.receiver.otlp "default" { | ||
grpc { } | ||
|
||
http { } | ||
|
||
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" | ||
auth = otelcol.auth.sigv4.default.handler | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...rnal/converter/internal/otelcolconvert/testdata/otelcol_without_validation/sigv4auth.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
extensions: | ||
sigv4auth: | ||
region: "ap-southeast-1" | ||
service: "s3" | ||
assume_role: | ||
arn: "arn:aws:iam::123456789012:role/aws-service-role/access" | ||
sts_region: "us-east-1" | ||
|
||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
http: | ||
|
||
exporters: | ||
otlp: | ||
auth: | ||
authenticator: sigv4auth | ||
endpoint: database:4317 | ||
|
||
service: | ||
extensions: [sigv4auth] | ||
pipelines: | ||
metrics: | ||
receivers: [otlp] | ||
processors: [] | ||
exporters: [otlp] | ||
logs: | ||
receivers: [otlp] | ||
processors: [] | ||
exporters: [otlp] | ||
traces: | ||
receivers: [otlp] | ||
processors: [] | ||
exporters: [otlp] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters