Skip to content

Commit

Permalink
Merge branch 'main' into am-template-vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jcreixell authored Nov 15, 2023
2 parents 6743664 + ea7b005 commit 684e920
Show file tree
Hide file tree
Showing 55 changed files with 326 additions and 107 deletions.
128 changes: 64 additions & 64 deletions .drone/drone.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.21.0"
go-version: "1.21"
- name: Set OTEL Exporter Endpoint
run: echo "OTEL_EXPORTER_ENDPOINT=http://172.17.0.1:8080" >> $GITHUB_ENV
- name: Run tests
run: make integration-test
run: make integration-test
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ Main (unreleased)

- Use Go 1.21.4 for builds. (@rfratto)

- Change User-Agent header for outbound requests to include agent-mode, goos, and deployment mode. Example `GrafanaAgent/v0.38.0 (flow; linux; docker)` (@captncraig)

v0.37.4 (2023-11-06)
-----------------

Expand Down
2 changes: 1 addition & 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.3 as build
FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.4 as build
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETOS
Expand Down
3 changes: 2 additions & 1 deletion 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.3 as build
FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.4 as build
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETOS
Expand Down Expand Up @@ -47,4 +47,5 @@ COPY cmd/grafana-agent/agent-local-config.yaml /etc/agent/agent.yaml


ENTRYPOINT ["/bin/grafana-agent"]
ENV AGENT_DEPLOY_MODE=docker
CMD ["--config.file=/etc/agent/agent.yaml", "--metrics.wal-directory=/etc/agent/data"]
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.3-windows as builder
FROM grafana/agent-build-image:0.30.4-windows as builder
ARG VERSION
ARG RELEASE_BUILD=1

Expand Down
2 changes: 1 addition & 1 deletion 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.3 as build
FROM --platform=$BUILDPLATFORM grafana/agent-build-image:0.30.4 as build
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETOS
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.3-windows as builder
FROM grafana/agent-build-image:0.30.4-windows as builder
ARG VERSION
ARG RELEASE_BUILD=1

Expand Down
4 changes: 2 additions & 2 deletions component/common/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/go-kit/log"
commoncfg "github.com/grafana/agent/component/common/config"
"github.com/grafana/agent/pkg/build"
"github.com/grafana/agent/internal/useragent"
"github.com/grafana/agent/pkg/flow/logging/level"
promconfig "github.com/prometheus/common/config"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -79,7 +79,7 @@ func (args *ClientArguments) BuildRESTConfig(l log.Logger) (*rest.Config, error)
}
}

cfg.UserAgent = fmt.Sprintf("GrafanaAgent/%s", build.Version)
cfg.UserAgent = useragent.Get()
cfg.ContentType = "application/vnd.kubernetes.protobuf"

return cfg, nil
Expand Down
6 changes: 3 additions & 3 deletions component/common/loki/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
"time"

"github.com/go-kit/log"
"github.com/grafana/agent/internal/useragent"
"github.com/grafana/agent/pkg/flow/logging/level"
"github.com/grafana/dskit/backoff"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/config"
"github.com/prometheus/common/model"

"github.com/grafana/agent/component/common/loki"
"github.com/grafana/agent/pkg/build"
"github.com/grafana/agent/pkg/util"
lokiutil "github.com/grafana/loki/pkg/util"
)
Expand All @@ -47,7 +47,7 @@ const (

var Reasons = []string{ReasonGeneric, ReasonRateLimited, ReasonStreamLimited, ReasonLineTooLong}

var UserAgent = fmt.Sprintf("GrafanaAgent/%s", build.Version)
var userAgent = useragent.Get()

type Metrics struct {
encodedBytes *prometheus.CounterVec
Expand Down Expand Up @@ -419,7 +419,7 @@ func (c *client) send(ctx context.Context, tenantID string, buf []byte) (int, er
}
req = req.WithContext(ctx)
req.Header.Set("Content-Type", contentType)
req.Header.Set("User-Agent", UserAgent)
req.Header.Set("User-Agent", userAgent)

// If the tenant ID is not empty promtail is running in multi-tenant mode, so
// we should send it to Loki
Expand Down
2 changes: 1 addition & 1 deletion component/common/loki/client/queue_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func (c *queueClient) send(ctx context.Context, tenantID string, buf []byte) (in
}
req = req.WithContext(ctx)
req.Header.Set("Content-Type", contentType)
req.Header.Set("User-Agent", UserAgent)
req.Header.Set("User-Agent", userAgent)

// If the tenant ID is not empty promtail is running in multi-tenant mode, so
// we should send it to Loki
Expand Down
4 changes: 2 additions & 2 deletions component/loki/source/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
flow_relabel "github.com/grafana/agent/component/common/relabel"
"github.com/grafana/agent/component/discovery"
dt "github.com/grafana/agent/component/loki/source/docker/internal/dockertarget"
"github.com/grafana/agent/pkg/build"
"github.com/grafana/agent/internal/useragent"
"github.com/grafana/agent/pkg/flow/logging/level"
"github.com/prometheus/common/config"
"github.com/prometheus/common/model"
Expand All @@ -40,7 +40,7 @@ func init() {
})
}

var userAgent = fmt.Sprintf("GrafanaAgent/%s", build.Version)
var userAgent = useragent.Get()

const (
dockerLabel = model.MetaLabelPrefix + "docker_"
Expand Down
3 changes: 0 additions & 3 deletions component/loki/write/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/grafana/agent/component/common/loki/client"
"github.com/grafana/agent/component/common/loki/limit"
"github.com/grafana/agent/component/common/loki/wal"
"github.com/grafana/agent/pkg/build"
)

func init() {
Expand All @@ -25,8 +24,6 @@ func init() {
return New(opts, args.(Arguments))
},
})

client.UserAgent = fmt.Sprintf("GrafanaAgent/%s", build.Version)
}

// Arguments holds values which are used to configure the loki.write component.
Expand Down
4 changes: 2 additions & 2 deletions component/prometheus/remotewrite/remote_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/go-kit/log"
"github.com/grafana/agent/component"
"github.com/grafana/agent/pkg/build"
"github.com/grafana/agent/internal/useragent"
"github.com/grafana/agent/pkg/flow/logging/level"
"github.com/grafana/agent/pkg/metrics/wal"
"github.com/prometheus/prometheus/model/timestamp"
Expand All @@ -35,7 +35,7 @@ import (
var remoteFlushDeadline = 1 * time.Minute

func init() {
remote.UserAgent = fmt.Sprintf("GrafanaAgent/%s", build.Version)
remote.UserAgent = useragent.Get()

component.Register(component.Registration{
Name: "prometheus.remote_write",
Expand Down
4 changes: 2 additions & 2 deletions component/prometheus/scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
component_config "github.com/grafana/agent/component/common/config"
"github.com/grafana/agent/component/discovery"
"github.com/grafana/agent/component/prometheus"
"github.com/grafana/agent/pkg/build"
"github.com/grafana/agent/internal/useragent"
"github.com/grafana/agent/pkg/flow/logging/level"
"github.com/grafana/agent/service/cluster"
"github.com/grafana/agent/service/http"
Expand All @@ -27,7 +27,7 @@ import (
)

func init() {
scrape.UserAgent = fmt.Sprintf("GrafanaAgent/%s", build.Version)
scrape.UserAgent = useragent.Get()

component.Register(component.Registration{
Name: "prometheus.scrape",
Expand Down
5 changes: 2 additions & 3 deletions component/pyroscope/scrape/scrape_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ import (

"github.com/go-kit/log"
"github.com/grafana/agent/component/pyroscope"
"github.com/grafana/agent/internal/useragent"
"github.com/grafana/agent/pkg/flow/logging/level"
commonconfig "github.com/prometheus/common/config"
"github.com/prometheus/prometheus/discovery/targetgroup"
"github.com/prometheus/prometheus/util/pool"
"golang.org/x/net/context/ctxhttp"

"github.com/grafana/agent/pkg/build"
)

var (
payloadBuffers = pool.New(1e3, 1e6, 3, func(sz int) interface{} { return make([]byte, 0, sz) })
userAgentHeader = fmt.Sprintf("GrafanaAgent/%s", build.Version)
userAgentHeader = useragent.Get()
)

type scrapePool struct {
Expand Down
5 changes: 2 additions & 3 deletions component/pyroscope/write/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package write
import (
"context"
"errors"
"fmt"
"strings"
"time"

"github.com/bufbuild/connect-go"
"github.com/grafana/agent/component/pyroscope"
"github.com/grafana/agent/internal/useragent"
"github.com/grafana/agent/pkg/flow/logging/level"
"github.com/oklog/run"
commonconfig "github.com/prometheus/common/config"
Expand All @@ -18,15 +18,14 @@ import (

"github.com/grafana/agent/component"
"github.com/grafana/agent/component/common/config"
"github.com/grafana/agent/pkg/build"
"github.com/grafana/dskit/backoff"
pushv1 "github.com/grafana/pyroscope/api/gen/proto/go/push/v1"
"github.com/grafana/pyroscope/api/gen/proto/go/push/v1/pushv1connect"
typesv1 "github.com/grafana/pyroscope/api/gen/proto/go/types/v1"
)

var (
userAgent = fmt.Sprintf("GrafanaAgent/%s", build.Version)
userAgent = useragent.Get()
DefaultArguments = func() Arguments {
return Arguments{}
}
Expand Down
4 changes: 2 additions & 2 deletions component/remote/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
"github.com/go-kit/log"
"github.com/grafana/agent/component"
common_config "github.com/grafana/agent/component/common/config"
"github.com/grafana/agent/pkg/build"
"github.com/grafana/agent/internal/useragent"
"github.com/grafana/agent/pkg/flow/logging/level"
"github.com/grafana/river/rivertypes"
prom_config "github.com/prometheus/common/config"
)

var userAgent = fmt.Sprintf("GrafanaAgent/%s", build.Version)
var userAgent = useragent.Get()

func init() {
component.Register(component.Registration{
Expand Down
60 changes: 60 additions & 0 deletions internal/useragent/useragent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// package useragent provides a consistent way to get a user agent for outbound http requests from Grafana Agent.
// The default User-Agent is `GrafanaAgent/$VERSION($MODE)`
// Where version is the build version of the agent and MODE is one of "static" or "flow".
package useragent

import (
"fmt"
"os"
"runtime"
"strings"

"github.com/grafana/agent/pkg/build"
)

const (
deployModeEnv = "AGENT_DEPLOY_MODE"
modeEnv = "AGENT_MODE"
)

// settable by tests
var goos = runtime.GOOS

func Get() string {
parenthesis := ""
metadata := []string{}
if mode := getRunMode(); mode != "" {
metadata = append(metadata, mode)
}
metadata = append(metadata, goos)
if op := getDeployMode(); op != "" {
metadata = append(metadata, op)
}
if len(metadata) > 0 {
parenthesis = fmt.Sprintf(" (%s)", strings.Join(metadata, "; "))
}
return fmt.Sprintf("GrafanaAgent/%s%s", build.Version, parenthesis)
}

// getRunMode attempts to get agent mode, using `unknown` for invalid values.
func getRunMode() string {
key := os.Getenv(modeEnv)
switch key {
case "flow":
return "flow"
case "static", "":
return "static"
default:
return "unknown"
}
}

func getDeployMode() string {
op := os.Getenv(deployModeEnv)
// only return known modes. Use "binary" as a default catch-all.
switch op {
case "operator", "helm", "docker", "deb", "rpm", "brew":
return op
}
return "binary"
}
Loading

0 comments on commit 684e920

Please sign in to comment.