hanahmily commented on code in PR #1047: URL: https://github.com/apache/skywalking-banyandb/pull/1047#discussion_r3058103237
########## test/integration/replication/benchmark/kube.go: ########## @@ -0,0 +1,217 @@ +// Licensed to Apache Software Foundation (ASF) under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Apache Software Foundation (ASF) licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package benchmark + +import ( + "context" + "encoding/json" + "fmt" + "sort" + "strings" +) + +const ( + componentLiaison = "liaison" + componentEtcd = "etcd" Review Comment: Please remove the etcd component. Instead, use the banyandb's default property-based schema repo and DNS-based service discovery. ########## test/integration/replication/benchmark/runner.go: ########## @@ -0,0 +1,228 @@ +// Licensed to Apache Software Foundation (ASF) under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Apache Software Foundation (ASF) licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package benchmark + +import ( + "context" + "fmt" + "time" + + "google.golang.org/grpc" + + "github.com/apache/skywalking-banyandb/pkg/test" +) + +func runBenchmarkRF(ctx context.Context, repoRoot string, cfg Config, rf int) (RFResult, error) { + result := RFResult{ReplicationFactor: rf} + if err := cfg.Validate(); err != nil { + return result, err + } + namespace := fmt.Sprintf("banyandb-bench-rf-%d-%d", rf, time.Now().UnixNano()) + + if err := installChart(ctx, repoRoot, namespace, cfg); err != nil { + return result, err + } + defer func() { + _ = uninstallChart(ctx, namespace) + _ = deleteNamespace(ctx, namespace) + }() + + if _, err := runCommand(ctx, "kubectl", "-n", namespace, "wait", "--for=condition=ready", "pod", "--all", "--timeout=600s"); err != nil { + return result, err + } + + pods, err := fetchPods(ctx, namespace) + if err != nil { + return result, err + } + services, err := fetchServices(ctx, namespace) + if err != nil { + return result, err + } + dataPods := discoverDataPods(pods) + liaisonPods := discoverLiaisonPods(pods) + if len(dataPods) == 0 { + return result, fmt.Errorf("no data pods discovered in namespace %s", namespace) + } + if len(liaisonPods) == 0 { + return result, fmt.Errorf("no liaison pods discovered in namespace %s", namespace) + } + grpcService, err := discoverGRPCService(services) + if err != nil { + return result, err + } + + grpcPorts, err := test.AllocateFreePorts(1) + if err != nil { + return result, err + } + grpcPF, err := startPortForward(ctx, namespace, "svc/"+grpcService.Metadata.Name, grpcPorts[0], 17912) + if err != nil { + return result, err + } + defer grpcPF.Stop() + + conn, err := connectGRPC(ctx, fmt.Sprintf("127.0.0.1:%d", grpcPorts[0])) + if err != nil { + return result, err + } + defer conn.Close() + rfCtx := context.WithoutCancel(ctx) + + err = createMeasureSchema(rfCtx, conn, rf) + if err != nil { + return result, err + } + baseTime := time.Now().Truncate(time.Second) + + liaisonEndpoints, liaisonStop, err := startMetricsPortForwards(ctx, namespace, liaisonPods) + if err != nil { + return result, err + } + defer liaisonStop() + dataEndpoints, dataStop, err := startMetricsPortForwards(ctx, namespace, dataPods) + if err != nil { + return result, err + } + defer dataStop() + + writeStats, writeResources, err := runWritePhase(ctx, conn, cfg, baseTime, liaisonEndpoints, dataEndpoints) + if err != nil { + return result, err + } + result.Write = writeStats + result.Resources.WritePhase = writeResources + + if err = waitForVisibility(ctx, conn, baseTime, cfg.PointsPerEntity); err != nil { + return result, err + } + + readStats, readResources, err := runReadPhase(rfCtx, conn, cfg, baseTime, liaisonEndpoints, dataEndpoints) + if err != nil { + return result, err + } + result.Read = readStats + result.Resources.ReadPhase = readResources + return result, nil +} + +func startMetricsPortForwards(ctx context.Context, namespace string, pods []kubePod) ([]string, func(), error) { + ports, err := test.AllocateFreePorts(len(pods)) + if err != nil { + return nil, nil, err + } + endpoints := make([]string, 0, len(pods)) + portForwards := make([]*portForward, 0, len(pods)) + for i, pod := range pods { + pf, err := startPortForward(ctx, namespace, "pod/"+pod.Metadata.Name, ports[i], 2121) + if err != nil { + for _, p := range portForwards { + p.Stop() + } + return nil, nil, err + } + portForwards = append(portForwards, pf) + endpoints = append(endpoints, fmt.Sprintf("http://127.0.0.1:%d/metrics", ports[i])) + } + stop := func() { + for _, p := range portForwards { + p.Stop() + } + } + return endpoints, stop, nil +} + +func runWritePhase(ctx context.Context, conn *grpc.ClientConn, cfg Config, base time.Time, liaisonEndpoints, dataEndpoints []string) (WriteResult, ResourcePhase, error) { + lSeriesCh, lErrCh, lCancel := startCollector(ctx, cfg.MetricsPollInterval, liaisonEndpoints) + dSeriesCh, dErrCh, dCancel := startCollector(ctx, cfg.MetricsPollInterval, dataEndpoints) + + writeResult, err := writeMeasureData(ctx, conn, cfg, base) + lCancel() + dCancel() + lSeries := <-lSeriesCh + dSeries := <-dSeriesCh + if err != nil { + return WriteResult{}, ResourcePhase{}, err + } + if err := firstError(lErrCh, dErrCh); err != nil { + return WriteResult{}, ResourcePhase{}, err + } + return writeResult, ResourcePhase{ + Liaison: toResourceStats(lSeries), + Data: toResourceStats(dSeries), + }, nil +} + +func runReadPhase(ctx context.Context, conn *grpc.ClientConn, cfg Config, base time.Time, liaisonEndpoints, dataEndpoints []string) (ReadResult, ResourcePhase, error) { + lSeriesCh, lErrCh, lCancel := startCollector(ctx, cfg.MetricsPollInterval, liaisonEndpoints) + dSeriesCh, dErrCh, dCancel := startCollector(ctx, cfg.MetricsPollInterval, dataEndpoints) + + latencies, err := runReadQueries(ctx, conn, cfg, base) + lCancel() + dCancel() + lSeries := <-lSeriesCh + dSeries := <-dSeriesCh + if err != nil { + return ReadResult{}, ResourcePhase{}, err + } + if err := firstError(lErrCh, dErrCh); err != nil { + return ReadResult{}, ResourcePhase{}, err + } + return summarizeLatencies(latencies), ResourcePhase{ + Liaison: toResourceStats(lSeries), + Data: toResourceStats(dSeries), + }, nil +} + +func startCollector(parent context.Context, interval time.Duration, endpoints []string) (<-chan AggregatedSeries, <-chan error, context.CancelFunc) { + seriesCh := make(chan AggregatedSeries, 1) + errCh := make(chan error, 1) + ctx, cancel := context.WithCancel(parent) + go func() { + series, err := collectSeries(ctx, interval, endpoints) + if err != nil { + errCh <- err + } else { + errCh <- nil + } + seriesCh <- series Review Comment: If the parent context is canceled, collectSeries returns early, then the goroutine sends to both channels. But if cancel() is called before collectSeries returns, the goroutine blocks on seriesCh <- series because the receiver has already returned and closed the channel. ########## test/integration/replication/benchmark/helm.go: ########## @@ -0,0 +1,71 @@ +// Licensed to Apache Software Foundation (ASF) under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Apache Software Foundation (ASF) licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package benchmark + +import ( + "context" + "path/filepath" + "strings" +) + +const ( + benchmarkRelease = "banyandb-bench" + localImage = "apache/skywalking-banyandb:latest" Review Comment: Use the image with the commit SHA-256 tag to prevent deploying the wrong image, which would cause the test to pass unexpectedly. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
