From 6100c557d0e46e9ee1814e17d596fdcd04d248ad Mon Sep 17 00:00:00 2001 From: Rail Aliiev Date: Mon, 27 Mar 2023 17:14:04 -0400 Subject: [PATCH] telemetry: add FIPS-specific channel Previously, all official builds were reporting using the same telemetry channel. This PR adds an new telemetry channel for the FIPS build target. Fixes: CC-24110 Epic: DEVINF-478 Release note: None --- pkg/build/info.go | 7 ++++++- pkg/cmd/publish-artifacts/main.go | 8 +++++++- pkg/cmd/publish-artifacts/main_test.go | 10 +++++----- pkg/cmd/publish-provisional-artifacts/main.go | 8 ++++++-- .../main_test.go | 12 ++++++------ pkg/release/BUILD.bazel | 1 + pkg/release/build.go | 19 +++++++++++++++++-- 7 files changed, 48 insertions(+), 17 deletions(-) diff --git a/pkg/build/info.go b/pkg/build/info.go index ff47bd7749fd..b3697cf6d86c 100644 --- a/pkg/build/info.go +++ b/pkg/build/info.go @@ -45,6 +45,11 @@ var ( binaryVersion = computeBinaryVersion(cockroachVersion, rev) ) +const ( + DefaultTelemetryChannel = "official-binary" + FIPSTelemetryChannel = "official-fips-binary" +) + // IsRelease returns true if the binary was produced by a "release" build. func IsRelease() bool { return typ == "release" @@ -53,7 +58,7 @@ func IsRelease() bool { // SeemsOfficial reports whether this binary is likely to have come from an // official release channel. func SeemsOfficial() bool { - return channel == "official-binary" + return channel == DefaultTelemetryChannel || channel == FIPSTelemetryChannel } func computeBinaryVersion(versionTxt, revision string) string { diff --git a/pkg/cmd/publish-artifacts/main.go b/pkg/cmd/publish-artifacts/main.go index 849579443b55..5781db7fc625 100644 --- a/pkg/cmd/publish-artifacts/main.go +++ b/pkg/cmd/publish-artifacts/main.go @@ -96,6 +96,7 @@ func run(providers []release.ObjectPutGetter, flags runFlags, execFn release.Exe o.VersionStr = flags.sha o.AbsolutePath = filepath.Join(flags.pkgDir, "cockroach"+release.SuffixFromPlatform(platform)) o.CockroachSQLAbsolutePath = filepath.Join(flags.pkgDir, "cockroach-sql"+release.SuffixFromPlatform(platform)) + o.Channel = release.ChannelFromPlatform(platform) log.Printf("building %s", pretty.Sprint(o)) buildOneCockroach(providers, o, execFn) @@ -111,7 +112,11 @@ func run(providers []release.ObjectPutGetter, flags runFlags, execFn release.Exe func buildOneCockroach(providers []release.ObjectPutGetter, o opts, execFn release.ExecFn) { log.Printf("building cockroach %s", pretty.Sprint(o)) - if err := release.MakeRelease(o.Platform, release.BuildOptions{ExecFn: execFn}, o.PkgDir); err != nil { + buildOpts := release.BuildOptions{ + ExecFn: execFn, + Channel: o.Channel, + } + if err := release.MakeRelease(o.Platform, buildOpts, o.PkgDir); err != nil { log.Fatal(err) } for _, provider := range providers { @@ -160,4 +165,5 @@ type opts struct { AbsolutePath string CockroachSQLAbsolutePath string PkgDir string + Channel string } diff --git a/pkg/cmd/publish-artifacts/main_test.go b/pkg/cmd/publish-artifacts/main_test.go index a842c60e7ae7..348b078e74ae 100644 --- a/pkg/cmd/publish-artifacts/main_test.go +++ b/pkg/cmd/publish-artifacts/main_test.go @@ -171,7 +171,7 @@ func TestPublish(t *testing.T) { "env=[MALLOC_CONF=prof:true] args=./cockroach.linux-2.6.32-gnu-amd64 version", "env=[] args=ldd ./cockroach.linux-2.6.32-gnu-amd64", "env=[] args=bazel run @go_sdk//:bin/go -- tool nm ./cockroach.linux-2.6.32-gnu-amd64", - "env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", + "env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-fips-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "env=[] args=bazel info bazel-bin -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "env=[MALLOC_CONF=prof:true] args=./cockroach.linux-2.6.32-gnu-amd64-fips version", "env=[] args=ldd ./cockroach.linux-2.6.32-gnu-amd64-fips", @@ -211,22 +211,22 @@ func TestPublish(t *testing.T) { "gs://edge-binaries-bucket/cockroach/lib/libgeos_c.linux-gnu-amd64.so.LATEST/no-cache REDIRECT /cockroach/lib/libgeos_c.linux-gnu-amd64.1234567890abcdef.so", "gs://edge-binaries-bucket/cockroach/cockroach.linux-gnu-amd64-fips.1234567890abcdef CONTENTS env=[] args=bazel build " + "//pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos " + - "'--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-binary' " + + "'--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-fips-binary' " + "-c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "gs://edge-binaries-bucket/cockroach/cockroach.linux-gnu-amd64-fips.LATEST/no-cache REDIRECT /cockroach/cockroach.linux-gnu-amd64-fips.1234567890abcdef", "gs://edge-binaries-bucket/cockroach/cockroach-sql.linux-gnu-amd64-fips.1234567890abcdef CONTENTS env=[] args=bazel build " + "//pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos " + - "'--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-binary' " + + "'--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-fips-binary' " + "-c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "gs://edge-binaries-bucket/cockroach/cockroach-sql.linux-gnu-amd64-fips.LATEST/no-cache REDIRECT /cockroach/cockroach-sql.linux-gnu-amd64-fips.1234567890abcdef", "gs://edge-binaries-bucket/cockroach/lib/libgeos.linux-gnu-amd64-fips.1234567890abcdef.so CONTENTS env=[] args=bazel build " + "//pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos " + - "'--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-binary' " + + "'--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-fips-binary' " + "-c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "gs://edge-binaries-bucket/cockroach/lib/libgeos.linux-gnu-amd64-fips.so.LATEST/no-cache REDIRECT /cockroach/lib/libgeos.linux-gnu-amd64-fips.1234567890abcdef.so", "gs://edge-binaries-bucket/cockroach/lib/libgeos_c.linux-gnu-amd64-fips.1234567890abcdef.so CONTENTS env=[] args=bazel build " + "//pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos " + - "'--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-binary' " + + "'--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-fips-binary' " + "-c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "gs://edge-binaries-bucket/cockroach/lib/libgeos_c.linux-gnu-amd64-fips.so.LATEST/no-cache REDIRECT /cockroach/lib/libgeos_c.linux-gnu-amd64-fips.1234567890abcdef.so", "gs://edge-binaries-bucket/cockroach/cockroach.linux-gnu-arm64.1234567890abcdef CONTENTS env=[] args=bazel build " + diff --git a/pkg/cmd/publish-provisional-artifacts/main.go b/pkg/cmd/publish-provisional-artifacts/main.go index 332c388c4f69..6a858a39f1b7 100644 --- a/pkg/cmd/publish-provisional-artifacts/main.go +++ b/pkg/cmd/publish-provisional-artifacts/main.go @@ -157,6 +157,7 @@ func run(providers []release.ObjectPutGetter, flags runFlags, execFn release.Exe o.VersionStr = versionStr o.AbsolutePath = filepath.Join(flags.pkgDir, "cockroach"+release.SuffixFromPlatform(platform)) o.CockroachSQLAbsolutePath = filepath.Join(flags.pkgDir, "cockroach-sql"+release.SuffixFromPlatform(platform)) + o.Channel = release.ChannelFromPlatform(platform) cockroachBuildOpts = append(cockroachBuildOpts, o) } @@ -234,8 +235,10 @@ func buildCockroach(flags runFlags, o opts, execFn release.ExecFn) { log.Printf("done building cockroach: %s", pretty.Sprint(o)) }() - var buildOpts release.BuildOptions - buildOpts.ExecFn = execFn + buildOpts := release.BuildOptions{ + ExecFn: execFn, + Channel: release.ChannelFromPlatform(o.Platform), + } if flags.isRelease { buildOpts.Release = true buildOpts.BuildTag = o.VersionStr @@ -253,6 +256,7 @@ type opts struct { AbsolutePath string CockroachSQLAbsolutePath string PkgDir string + Channel string } func markLatestRelease(svc release.ObjectPutGetter, o opts) { diff --git a/pkg/cmd/publish-provisional-artifacts/main_test.go b/pkg/cmd/publish-provisional-artifacts/main_test.go index 3066187c8b34..f0d9c48bcfec 100644 --- a/pkg/cmd/publish-provisional-artifacts/main_test.go +++ b/pkg/cmd/publish-provisional-artifacts/main_test.go @@ -179,7 +179,7 @@ func TestProvisional(t *testing.T) { "env=[MALLOC_CONF=prof:true] args=./cockroach.linux-2.6.32-gnu-amd64 version", "env=[] args=ldd ./cockroach.linux-2.6.32-gnu-amd64", "env=[] args=bazel run @go_sdk//:bin/go -- tool nm ./cockroach.linux-2.6.32-gnu-amd64", - "env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-binary release' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", + "env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-fips-binary release' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "env=[] args=bazel info bazel-bin -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "env=[MALLOC_CONF=prof:true] args=./cockroach.linux-2.6.32-gnu-amd64-fips version", "env=[] args=ldd ./cockroach.linux-2.6.32-gnu-amd64-fips", @@ -241,7 +241,7 @@ func TestProvisional(t *testing.T) { "env=[MALLOC_CONF=prof:true] args=./cockroach.linux-2.6.32-gnu-amd64 version", "env=[] args=ldd ./cockroach.linux-2.6.32-gnu-amd64", "env=[] args=bazel run @go_sdk//:bin/go -- tool nm ./cockroach.linux-2.6.32-gnu-amd64", - "env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", + "env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-fips-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "env=[] args=bazel info bazel-bin -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "env=[MALLOC_CONF=prof:true] args=./cockroach.linux-2.6.32-gnu-amd64-fips version", "env=[] args=ldd ./cockroach.linux-2.6.32-gnu-amd64-fips", @@ -277,13 +277,13 @@ func TestProvisional(t *testing.T) { "so CONTENTS env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos " + "'--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxbase", "gs://edge-binaries-bucket/cockroach/lib/libgeos_c.linux-gnu-amd64.so.LATEST/no-cache REDIRECT /cockroach/lib/libgeos_c.linux-gnu-amd64.00SHA00.so", - "gs://edge-binaries-bucket/cockroach/cockroach.linux-gnu-amd64-fips.00SHA00 CONTENTS env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", + "gs://edge-binaries-bucket/cockroach/cockroach.linux-gnu-amd64-fips.00SHA00 CONTENTS env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-fips-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "gs://edge-binaries-bucket/cockroach/cockroach.linux-gnu-amd64-fips.LATEST/no-cache REDIRECT /cockroach/cockroach.linux-gnu-amd64-fips.00SHA00", - "gs://edge-binaries-bucket/cockroach/cockroach-sql.linux-gnu-amd64-fips.00SHA00 CONTENTS env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", + "gs://edge-binaries-bucket/cockroach/cockroach-sql.linux-gnu-amd64-fips.00SHA00 CONTENTS env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-fips-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "gs://edge-binaries-bucket/cockroach/cockroach-sql.linux-gnu-amd64-fips.LATEST/no-cache REDIRECT /cockroach/cockroach-sql.linux-gnu-amd64-fips.00SHA00", - "gs://edge-binaries-bucket/cockroach/lib/libgeos.linux-gnu-amd64-fips.00SHA00.so CONTENTS env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", + "gs://edge-binaries-bucket/cockroach/lib/libgeos.linux-gnu-amd64-fips.00SHA00.so CONTENTS env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-fips-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "gs://edge-binaries-bucket/cockroach/lib/libgeos.linux-gnu-amd64-fips.so.LATEST/no-cache REDIRECT /cockroach/lib/libgeos.linux-gnu-amd64-fips.00SHA00.so", - "gs://edge-binaries-bucket/cockroach/lib/libgeos_c.linux-gnu-amd64-fips.00SHA00.so CONTENTS env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", + "gs://edge-binaries-bucket/cockroach/lib/libgeos_c.linux-gnu-amd64-fips.00SHA00.so CONTENTS env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-pc-linux-gnu official-fips-binary' -c opt --config=ci --config=force_build_cdeps --config=with_ui --config=crosslinuxfipsbase", "gs://edge-binaries-bucket/cockroach/lib/libgeos_c.linux-gnu-amd64-fips.so.LATEST/no-cache REDIRECT /cockroach/lib/libgeos_c.linux-gnu-amd64-fips.00SHA00.so", "gs://edge-binaries-bucket/cockroach/cockroach.darwin-amd64.00SHA00 " + "CONTENTS env=[] args=bazel build //pkg/cmd/cockroach //pkg/cmd/cockroach-sql //c-deps:libgeos " + diff --git a/pkg/release/BUILD.bazel b/pkg/release/BUILD.bazel index df10e3674e0e..875816355a50 100644 --- a/pkg/release/BUILD.bazel +++ b/pkg/release/BUILD.bazel @@ -12,6 +12,7 @@ go_library( importpath = "github.com/cockroachdb/cockroach/pkg/release", visibility = ["//visibility:public"], deps = [ + "//pkg/build", "//pkg/build/util", "@com_github_cockroachdb_errors//:errors", "@com_google_cloud_go_storage//:storage", diff --git a/pkg/release/build.go b/pkg/release/build.go index 769755d0a6fe..a42e9cd0d646 100644 --- a/pkg/release/build.go +++ b/pkg/release/build.go @@ -22,6 +22,7 @@ import ( "regexp" "strings" + "github.com/cockroachdb/cockroach/pkg/build" "github.com/cockroachdb/cockroach/pkg/build/util" "github.com/cockroachdb/errors" ) @@ -37,6 +38,17 @@ type BuildOptions struct { // The zero value is appropriate in "real" scenarios but for // tests you can update ExecFn.MockExecFn. ExecFn ExecFn + + // Channel represents the telemetry channel + Channel string +} + +// ChannelFromPlatform retrurns the telemetry channel used for a particular platform. +func ChannelFromPlatform(platform Platform) string { + if platform == PlatformLinuxFIPS { + return build.FIPSTelemetryChannel + } + return build.DefaultTelemetryChannel } // SuffixFromPlatform returns the suffix that will be appended to the @@ -143,6 +155,9 @@ func MakeWorkload(opts BuildOptions, pkgDir string) error { // MakeRelease makes the release binary and associated files. func MakeRelease(platform Platform, opts BuildOptions, pkgDir string) error { + if !(opts.Channel == build.DefaultTelemetryChannel || opts.Channel == build.FIPSTelemetryChannel) { + return errors.Newf("cannot set the telemetry channel to %s, supported channels: %s and %s", opts.Channel, build.DefaultTelemetryChannel, build.FIPSTelemetryChannel) + } buildArgs := []string{"build", "//pkg/cmd/cockroach", "//pkg/cmd/cockroach-sql"} if platform != PlatformMacOSArm { buildArgs = append(buildArgs, "//c-deps:libgeos") @@ -152,12 +167,12 @@ func MakeRelease(platform Platform, opts BuildOptions, pkgDir string) error { if opts.BuildTag == "" { return errors.Newf("must set BuildTag if Release is set") } - buildArgs = append(buildArgs, fmt.Sprintf("--workspace_status_command=./build/bazelutil/stamp.sh %s official-binary release", targetTriple)) + buildArgs = append(buildArgs, fmt.Sprintf("--workspace_status_command=./build/bazelutil/stamp.sh %s %s release", targetTriple, opts.Channel)) } else { if opts.BuildTag != "" { return errors.Newf("cannot set BuildTag if Release is not set") } - buildArgs = append(buildArgs, fmt.Sprintf("--workspace_status_command=./build/bazelutil/stamp.sh %s official-binary", targetTriple)) + buildArgs = append(buildArgs, fmt.Sprintf("--workspace_status_command=./build/bazelutil/stamp.sh %s %s", targetTriple, opts.Channel)) } configs := []string{"-c", "opt", "--config=ci", "--config=force_build_cdeps", "--config=with_ui", fmt.Sprintf("--config=%s", CrossConfigFromPlatform(platform))} buildArgs = append(buildArgs, configs...)