-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(exporter/otelcol): support converting
vcenterreceiver
(#6714)
* feat(otelcol/exporter): support converting `vcenterreceiver` Signed-off-by: hainenber <[email protected]> * fix(converter/otelcol): add converter to `MetricsBuilderConfig` attribute + use helper for converting TLS setting Signed-off-by: hainenber <[email protected]> --------- Signed-off-by: hainenber <[email protected]> Signed-off-by: erikbaranowski <[email protected]>
- Loading branch information
Showing
3 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
internal/converter/internal/otelcolconvert/converter_vcenterreceiver.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,145 @@ | ||
package otelcolconvert | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/grafana/agent/internal/component/otelcol" | ||
"github.com/grafana/agent/internal/component/otelcol/receiver/vcenter" | ||
"github.com/grafana/agent/internal/converter/diag" | ||
"github.com/grafana/agent/internal/converter/internal/common" | ||
"github.com/grafana/river/rivertypes" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/vcenterreceiver" | ||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
func init() { | ||
converters = append(converters, vcenterReceiverConverter{}) | ||
} | ||
|
||
type vcenterReceiverConverter struct{} | ||
|
||
func (vcenterReceiverConverter) Factory() component.Factory { return vcenterreceiver.NewFactory() } | ||
|
||
func (vcenterReceiverConverter) InputComponentName() string { return "" } | ||
|
||
func (vcenterReceiverConverter) ConvertAndAppend(state *state, id component.InstanceID, cfg component.Config) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
|
||
label := state.FlowComponentLabel() | ||
|
||
args := toVcenterReceiver(state, id, cfg.(*vcenterreceiver.Config)) | ||
block := common.NewBlockWithOverride([]string{"otelcol", "receiver", "vcenter"}, label, args) | ||
|
||
diags.Add( | ||
diag.SeverityLevelInfo, | ||
fmt.Sprintf("Converted %s into %s", stringifyInstanceID(id), stringifyBlock(block)), | ||
) | ||
|
||
state.Body().AppendBlock(block) | ||
return diags | ||
} | ||
|
||
func toVcenterReceiver(state *state, id component.InstanceID, cfg *vcenterreceiver.Config) *vcenter.Arguments { | ||
var ( | ||
nextMetrics = state.Next(id, component.DataTypeMetrics) | ||
nextTraces = state.Next(id, component.DataTypeTraces) | ||
) | ||
|
||
return &vcenter.Arguments{ | ||
Endpoint: cfg.Endpoint, | ||
Username: cfg.Username, | ||
Password: rivertypes.Secret(cfg.Password), | ||
|
||
DebugMetrics: common.DefaultValue[vcenter.Arguments]().DebugMetrics, | ||
|
||
MetricsBuilderConfig: toMetricsBuildConfig(encodeMapstruct(cfg.MetricsBuilderConfig)), | ||
|
||
ScraperControllerArguments: otelcol.ScraperControllerArguments{ | ||
CollectionInterval: cfg.CollectionInterval, | ||
InitialDelay: cfg.InitialDelay, | ||
Timeout: cfg.Timeout, | ||
}, | ||
|
||
TLS: toTLSClientArguments(cfg.TLSClientSetting), | ||
|
||
Output: &otelcol.ConsumerArguments{ | ||
Metrics: toTokenizedConsumers(nextMetrics), | ||
Traces: toTokenizedConsumers(nextTraces), | ||
}, | ||
} | ||
} | ||
|
||
func toMetricsBuildConfig(cfg map[string]any) vcenter.MetricsBuilderConfig { | ||
return vcenter.MetricsBuilderConfig{ | ||
Metrics: toVcenterMetricsConfig(encodeMapstruct(cfg["metrics"])), | ||
ResourceAttributes: toVcenterResourceAttributesConfig(encodeMapstruct(cfg["resource_attributes"])), | ||
} | ||
} | ||
|
||
func toVcenterMetricConfig(cfg map[string]any) vcenter.MetricConfig { | ||
return vcenter.MetricConfig{ | ||
Enabled: cfg["enabled"].(bool), | ||
} | ||
} | ||
|
||
func toVcenterMetricsConfig(cfg map[string]any) vcenter.MetricsConfig { | ||
return vcenter.MetricsConfig{ | ||
VcenterClusterCPUEffective: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.cluster.cpu.effective"])), | ||
VcenterClusterCPULimit: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.cluster.cpu.limit"])), | ||
VcenterClusterHostCount: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.cluster.host.count"])), | ||
VcenterClusterMemoryEffective: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.cluster.memory.effective"])), | ||
VcenterClusterMemoryLimit: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.cluster.memory.limit"])), | ||
VcenterClusterMemoryUsed: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.cluster.memory.used"])), | ||
VcenterClusterVMCount: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.cluster.vm.count"])), | ||
VcenterDatastoreDiskUsage: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.datastore.disk.usage"])), | ||
VcenterDatastoreDiskUtilization: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.datastore.disk.utilization"])), | ||
VcenterHostCPUUsage: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.host.cpu.usage"])), | ||
VcenterHostCPUUtilization: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.host.cpu.utilization"])), | ||
VcenterHostDiskLatencyAvg: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.host.disk.latency.avg"])), | ||
VcenterHostDiskLatencyMax: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.host.disk.latency.max"])), | ||
VcenterHostDiskThroughput: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.host.disk.throughput"])), | ||
VcenterHostMemoryUsage: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.host.memory.usage"])), | ||
VcenterHostMemoryUtilization: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.host.memory.utilization"])), | ||
VcenterHostNetworkPacketCount: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.host.network.packet.count"])), | ||
VcenterHostNetworkPacketErrors: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.host.network.packet.errors"])), | ||
VcenterHostNetworkThroughput: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.host.network.throughput"])), | ||
VcenterHostNetworkUsage: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.host.network.usage"])), | ||
VcenterResourcePoolCPUShares: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.resource_pool.cpu.shares"])), | ||
VcenterResourcePoolCPUUsage: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.resource_pool.cpu.usage"])), | ||
VcenterResourcePoolMemoryShares: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.resource_pool.memory.shares"])), | ||
VcenterResourcePoolMemoryUsage: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.resource_pool.memory.usage"])), | ||
VcenterVMCPUUsage: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.cpu.usage"])), | ||
VcenterVMCPUUtilization: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.cpu.utilization"])), | ||
VcenterVMDiskLatencyAvg: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.disk.latency.avg"])), | ||
VcenterVMDiskLatencyMax: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.disk.latency.max"])), | ||
VcenterVMDiskThroughput: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.disk.throughput"])), | ||
VcenterVMDiskUsage: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.disk.usage"])), | ||
VcenterVMDiskUtilization: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.disk.utilization"])), | ||
VcenterVMMemoryBallooned: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.memory.ballooned"])), | ||
VcenterVMMemorySwapped: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.memory.swapped"])), | ||
VcenterVMMemorySwappedSsd: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.memory.swapped_ssd"])), | ||
VcenterVMMemoryUsage: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.memory.usage"])), | ||
VcenterVMMemoryUtilization: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.memory.utilization"])), | ||
VcenterVMNetworkPacketCount: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.network.packet.count"])), | ||
VcenterVMNetworkThroughput: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.network.throughput"])), | ||
VcenterVMNetworkUsage: toVcenterMetricConfig(encodeMapstruct(cfg["vcenter.vm.network.usage"])), | ||
} | ||
} | ||
|
||
func toVcenterResourceAttributesConfig(cfg map[string]any) vcenter.ResourceAttributesConfig { | ||
return vcenter.ResourceAttributesConfig{ | ||
VcenterClusterName: toVcenterResourceAttributeConfig(encodeMapstruct(cfg["vcenter.cluster.name"])), | ||
VcenterDatastoreName: toVcenterResourceAttributeConfig(encodeMapstruct(cfg["vcenter.datastore.name"])), | ||
VcenterHostName: toVcenterResourceAttributeConfig(encodeMapstruct(cfg["vcenter.host.name"])), | ||
VcenterResourcePoolInventoryPath: toVcenterResourceAttributeConfig(encodeMapstruct(cfg["vcenter.resource_pool.inventory_path"])), | ||
VcenterResourcePoolName: toVcenterResourceAttributeConfig(encodeMapstruct(cfg["vcenter.resource_pool.name"])), | ||
VcenterVMID: toVcenterResourceAttributeConfig(encodeMapstruct(cfg["vcenter.vm.id"])), | ||
VcenterVMName: toVcenterResourceAttributeConfig(encodeMapstruct(cfg["vcenter.vm.name"])), | ||
} | ||
} | ||
|
||
func toVcenterResourceAttributeConfig(cfg map[string]any) vcenter.ResourceAttributeConfig { | ||
return vcenter.ResourceAttributeConfig{ | ||
Enabled: cfg["enabled"].(bool), | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
internal/converter/internal/otelcolconvert/testdata/vcenterreceiver.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.receiver.vcenter "default" { | ||
endpoint = "http://localhost:15672" | ||
username = "otelu" | ||
password = "abc" | ||
|
||
metrics { | ||
vcenter.host.cpu.utilization { | ||
enabled = false | ||
} | ||
} | ||
|
||
resource_attributes { | ||
vcenter.cluster.name { | ||
enabled = false | ||
} | ||
} | ||
|
||
output { | ||
metrics = [] | ||
traces = [otelcol.exporter.otlp.default.input] | ||
} | ||
} | ||
|
||
otelcol.exporter.otlp "default" { | ||
client { | ||
endpoint = "database:4317" | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
internal/converter/internal/otelcolconvert/testdata/vcenterreceiver.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,24 @@ | ||
receivers: | ||
vcenter: | ||
endpoint: http://localhost:15672 | ||
username: otelu | ||
password: "abc" | ||
collection_interval: 1m | ||
initial_delay: 1s | ||
metrics: | ||
vcenter.host.cpu.utilization: | ||
enabled: false | ||
resource_attributes: | ||
vcenter.cluster.name: | ||
enabled: false | ||
|
||
exporters: | ||
otlp: | ||
endpoint: database:4317 | ||
|
||
service: | ||
pipelines: | ||
traces: | ||
receivers: [vcenter] | ||
processors: [] | ||
exporters: [otlp] |