diff --git a/pkg/logo/BUILD.bazel b/pkg/logo/BUILD.bazel new file mode 100644 index 000000000..ba66cdc3b --- /dev/null +++ b/pkg/logo/BUILD.bazel @@ -0,0 +1,18 @@ +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 000000000..8728b2454 --- /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 000000000..12a2a907d --- /dev/null +++ b/pkg/logo/logo.go @@ -0,0 +1,21 @@ +package logo + +import ( + _ "embed" // For "go:embed". + "encoding/base64" + "html/template" +) + +//go:embed favicon.svg +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 99cead49e..c38b03fa5 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 ef7d20b40..1d0c0d31c 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 8c0ba5679..f3b7ad5eb 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 8eaab1843..60d7e8b49 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 +