Skip to content

Commit

Permalink
Merge pull request #1700 from grafana/feat/user-agent
Browse files Browse the repository at this point in the history
feat: add user agent to requests made by operator
  • Loading branch information
theSuess authored Oct 7, 2024
2 parents 70b6599 + 82830a2 commit 1519bae
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
- name: Install ko
uses: ko-build/[email protected]
with:
version: v0.13.0
version: v0.16.0

- name: Install chainsaw
uses: kyverno/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:

- uses: ko-build/[email protected]
with:
version: v0.15.1
version: v0.16.0

- name: Install cosign
uses: sigstore/[email protected]
Expand Down
8 changes: 8 additions & 0 deletions .ko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
builds:
- id: grafana-operator
dir: .
main: .
flags:
- '-trimpath'
ldflags:
- -X github.com/grafana/grafana-operator/v5/embeds.Version={{.Git.Tag}}
2 changes: 2 additions & 0 deletions controllers/client/round_tripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"strconv"

"github.com/grafana/grafana-operator/v5/embeds"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -36,6 +37,7 @@ func NewInstrumentedRoundTripper(relatedResource string, metric *prometheus.Coun
}

func (in *instrumentedRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
r.Header.Add("user-agent", "grafana-operator/"+embeds.Version)
resp, err := in.wrapped.RoundTrip(r)
if resp != nil {
in.metric.WithLabelValues(
Expand Down
6 changes: 5 additions & 1 deletion embeds/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Embeds

This directory is used for embedding FS structs into go code.
This package contains static information compiled into the binary at build time.

# Grafonnet

The Grafonnet Jsonnet is used to allow users to define their dashboards using the jsonnet framework.

# Version

The `Version` variable is set during production builds by `ko`. Configuration for this can be found in `.ko.yaml`
3 changes: 3 additions & 0 deletions embeds/grafana_embeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ var TestDashboardEmbedWithEnvExpectedJSON []byte

//go:embed testing/jsonnetProjectWithRuntimeRaw.tar.gz
var TestJsonnetProjectBuildFolderGzip []byte

// this variable is replaced during production builds
var Version = "dev"
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
grafanav1beta1 "github.com/grafana/grafana-operator/v5/api/v1beta1"
"github.com/grafana/grafana-operator/v5/controllers"
"github.com/grafana/grafana-operator/v5/controllers/autodetect"
"github.com/grafana/grafana-operator/v5/embeds"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand All @@ -66,7 +67,7 @@ const (

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
setupLog = ctrl.Log.WithName("setup").WithValues("version", embeds.Version)
)

func init() {
Expand Down

0 comments on commit 1519bae

Please sign in to comment.