Skip to content

Commit

Permalink
Merge branch 'main' into docs/update-topics-concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
clayton-cornell authored Dec 12, 2023
2 parents e45d9cf + 8c0f6de commit 57c187b
Show file tree
Hide file tree
Showing 17 changed files with 355 additions and 26 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ internal API changes are not present.
Main (unreleased)
-----------------

### Breaking changes

- The `target` block in `prometheus.exporter.blackbox` requires a mandatory `name`
argument instead of a block label. (@hainenber)

### Enhancements

- Flow Windows service: Support environment variables. (@jkroepke)
Expand Down
2 changes: 1 addition & 1 deletion component/prometheus/exporter/blackbox/blackbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var DefaultArguments = Arguments{

// BlackboxTarget defines a target to be used by the exporter.
type BlackboxTarget struct {
Name string `river:",label"`
Name string `river:"name,attr"`
Target string `river:"address,attr"`
Module string `river:"module,attr,optional"`
Labels map[string]string `river:"labels,attr,optional"`
Expand Down
46 changes: 33 additions & 13 deletions component/prometheus/exporter/blackbox/blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import (
func TestUnmarshalRiver(t *testing.T) {
riverCfg := `
config_file = "modules.yml"
target "target_a" {
target {
name = "target_a"
address = "http://example.com"
module = "http_2xx"
}
target "target_b" {
target {
name = "target-b"
address = "http://grafana.com"
module = "http_2xx"
}
Expand All @@ -35,7 +37,7 @@ func TestUnmarshalRiver(t *testing.T) {
require.Contains(t, "target_a", args.Targets[0].Name)
require.Contains(t, "http://example.com", args.Targets[0].Target)
require.Contains(t, "http_2xx", args.Targets[0].Module)
require.Contains(t, "target_b", args.Targets[1].Name)
require.Contains(t, "target-b", args.Targets[1].Name)
require.Contains(t, "http://grafana.com", args.Targets[1].Target)
require.Contains(t, "http_2xx", args.Targets[1].Module)
}
Expand All @@ -44,11 +46,13 @@ func TestUnmarshalRiverWithInlineConfig(t *testing.T) {
riverCfg := `
config = "{ modules: { http_2xx: { prober: http, timeout: 5s } } }"
target "target_a" {
target {
name = "target_a"
address = "http://example.com"
module = "http_2xx"
}
target "target_b" {
target {
name = "target-b"
address = "http://grafana.com"
module = "http_2xx"
}
Expand All @@ -68,7 +72,7 @@ func TestUnmarshalRiverWithInlineConfig(t *testing.T) {
require.Contains(t, "target_a", args.Targets[0].Name)
require.Contains(t, "http://example.com", args.Targets[0].Target)
require.Contains(t, "http_2xx", args.Targets[0].Module)
require.Contains(t, "target_b", args.Targets[1].Name)
require.Contains(t, "target-b", args.Targets[1].Name)
require.Contains(t, "http://grafana.com", args.Targets[1].Target)
require.Contains(t, "http_2xx", args.Targets[1].Module)
}
Expand All @@ -77,11 +81,13 @@ func TestUnmarshalRiverWithInlineConfigYaml(t *testing.T) {
riverCfg := `
config = "modules:\n http_2xx:\n prober: http\n timeout: 5s\n"
target "target_a" {
target {
name = "target_a"
address = "http://example.com"
module = "http_2xx"
}
target "target_b" {
target {
name = "target-b"
address = "http://grafana.com"
module = "http_2xx"
}
Expand All @@ -101,7 +107,7 @@ func TestUnmarshalRiverWithInlineConfigYaml(t *testing.T) {
require.Contains(t, "target_a", args.Targets[0].Name)
require.Contains(t, "http://example.com", args.Targets[0].Target)
require.Contains(t, "http_2xx", args.Targets[0].Module)
require.Contains(t, "target_b", args.Targets[1].Name)
require.Contains(t, "target-b", args.Targets[1].Name)
require.Contains(t, "http://grafana.com", args.Targets[1].Target)
require.Contains(t, "http_2xx", args.Targets[1].Module)
}
Expand All @@ -117,7 +123,8 @@ func TestUnmarshalRiverWithInvalidConfig(t *testing.T) {
`
config = "{ modules: { http_2xx: { prober: http, timeout: 5s }"
target "target_a" {
target {
name = "target_a"
address = "http://example.com"
module = "http_2xx"
}
Expand All @@ -129,7 +136,8 @@ func TestUnmarshalRiverWithInvalidConfig(t *testing.T) {
`
config = "{ module: { http_2xx: { prober: http, timeout: 5s } } }"
target "target_a" {
target {
name = "target_a"
address = "http://example.com"
module = "http_2xx"
}
Expand All @@ -142,7 +150,8 @@ func TestUnmarshalRiverWithInvalidConfig(t *testing.T) {
config_file = "config"
config = "{ modules: { http_2xx: { prober: http, timeout: 5s } } }"
target "target_a" {
target {
name = "target-a"
address = "http://example.com"
module = "http_2xx"
}
Expand All @@ -152,13 +161,24 @@ func TestUnmarshalRiverWithInvalidConfig(t *testing.T) {
{
"Define neither config nor config_file",
`
target "target_a" {
target {
name = "target-a"
address = "http://example.com"
module = "http_2xx"
}
`,
`config or config_file must be set`,
},
{
"Specify label for target block instead of name attribute",
`
target "target_a" {
address = "http://example.com"
module = "http_2xx"
}
`,
`2:4: block "target" does not support specifying labels`,
},
}
for _, tt := range tests {
t.Run(tt.testname, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package build

import (
"fmt"

"github.com/alecthomas/units"
"github.com/grafana/agent/component/common/loki"
"github.com/grafana/agent/component/faro/receiver"
"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/converter/diag"
"github.com/grafana/agent/converter/internal/common"
app_agent_receiver_v2 "github.com/grafana/agent/pkg/integrations/v2/app_agent_receiver"
"github.com/grafana/river/rivertypes"
"github.com/grafana/river/scanner"
)

func (b *IntegrationsConfigBuilder) appendAppAgentReceiverV2(config *app_agent_receiver_v2.Config) {
args := toAppAgentReceiverV2(config)

compLabel, err := scanner.SanitizeIdentifier(b.formatJobName(config.Name(), nil))
if err != nil {
b.diags.Add(diag.SeverityLevelCritical, fmt.Sprintf("failed to sanitize job name: %s", err))
}

b.f.Body().AppendBlock(common.NewBlockWithOverride(
[]string{"faro", "receiver"},
compLabel,
args,
))
}

func toAppAgentReceiverV2(config *app_agent_receiver_v2.Config) *receiver.Arguments {
var logLabels map[string]string
if config.LogsLabels != nil {
logLabels = config.LogsLabels
}

logsReceiver := common.ConvertLogsReceiver{}
if config.LogsInstance != "" {
compLabel, err := scanner.SanitizeIdentifier("logs_" + config.LogsInstance)
if err != nil {
panic(fmt.Errorf("failed to sanitize job name: %s", err))
}

logsReceiver.Expr = fmt.Sprintf("loki.write.%s.receiver", compLabel)
}

return &receiver.Arguments{
LogLabels: logLabels,
Server: receiver.ServerArguments{
Host: config.Server.Host,
Port: config.Server.Port,
CORSAllowedOrigins: config.Server.CORSAllowedOrigins,
APIKey: rivertypes.Secret(config.Server.APIKey),
MaxAllowedPayloadSize: units.Base2Bytes(config.Server.MaxAllowedPayloadSize),
RateLimiting: receiver.RateLimitingArguments{
Enabled: config.Server.RateLimiting.Enabled,
Rate: config.Server.RateLimiting.RPS,
BurstSize: float64(config.Server.RateLimiting.Burstiness),
},
},
SourceMaps: receiver.SourceMapsArguments{
Download: config.SourceMaps.Download,
DownloadFromOrigins: config.SourceMaps.DownloadFromOrigins,
DownloadTimeout: config.SourceMaps.DownloadTimeout,
Locations: toLocationArguments(config.SourceMaps.FileSystem),
},
Output: receiver.OutputArguments{
Logs: []loki.LogsReceiver{logsReceiver},
Traces: []otelcol.Consumer{},
},
}
}

func toLocationArguments(locations []app_agent_receiver_v2.SourceMapFileLocation) []receiver.LocationArguments {
args := make([]receiver.LocationArguments, len(locations))
for i, location := range locations {
args[i] = receiver.LocationArguments{
Path: location.Path,
MinifiedPathPrefix: location.MinifiedPathPrefix,
}
}
return args
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/grafana/agent/component/discovery"
"github.com/grafana/agent/component/prometheus/exporter/blackbox"
"github.com/grafana/agent/converter/internal/common"
"github.com/grafana/agent/pkg/integrations/blackbox_exporter"
blackbox_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/blackbox_exporter"
"github.com/grafana/river/rivertypes"
Expand Down Expand Up @@ -57,7 +56,7 @@ func toBlackboxTargets(blackboxTargets []blackbox_exporter.BlackboxTarget) black

func toBlackboxTarget(target blackbox_exporter.BlackboxTarget) blackbox.BlackboxTarget {
return blackbox.BlackboxTarget{
Name: common.SanitizeIdentifierPanics(target.Name),
Name: target.Name,
Target: target.Target,
Module: target.Module,
}
Expand Down
8 changes: 8 additions & 0 deletions converter/internal/staticconvert/internal/build/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ import (
"github.com/grafana/agent/pkg/integrations/statsd_exporter"
agent_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/agent"
apache_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/apache_http"
app_agent_receiver_v2 "github.com/grafana/agent/pkg/integrations/v2/app_agent_receiver"
blackbox_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/blackbox_exporter"
common_v2 "github.com/grafana/agent/pkg/integrations/v2/common"
"github.com/grafana/agent/pkg/integrations/v2/metricsutils"
snmp_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/snmp_exporter"
vmware_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/vmware_exporter"
"github.com/grafana/agent/pkg/integrations/windows_exporter"
"github.com/grafana/river/scanner"
"github.com/grafana/river/token/builder"
Expand Down Expand Up @@ -217,12 +219,18 @@ func (b *IntegrationsConfigBuilder) appendV2Integrations() {
case *apache_exporter_v2.Config:
exports = b.appendApacheExporterV2(itg)
commonConfig = itg.Common
case *app_agent_receiver_v2.Config:
b.appendAppAgentReceiverV2(itg)
commonConfig = itg.Common
case *blackbox_exporter_v2.Config:
exports = b.appendBlackboxExporterV2(itg)
commonConfig = itg.Common
case *snmp_exporter_v2.Config:
exports = b.appendSnmpExporterV2(itg)
commonConfig = itg.Common
case *vmware_exporter_v2.Config:
exports = b.appendVmwareExporterV2(itg)
commonConfig = itg.Common
case *metricsutils.ConfigShim:
commonConfig = itg.Common
switch v1_itg := itg.Orig.(type) {
Expand Down
25 changes: 25 additions & 0 deletions converter/internal/staticconvert/internal/build/vmware_exporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package build

import (
"github.com/grafana/agent/component/discovery"
"github.com/grafana/agent/component/prometheus/exporter/vsphere"
vmware_exporter_v2 "github.com/grafana/agent/pkg/integrations/v2/vmware_exporter"
"github.com/grafana/river/rivertypes"
)

func (b *IntegrationsConfigBuilder) appendVmwareExporterV2(config *vmware_exporter_v2.Config) discovery.Exports {
args := toVmwareExporter(config)
return b.appendExporterBlock(args, config.Name(), nil, "vsphere")
}

func toVmwareExporter(config *vmware_exporter_v2.Config) *vsphere.Arguments {
return &vsphere.Arguments{
ChunkSize: config.ChunkSize,
CollectConcurrency: config.CollectConcurrency,
VSphereURL: config.VSphereURL,
VSphereUser: config.VSphereUser,
VSpherePass: rivertypes.Secret(config.VSpherePass),
ObjectDiscoveryInterval: config.ObjectDiscoveryInterval,
EnableExporterMetrics: config.EnableExporterMetrics,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ prometheus.remote_write "metrics_default" {
}
}

loki.write "logs_log_config" {
endpoint {
url = "http://localhost/loki/api/v1/push"
}
external_labels = {}
}

prometheus.exporter.azure "integrations_azure1" {
subscriptions = ["subId"]
resource_type = "Microsoft.Dashboard/grafana"
Expand Down Expand Up @@ -471,10 +478,37 @@ prometheus.scrape "integrations_apache2" {
job_name = "integrations/apache2"
}

faro.receiver "integrations_app_agent_receiver" {
extra_log_labels = {}

server {
listen_address = "localhost"
listen_port = 55678
max_allowed_payload_size = "4MiB786KiB832B"

rate_limiting {
enabled = true
rate = 100
burst_size = 50
}
}

sourcemaps {
download_from_origins = ["*"]
download_timeout = "1s"
}

output {
logs = [loki.write.logs_log_config.receiver]
traces = []
}
}

prometheus.exporter.blackbox "integrations_blackbox" {
config = "modules:\n http_2xx:\n prober: http\n timeout: 5s\n http:\n method: POST\n headers:\n Content-Type: application/json\n body: '{}'\n preferred_ip_protocol: ip4\n"

target "example" {
target {
name = "example"
address = "http://example.com"
module = "http_2xx"
}
Expand Down Expand Up @@ -508,3 +542,24 @@ prometheus.scrape "integrations_snmp" {
forward_to = [prometheus.remote_write.metrics_default.receiver]
job_name = "integrations/snmp"
}

prometheus.exporter.vsphere "integrations_vsphere" {
vsphere_url = "https://127.0.0.1:8989/sdk"
vsphere_user = "user"
vsphere_password = "pass"
}

discovery.relabel "integrations_vsphere" {
targets = prometheus.exporter.vsphere.integrations_vsphere.targets

rule {
target_label = "instance"
replacement = "vsphere"
}
}

prometheus.scrape "integrations_vsphere" {
targets = discovery.relabel.integrations_vsphere.output
forward_to = [prometheus.remote_write.metrics_default.receiver]
job_name = "integrations/vsphere"
}
Loading

0 comments on commit 57c187b

Please sign in to comment.