Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry picks for v0.37.2 #5484

Merged
merged 6 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 63 additions & 63 deletions .drone/drone.yml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion cmd/grafana-agent-operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# default when running `docker buildx build` or when DOCKER_BUILDKIT=1 is set
# in environment variables.

FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.2 as build
FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.3 as build
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETOS
Expand All @@ -30,6 +30,7 @@ LABEL org.opencontainers.image.source="https://github.com/grafana/agent"
RUN <<EOF
apt-get update
apt-get install -qy libsystemd-dev tzdata ca-certificates
apt-get upgrade -y
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EOF

Expand Down
4 changes: 2 additions & 2 deletions cmd/grafana-agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# default when running `docker buildx build` or when DOCKER_BUILDKIT=1 is set
# in environment variables.

FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.2 as build
FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.3 as build
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETOS
Expand Down Expand Up @@ -38,7 +38,7 @@ LABEL org.opencontainers.image.source="https://github.com/grafana/agent"
RUN <<EOF
apt-get update
apt-get install -qy libsystemd-dev tzdata ca-certificates

apt-get upgrade -y
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EOF

Expand Down
2 changes: 1 addition & 1 deletion cmd/grafana-agent/Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM grafana/agent-build-image:0.30.2-windows as builder
FROM grafana/agent-build-image:0.30.3-windows as builder
ARG VERSION
ARG RELEASE_BUILD=1

Expand Down
4 changes: 2 additions & 2 deletions cmd/grafana-agentctl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# default when running `docker buildx build` or when DOCKER_BUILDKIT=1 is set
# in environment variables.

FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.2 as build
FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.3 as build
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETOS
Expand All @@ -31,7 +31,7 @@ LABEL org.opencontainers.image.source="https://github.com/grafana/agent"
RUN <<EOF
apt-get update
apt-get install -qy libsystemd-dev tzdata ca-certificates

apt-get upgrade -y
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EOF

Expand Down
2 changes: 1 addition & 1 deletion cmd/grafana-agentctl/Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM grafana/agent-build-image:0.30.2-windows as builder
FROM grafana/agent-build-image:0.30.3-windows as builder
ARG VERSION
ARG RELEASE_BUILD=1

Expand Down
18 changes: 18 additions & 0 deletions cmd/internal/flowmode/cluster_builder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package flowmode

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestBuildClusterService(t *testing.T) {
opts := clusterOptions{
JoinPeers: []string{"foo", "bar"},
DiscoverPeers: "provider=aws key1=val1 key2=val2",
}

cs, err := buildClusterService(opts)
require.Nil(t, cs)
require.EqualError(t, err, "at most one of join peers and discover peers may be set")
}
9 changes: 8 additions & 1 deletion cmd/internal/flowmode/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (fr *flowRun) Run(configPath string) error {
NodeName: fr.clusterNodeName,
AdvertiseAddress: fr.clusterAdvAddr,
ListenAddress: fr.httpListenAddr,
JoinPeers: strings.Split(fr.clusterJoinAddr, ","),
JoinPeers: splitPeers(fr.clusterJoinAddr, ","),
DiscoverPeers: fr.clusterDiscoverPeers,
RejoinInterval: fr.clusterRejoinInterval,
AdvertiseInterfaces: fr.clusterAdvInterfaces,
Expand Down Expand Up @@ -430,3 +430,10 @@ func interruptContext() (context.Context, context.CancelFunc) {

return ctx, cancel
}

func splitPeers(s, sep string) []string {
if len(s) == 0 {
return []string{}
}
return strings.Split(s, sep)
}
7 changes: 4 additions & 3 deletions component/prometheus/exporter/blackbox/blackbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/grafana/agent/component/prometheus/exporter"
"github.com/grafana/agent/pkg/integrations"
"github.com/grafana/agent/pkg/integrations/blackbox_exporter"
"github.com/grafana/agent/pkg/util"
"github.com/grafana/river/rivertypes"
)

Expand Down Expand Up @@ -92,7 +93,6 @@ type Arguments struct {
Config rivertypes.OptionalSecret `river:"config,attr,optional"`
Targets TargetBlock `river:"target,block"`
ProbeTimeoutOffset time.Duration `river:"probe_timeout_offset,attr,optional"`
ConfigStruct blackbox_config.Config
}

// SetToDefault implements river.Defaulter.
Expand All @@ -106,7 +106,8 @@ func (a *Arguments) Validate() error {
return errors.New("config and config_file are mutually exclusive")
}

err := yaml.UnmarshalStrict([]byte(a.Config.Value), &a.ConfigStruct)
var blackboxConfig blackbox_config.Config
err := yaml.UnmarshalStrict([]byte(a.Config.Value), &blackboxConfig)
if err != nil {
return fmt.Errorf("invalid backbox_exporter config: %s", err)
}
Expand All @@ -118,7 +119,7 @@ func (a *Arguments) Validate() error {
func (a *Arguments) Convert() *blackbox_exporter.Config {
return &blackbox_exporter.Config{
BlackboxConfigFile: a.ConfigFile,
BlackboxConfig: a.ConfigStruct,
BlackboxConfig: util.RawYAML(a.Config.Value),
BlackboxTargets: a.Targets.Convert(),
ProbeTimeoutOffset: a.ProbeTimeoutOffset.Seconds(),
}
Expand Down
43 changes: 41 additions & 2 deletions component/prometheus/exporter/blackbox/blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/discovery"
"github.com/grafana/river"
blackbox_config "github.com/prometheus/blackbox_exporter/config"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
)

func TestUnmarshalRiver(t *testing.T) {
Expand Down Expand Up @@ -56,8 +58,11 @@ func TestUnmarshalRiverWithInlineConfig(t *testing.T) {
err := river.Unmarshal([]byte(riverCfg), &args)
require.NoError(t, err)
require.Equal(t, "", args.ConfigFile)
require.Equal(t, args.ConfigStruct.Modules["http_2xx"].Prober, "http")
require.Equal(t, args.ConfigStruct.Modules["http_2xx"].Timeout, 5*time.Second)
var blackboxConfig blackbox_config.Config
err = yaml.UnmarshalStrict([]byte(args.Config.Value), &blackboxConfig)
require.NoError(t, err)
require.Equal(t, blackboxConfig.Modules["http_2xx"].Prober, "http")
require.Equal(t, blackboxConfig.Modules["http_2xx"].Timeout, 5*time.Second)
require.Equal(t, 2, len(args.Targets))
require.Equal(t, 500*time.Millisecond, args.ProbeTimeoutOffset)
require.Contains(t, "target_a", args.Targets[0].Name)
Expand All @@ -67,6 +72,40 @@ func TestUnmarshalRiverWithInlineConfig(t *testing.T) {
require.Contains(t, "http://grafana.com", args.Targets[1].Target)
require.Contains(t, "http_2xx", args.Targets[1].Module)
}

func TestUnmarshalRiverWithInlineConfigYaml(t *testing.T) {
riverCfg := `
config = "modules:\n http_2xx:\n prober: http\n timeout: 5s\n"

target "target_a" {
address = "http://example.com"
module = "http_2xx"
}
target "target_b" {
address = "http://grafana.com"
module = "http_2xx"
}
probe_timeout_offset = "0.5s"
`
var args Arguments
err := river.Unmarshal([]byte(riverCfg), &args)
require.NoError(t, err)
require.Equal(t, "", args.ConfigFile)
var blackboxConfig blackbox_config.Config
err = yaml.UnmarshalStrict([]byte(args.Config.Value), &blackboxConfig)
require.NoError(t, err)
require.Equal(t, blackboxConfig.Modules["http_2xx"].Prober, "http")
require.Equal(t, blackboxConfig.Modules["http_2xx"].Timeout, 5*time.Second)
require.Equal(t, 2, len(args.Targets))
require.Equal(t, 500*time.Millisecond, args.ProbeTimeoutOffset)
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, "http://grafana.com", args.Targets[1].Target)
require.Contains(t, "http_2xx", args.Targets[1].Module)
}

func TestUnmarshalRiverWithInvalidInlineConfig(t *testing.T) {
var tests = []struct {
testname string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ func (b *IntegrationsV1ConfigBuilder) appendBlackboxExporter(config *blackbox_ex

func toBlackboxExporter(config *blackbox_exporter.Config) *blackbox.Arguments {
return &blackbox.Arguments{
ConfigFile: config.BlackboxConfigFile,
Config: rivertypes.OptionalSecret{},
ConfigFile: config.BlackboxConfigFile,
Config: rivertypes.OptionalSecret{
IsSecret: false,
Value: string(config.BlackboxConfig),
},
Targets: toBlackboxTargets(config.BlackboxTargets),
ProbeTimeoutOffset: time.Duration(config.ProbeTimeoutOffset),
ConfigStruct: config.BlackboxConfig,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ prometheus.remote_write "integrations" {
}

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" {
address = "http://example.com"
module = "http_2xx"
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,8 @@ replace (
// * There is a release of Prometheus which contains
// prometheus/prometheus#12677 and prometheus/prometheus#12729.
// We use the last v1-related tag as the replace statement does not work for v2
// tags without the v2 suffix to the module root
replace github.com/prometheus/prometheus => github.com/grafana/prometheus v1.8.2-0.20231003113207-17e15326a784 // grafana:prometheus:v0.46.0-retry-improvements
// tags without the v2 suffix to the module root.
replace github.com/prometheus/prometheus => github.com/grafana/prometheus v1.8.2-0.20231016083943-46550094220d // grafana:prometheus:v0.47.2-retry-improvements

replace gopkg.in/yaml.v2 => github.com/rfratto/go-yaml v0.0.0-20211119180816-77389c3526dc

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,8 @@ github.com/grafana/perflib_exporter v0.1.1-0.20230511173423-6166026bd090 h1:Ko80
github.com/grafana/perflib_exporter v0.1.1-0.20230511173423-6166026bd090/go.mod h1:MinSWm88jguXFFrGsP56PtleUb4Qtm4tNRH/wXNXRTI=
github.com/grafana/postgres_exporter v0.8.1-0.20210722175051-db35d7c2f520 h1:HnFWqxhoSF3WC7sKAdMZ+SRXvHLVZlZ3sbQjuUlTqkw=
github.com/grafana/postgres_exporter v0.8.1-0.20210722175051-db35d7c2f520/go.mod h1:+HPXgiOV0InDHcZ2jNijL1SOKvo0eEPege5fQA0+ICI=
github.com/grafana/prometheus v1.8.2-0.20231003113207-17e15326a784 h1:B8AAFKq7WQPUYdoGwWjgxFARn5XodYlKJNHCYUopah8=
github.com/grafana/prometheus v1.8.2-0.20231003113207-17e15326a784/go.mod h1:10L5IJE5CEsjee1FnOcVswYXlPIscDWWt3IJ2UDYrz4=
github.com/grafana/prometheus v1.8.2-0.20231016083943-46550094220d h1:hr0QEXSfpdakWdHw2sZeT/5GnGwIkHnNO0YBkfRj5zk=
github.com/grafana/prometheus v1.8.2-0.20231016083943-46550094220d/go.mod h1:J/bmOSjgH7lFxz2gZhrWEZs2i64vMS+HIuZfmYNhJ/M=
github.com/grafana/pyroscope-go/godeltaprof v0.1.3 h1:eunWpv1B3Z7ZK9o4499EmQGlY+CsDmSZ4FbxjRx37uk=
github.com/grafana/pyroscope-go/godeltaprof v0.1.3/go.mod h1:1HSPtjU8vLG0jE9JrTdzjgFqdJ/VgN7fvxBNq3luJko=
github.com/grafana/pyroscope/api v0.2.0 h1:TzOxL0s6SiaLEy944ZAKgHcx/JDRJXu4O8ObwkqR6p4=
Expand Down
26 changes: 20 additions & 6 deletions pkg/integrations/blackbox_exporter/blackbox_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
"github.com/go-kit/log"
"github.com/grafana/agent/pkg/integrations"
"github.com/grafana/agent/pkg/integrations/config"
"github.com/grafana/agent/pkg/util"
blackbox_config "github.com/prometheus/blackbox_exporter/config"
"github.com/prometheus/blackbox_exporter/prober"
"github.com/prometheus/client_golang/prometheus"
"gopkg.in/yaml.v3"
)

// DefaultConfig holds the default settings for the blackbox_exporter integration.
Expand Down Expand Up @@ -39,18 +41,24 @@ type BlackboxTarget struct {

// Config configures the Blackbox integration.
type Config struct {
BlackboxConfigFile string `yaml:"config_file,omitempty"`
BlackboxTargets []BlackboxTarget `yaml:"blackbox_targets"`
BlackboxConfig blackbox_config.Config `yaml:"blackbox_config,omitempty"`
ProbeTimeoutOffset float64 `yaml:"probe_timeout_offset,omitempty"`
BlackboxConfigFile string `yaml:"config_file,omitempty"`
BlackboxTargets []BlackboxTarget `yaml:"blackbox_targets"`
BlackboxConfig util.RawYAML `yaml:"blackbox_config,omitempty"`
ProbeTimeoutOffset float64 `yaml:"probe_timeout_offset,omitempty"`
}

// UnmarshalYAML implements yaml.Unmarshaler for Config.
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultConfig

type plain Config
return unmarshal((*plain)(c))
err := unmarshal((*plain)(c))
if err != nil {
return err
}

var blackbox_config blackbox_config.Config
return yaml.Unmarshal(c.BlackboxConfig, &blackbox_config)
}

// Name returns the name of the integration.
Expand Down Expand Up @@ -96,7 +104,13 @@ func LoadBlackboxConfig(log log.Logger, configFile string, targets []BlackboxTar

// New creates a new blackbox_exporter integration
func New(log log.Logger, c *Config) (integrations.Integration, error) {
modules, err := LoadBlackboxConfig(log, c.BlackboxConfigFile, c.BlackboxTargets, &c.BlackboxConfig)
var blackbox_config blackbox_config.Config
err := yaml.Unmarshal(c.BlackboxConfig, &blackbox_config)
if err != nil {
return nil, err
}

modules, err := LoadBlackboxConfig(log, c.BlackboxConfigFile, c.BlackboxTargets, &blackbox_config)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion tools/crow/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# default when running `docker buildx build` or when DOCKER_BUILDKIT=1 is set
# in environment variables.

FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.2 as build
FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.3 as build
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETOS
Expand Down
2 changes: 1 addition & 1 deletion tools/make/build-container.mk
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# variable names should be passed through to the container.

USE_CONTAINER ?= 0
BUILD_IMAGE_VERSION ?= 0.30.2
BUILD_IMAGE_VERSION ?= 0.30.3
BUILD_IMAGE ?= grafana/agent-build-image:$(BUILD_IMAGE_VERSION)
DOCKER_OPTS ?= -it

Expand Down
2 changes: 1 addition & 1 deletion tools/smoke/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# default when running `docker buildx build` or when DOCKER_BUILDKIT=1 is set
# in environment variables.

FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.2 as build
FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.3 as build
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETOS
Expand Down