Skip to content

Commit

Permalink
Merge #99810 #100784
Browse files Browse the repository at this point in the history
99810: roachtest: create simple tpce workload driver r=renatolabs a=msbutler

Currently, the tpce workload is used in 2 roachtests in tpce.go. This patch makes it easier for other roachtests to init and run a tpce workload by creating a tpce driver that abstracts away the actual cmds required to init and run a tpce workload. This will make it easier to address #99787, for example.

Informs #99787

Release note: none

100784: release: use in-source version for Red Hat publishing r=jlinder a=rail

Previously, we passed the version we want to publish via TeamCIty. With version available in `pkg/build/version.txt`, we can start using it to simplify our automation.

This PR copies the existing publishing script and adjusts the way we read the version.

Epic: none
Release note: None

Co-authored-by: Michael Butler <[email protected]>
Co-authored-by: Rail Aliiev <[email protected]>
  • Loading branch information
3 people committed Apr 6, 2023
3 parents 7de717e + 36a1187 + ed73e76 commit 01f3b26
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env bash

set -euxo pipefail

dir="$(dirname $(dirname $(dirname $(dirname $(dirname $(dirname "${0}"))))))"
source "$dir/release/teamcity-support.sh"
source "$dir/shlib.sh"


tc_start_block "Variable Setup"
version=$(grep -v "^#" "$dir/../pkg/build/version.txt" | head -n1)
if [[ $version == *"-"* ]]; then
echo "Pushing pre-release versions to Red Hat is not implemented (there is no unstable repository for them to live)"
exit 0
fi

# Hard coded release number used only by the RedHat images
rhel_release=1
rhel_project_id=5e61ea74fe2231a0c2860382
rhel_registry="quay.io"
rhel_registry_username="redhat-isv-containers+${rhel_project_id}-robot"
rhel_repository="${rhel_registry}/redhat-isv-containers/$rhel_project_id"
dockerhub_repository="cockroachdb/cockroach"

if ! [[ -z "${DRY_RUN}" ]] ; then
version="${version}-dryrun"
dockerhub_repository="cockroachdb/cockroach-misc"
fi
tc_end_block "Variable Setup"

tc_start_block "Configure docker"
echo "${QUAY_REGISTRY_KEY}" | docker login --username $rhel_registry_username --password-stdin $rhel_registry
tc_end_block "Configure docker"

tc_start_block "Rebuild docker image"
sed \
-e "s,@repository@,${dockerhub_repository},g" \
-e "s,@tag@,${version},g" \
build/deploy-redhat/Dockerfile.in > build/deploy-redhat/Dockerfile

cat build/deploy-redhat/Dockerfile

docker build --no-cache \
--pull \
--label release=$rhel_release \
--tag="${rhel_repository}:${version}" \
build/deploy-redhat
tc_end_block "Rebuild docker image"

tc_start_block "Push RedHat docker image"
retry docker push "${rhel_repository}:${version}"
tc_end_block "Push RedHat docker image"

tc_start_block "Tag docker image as latest"
if [[ -n "${PUBLISH_LATEST}" ]]; then
docker tag "${rhel_repository}:${version}" "${rhel_repository}:latest"
retry docker push "${rhel_repository}:latest"
else
echo "Not required"
fi
tc_end_block "Tag docker images as latest"

tc_start_block "Run preflight"
mkdir -p artifacts
docker run \
--rm \
--security-opt=label=disable \
--env PFLT_LOGLEVEL=trace \
--env PFLT_ARTIFACTS=/artifacts \
--env PFLT_LOGFILE=/artifacts/preflight.log \
--env PFLT_CERTIFICATION_PROJECT_ID="$rhel_project_id" \
--env PFLT_PYXIS_API_TOKEN="$REDHAT_API_TOKEN" \
--env PFLT_DOCKERCONFIG=/temp-authfile.json \
--env DOCKER_CONFIG=/tmp/docker \
-v "$PWD/artifacts:/artifacts" \
-v ~/.docker/config.json:/temp-authfile.json:ro \
-v ~/.docker/config.json:/tmp/docker/config.json:ro \
quay.io/opdev/preflight:stable check container \
"${rhel_repository}:${version}" --submit
tc_end_block "Run preflight"
105 changes: 83 additions & 22 deletions pkg/cmd/roachtest/tests/tpce.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,82 @@ import (
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/registry"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/spec"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
"github.com/cockroachdb/cockroach/pkg/roachprod/install"
"github.com/cockroachdb/cockroach/pkg/roachprod/logger"
"github.com/cockroachdb/errors"
"github.com/stretchr/testify/require"
)

type tpceSpec struct {
loadNode int
roachNodes option.NodeListOption
roachNodeIPFlags []string
}

type tpceCmdOptions struct {
customers int
racks int
duration time.Duration
threads int
}

func (to tpceCmdOptions) AddCommandOptions(cmd *roachtestutil.Command) {
cmd.MaybeFlag(to.customers != 0, "customers", to.customers)
cmd.MaybeFlag(to.racks != 0, "racks", to.racks)
cmd.MaybeFlag(to.duration != 0, "duration", to.duration)
cmd.MaybeFlag(to.threads != 0, "threads", to.threads)
}

func initTPCESpec(
ctx context.Context,
l *logger.Logger,
c cluster.Cluster,
loadNode int,
roachNodes option.NodeListOption,
) (*tpceSpec, error) {
l.Printf("Installing docker")
if err := c.Install(ctx, l, c.Nodes(loadNode), "docker"); err != nil {
return nil, err
}
roachNodeIPs, err := c.InternalIP(ctx, l, roachNodes)
if err != nil {
return nil, err
}
roachNodeIPFlags := make([]string, len(roachNodeIPs))
for i, ip := range roachNodeIPs {
roachNodeIPFlags[i] = fmt.Sprintf("--hosts=%s", ip)
}
return &tpceSpec{
loadNode: loadNode,
roachNodes: roachNodes,
roachNodeIPFlags: roachNodeIPFlags,
}, nil
}

func (ts *tpceSpec) newCmd(o tpceCmdOptions) *roachtestutil.Command {
cmd := roachtestutil.NewCommand(`sudo docker run cockroachdb/tpc-e:latest`)
o.AddCommandOptions(cmd)
return cmd
}

// init initializes an empty cluster with a tpce database. This includes a bulk
// import of the data and schema creation.
func (ts *tpceSpec) init(ctx context.Context, t test.Test, c cluster.Cluster, o tpceCmdOptions) {
cmd := ts.newCmd(o).Option("init")
c.Run(ctx, c.Node(ts.loadNode), fmt.Sprintf("%s %s", cmd, ts.roachNodeIPFlags[0]))
}

// run runs the tpce workload on cluster that has been initialized with the tpce schema.
func (ts *tpceSpec) run(
ctx context.Context, t test.Test, c cluster.Cluster, o tpceCmdOptions,
) (install.RunResultDetails, error) {
cmd := fmt.Sprintf("%s %s", ts.newCmd(o), strings.Join(ts.roachNodeIPFlags, " "))
return c.RunWithDetailsSingleNode(ctx, t.L(), c.Node(ts.loadNode), cmd)
}

func registerTPCE(r registry.Registry) {
type tpceOptions struct {
owner registry.Owner // defaults to test-eng
Expand All @@ -39,7 +109,7 @@ func registerTPCE(r registry.Registry) {

runTPCE := func(ctx context.Context, t test.Test, c cluster.Cluster, opts tpceOptions) {
roachNodes := c.Range(1, opts.nodes)
loadNode := c.Node(opts.nodes + 1)
loadNode := opts.nodes + 1
racks := opts.nodes

t.Status("installing cockroach")
Expand All @@ -50,10 +120,8 @@ func registerTPCE(r registry.Registry) {
settings := install.MakeClusterSettings(install.NumRacksOption(racks))
c.Start(ctx, t.L(), startOpts, settings, roachNodes)

t.Status("installing docker")
if err := c.Install(ctx, t.L(), loadNode, "docker"); err != nil {
t.Fatal(err)
}
tpceSpec, err := initTPCESpec(ctx, t.L(), c, loadNode, roachNodes)
require.NoError(t, err)

// Configure to increase the speed of the import.
func() {
Expand All @@ -73,27 +141,20 @@ func registerTPCE(r registry.Registry) {

m := c.NewMonitor(ctx, roachNodes)
m.Go(func(ctx context.Context) error {
const dockerRun = `sudo docker run cockroachdb/tpc-e:latest`

roachNodeIPs, err := c.InternalIP(ctx, t.L(), roachNodes)
if err != nil {
return err
}
roachNodeIPFlags := make([]string, len(roachNodeIPs))
for i, ip := range roachNodeIPs {
roachNodeIPFlags[i] = fmt.Sprintf("--hosts=%s", ip)
}

t.Status("preparing workload")
c.Run(ctx, loadNode, fmt.Sprintf("%s --customers=%d --racks=%d --init %s",
dockerRun, opts.customers, racks, roachNodeIPFlags[0]))
tpceSpec.init(ctx, t, c, tpceCmdOptions{
customers: opts.customers,
racks: racks,
})

t.Status("running workload")
duration := 2 * time.Hour
threads := opts.nodes * opts.cpus
result, err := c.RunWithDetailsSingleNode(ctx, t.L(), loadNode,
fmt.Sprintf("%s --customers=%d --racks=%d --duration=%s --threads=%d %s",
dockerRun, opts.customers, racks, duration, threads, strings.Join(roachNodeIPFlags, " ")))
result, err := tpceSpec.run(ctx, t, c, tpceCmdOptions{
customers: opts.customers,
racks: racks,
duration: 2 * time.Hour,
threads: opts.nodes * opts.cpus,
})
if err != nil {
t.Fatal(err.Error())
}
Expand Down

0 comments on commit 01f3b26

Please sign in to comment.