From c1cfe44644da2cc1da6ff32364f6c1581f5d8059 Mon Sep 17 00:00:00 2001 From: Fredrik Medley Date: Wed, 13 Sep 2023 08:37:03 +0200 Subject: [PATCH 1/2] Add Buildbarn logo svg --- pkg/logo/BUILD.bazel | 20 ++++++++++++++++++++ pkg/logo/buildbarn_logo.svg | 21 +++++++++++++++++++++ pkg/logo/logo.go | 11 +++++++++++ 3 files changed, 52 insertions(+) create mode 100644 pkg/logo/BUILD.bazel create mode 100644 pkg/logo/buildbarn_logo.svg create mode 100644 pkg/logo/logo.go diff --git a/pkg/logo/BUILD.bazel b/pkg/logo/BUILD.bazel new file mode 100644 index 00000000..2fadb1a8 --- /dev/null +++ b/pkg/logo/BUILD.bazel @@ -0,0 +1,20 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +# Minify the logo into a favicon. +genrule( + name = "favicon", + srcs = [":buildbarn_logo.svg"], + outs = ["favicon.svg"], + # Remove embedded draw.io content attribute and svg comments. + cmd = "tr -d '\n' < $(location :buildbarn_logo.svg) | sed -e 's/ content=\"[^\"]*\"//' -e 's///g' > $@", +) + +go_library( + name = "logo", + srcs = ["logo.go"], + embedsrcs = [ + "favicon.svg", + ], + importpath = "github.com/buildbarn/bb-storage/pkg/logo", + visibility = ["//visibility:public"], +) diff --git a/pkg/logo/buildbarn_logo.svg b/pkg/logo/buildbarn_logo.svg new file mode 100644 index 00000000..8728b245 --- /dev/null +++ b/pkg/logo/buildbarn_logo.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + diff --git a/pkg/logo/logo.go b/pkg/logo/logo.go new file mode 100644 index 00000000..10b1ef5d --- /dev/null +++ b/pkg/logo/logo.go @@ -0,0 +1,11 @@ +package logo + +import ( + _ "embed" // For "go:embed". +) + +//go:embed favicon.svg +var faviconSvg []byte + +// FaviconSvg holds the Buildbarn logo and can be used as favicon in web browsers. +var FaviconSvg = faviconSvg From fd73ecbee3eb98559d8c67bceaabfe5d5f5ca0ab Mon Sep 17 00:00:00 2001 From: Fredrik Medley Date: Thu, 9 Nov 2023 23:36:46 +0100 Subject: [PATCH 2/2] Integrate logo in otel --- pkg/logo/BUILD.bazel | 4 +--- pkg/logo/logo.go | 10 ++++++++++ pkg/otel/BUILD.bazel | 2 ++ pkg/otel/active_spans.html | 1 + pkg/otel/active_spans_reporting_http_handler.go | 4 +++- pkg/otel/active_spans_reporting_http_handler_test.go | 3 +++ 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/logo/BUILD.bazel b/pkg/logo/BUILD.bazel index 2fadb1a8..ba66cdc3 100644 --- a/pkg/logo/BUILD.bazel +++ b/pkg/logo/BUILD.bazel @@ -12,9 +12,7 @@ genrule( go_library( name = "logo", srcs = ["logo.go"], - embedsrcs = [ - "favicon.svg", - ], + embedsrcs = ["favicon.svg"], importpath = "github.com/buildbarn/bb-storage/pkg/logo", visibility = ["//visibility:public"], ) diff --git a/pkg/logo/logo.go b/pkg/logo/logo.go index 10b1ef5d..12a2a907 100644 --- a/pkg/logo/logo.go +++ b/pkg/logo/logo.go @@ -2,6 +2,8 @@ package logo import ( _ "embed" // For "go:embed". + "encoding/base64" + "html/template" ) //go:embed favicon.svg @@ -9,3 +11,11 @@ var faviconSvg []byte // FaviconSvg holds the Buildbarn logo and can be used as favicon in web browsers. var FaviconSvg = faviconSvg + +// EmbeddedFaviconURL has encoded FaviconSvg into a 'data:' URL, +// to be embedded in a web site. +// +// Example: +// +// +var EmbeddedFaviconURL = template.URL("data:image/svg+xml;base64," + base64.StdEncoding.EncodeToString(FaviconSvg)) diff --git a/pkg/otel/BUILD.bazel b/pkg/otel/BUILD.bazel index 99cead49..c38b03fa 100644 --- a/pkg/otel/BUILD.bazel +++ b/pkg/otel/BUILD.bazel @@ -18,6 +18,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/clock", + "//pkg/logo", "@io_opentelemetry_go_otel//attribute", "@io_opentelemetry_go_otel//codes", "@io_opentelemetry_go_otel//propagation", @@ -45,6 +46,7 @@ go_test( deps = [ ":otel", "//internal/mock", + "//pkg/logo", "//pkg/testutil", "@com_github_golang_mock//gomock", "@com_github_stretchr_testify//require", diff --git a/pkg/otel/active_spans.html b/pkg/otel/active_spans.html index ef7d20b4..1d0c0d31 100644 --- a/pkg/otel/active_spans.html +++ b/pkg/otel/active_spans.html @@ -2,6 +2,7 @@ Active OpenTelemetry spans + diff --git a/pkg/otel/active_spans_reporting_http_handler.go b/pkg/otel/active_spans_reporting_http_handler.go index 8c0ba567..f3b7ad5e 100644 --- a/pkg/otel/active_spans_reporting_http_handler.go +++ b/pkg/otel/active_spans_reporting_http_handler.go @@ -10,6 +10,7 @@ import ( "time" "github.com/buildbarn/bb-storage/pkg/clock" + "github.com/buildbarn/bb-storage/pkg/logo" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" @@ -20,7 +21,8 @@ var ( //go:embed active_spans.html activeSpansTemplateBody string activeSpansTemplate = template.Must(template.New("ActiveSpans").Funcs(template.FuncMap{ - "stylesheet": func() template.CSS { return stylesheet }, + "favicon_url": func() template.URL { return logo.EmbeddedFaviconURL }, + "stylesheet": func() template.CSS { return stylesheet }, "timestamp_rfc3339": func(t time.Time) string { // Converts a timestamp to RFC3339 format. return t.Format("2006-01-02T15:04:05.999Z07:00") diff --git a/pkg/otel/active_spans_reporting_http_handler_test.go b/pkg/otel/active_spans_reporting_http_handler_test.go index 8eaab184..60d7e8b4 100644 --- a/pkg/otel/active_spans_reporting_http_handler_test.go +++ b/pkg/otel/active_spans_reporting_http_handler_test.go @@ -4,6 +4,7 @@ import ( "context" _ "embed" // For "go:embed". "errors" + "html/template" "io" "net/http" "net/http/httptest" @@ -12,6 +13,7 @@ import ( "time" "github.com/buildbarn/bb-storage/internal/mock" + "github.com/buildbarn/bb-storage/pkg/logo" "github.com/buildbarn/bb-storage/pkg/otel" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" @@ -38,6 +40,7 @@ func requireEqualBody(t *testing.T, expectedBody string, hh http.Handler) { Active OpenTelemetry spans +