diff --git a/Makefile b/Makefile index a3adcaa5306..02e9cdccf01 100644 --- a/Makefile +++ b/Makefile @@ -130,6 +130,9 @@ GO_ENV := GOEXPERIMENT=$(GOEXPERIMENT) GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOA VERSION ?= $(shell bash ./tools/image-tag) GIT_REVISION := $(shell git rev-parse --short HEAD) GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD) +BEYLA_MODULE := $(shell go list -m all | grep "^github.com/grafana/beyla" | head -1) +BEYLA_VERSION := $(shell echo $(BEYLA_MODULE) | cut -d' ' -f2) +BEYLA_PKG := $(shell echo $(BEYLA_MODULE) | cut -d' ' -f1)/pkg/buildinfo VPREFIX := github.com/grafana/alloy/internal/build VPREFIXSYNTAX := github.com/grafana/alloy/syntax/internal/stdlib ifdef SOURCE_DATE_EPOCH @@ -140,7 +143,8 @@ GO_LDFLAGS := -X $(VPREFIX).Branch=$(GIT_BRANCH) \ -X $(VPREFIXSYNTAX).Version=$(VERSION) \ -X $(VPREFIX).Revision=$(GIT_REVISION) \ -X $(VPREFIX).BuildUser=$(BUILDER_USER)@$(BUILDER_HOST) \ - -X $(VPREFIX).BuildDate=$(shell date -u $(DATE_STAMP) +"%Y-%m-%dT%H:%M:%SZ") + -X $(VPREFIX).BuildDate=$(shell date -u $(DATE_STAMP) +"%Y-%m-%dT%H:%M:%SZ") \ + -X $(BEYLA_PKG).Version=$(BEYLA_VERSION) DEFAULT_FLAGS := $(GO_FLAGS) DEBUG_GO_FLAGS := -ldflags "$(GO_LDFLAGS)" -tags "$(GO_TAGS)" diff --git a/integration-tests/docker/common/metric.go b/integration-tests/docker/common/metric.go index d1ce8c16968..76edb0cebc8 100644 --- a/integration-tests/docker/common/metric.go +++ b/integration-tests/docker/common/metric.go @@ -52,6 +52,7 @@ type Value struct { type Metric struct { TestName string `json:"test_name"` Name string `json:"__name__"` + Version string `json:"version"` } func (m *MetricResponse) Unmarshal(data []byte) error { diff --git a/integration-tests/docker/tests/beyla/beyla_test.go b/integration-tests/docker/tests/beyla/beyla_test.go index faa69fc1c60..5acc3eb0caf 100644 --- a/integration-tests/docker/tests/beyla/beyla_test.go +++ b/integration-tests/docker/tests/beyla/beyla_test.go @@ -6,6 +6,8 @@ import ( "testing" "github.com/grafana/alloy/integration-tests/docker/common" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBeylaMetrics(t *testing.T) { @@ -23,3 +25,19 @@ func TestBeylaTraces(t *testing.T) { } common.TracesTest(t, tags, "beyla") } + +// Test that checks that the Beyla version is correctly injected into the binary. +func TestBeylaVersion(t *testing.T) { + var metricResponse common.MetricResponse + require.EventuallyWithT(t, func(c *assert.CollectT) { + _, err := common.FetchDataFromURL( + common.MetricQuery("beyla_internal_build_info", "beyla"), + &metricResponse, + ) + // Ensure the version label is not the default "unset" value + assert.NoError(c, err) + if assert.NotEmpty(c, metricResponse.Data.Result) { + assert.NotEqual(c, "unset", metricResponse.Data.Result[0].Metric.Version) + } + }, common.TestTimeoutEnv(t), common.DefaultRetryInterval) +}