api-testing icon indicating copy to clipboard operation
api-testing copied to clipboard

feat: support send report to a gRPC server

Open lizzy-0323 opened this issue 1 year ago • 4 comments

What type of PR is this?

feat: support send report to a gRPC server What this PR does / why we need it: User can send report to a gRPC server with reflection. Which issue(s) this PR fixes:

Fixes #92

lizzy-0323 avatar May 15 '24 15:05 lizzy-0323

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 15 '24 15:05 CLAassistant

why closed it?

LinuxSuRen avatar May 16 '24 00:05 LinuxSuRen

why closed it?

sry, commit record may be a bit confusing, please check it first

lizzy-0323 avatar May 16 '24 02:05 lizzy-0323

I tried to test it but failed. Please let me know if I missed anything.

atest run --report grpc -p sample/testsuite-gitee.yaml --report-dest 127.0.0.1:7070/writer_templates.ReportWriter/SendReportResult
2024-05-17T04:33:56.903Z        INFO    loader  testing/loader_file.go:140      sample/testsuite-gitee.yaml      {"pattern": 1}
found suites: 1
start to run: 'stargazers'
start to send request to https://gitee.com/api/v5/repos/linuxsuren/api-testing/stargazers
start to run: 'branches'
start to send request to https://gitee.com/api/v5/repos/linuxsuren/api-testing/branches
start to run: 'branch'
start to send request to https://gitee.com/api/v5/repos/linuxsuren/api-testing/branches/feat/metrics
2024-05-17T04:34:00.010Z        INFO    run     cmd/run.go:300  routing end with        {"time": "3.106349975s"}
2024/05/17 04:34:00 will send report to:127.0.0.1:7070
failed to Output all reports proto: not found
Consumed: 3.108572285s

LinuxSuRen avatar May 17 '24 04:05 LinuxSuRen

I tried to test it but failed. Please let me know if I missed anything.

atest run --report grpc -p sample/testsuite-gitee.yaml --report-dest 127.0.0.1:7070/writer_templates.ReportWriter/SendReportResult
2024-05-17T04:33:56.903Z        INFO    loader  testing/loader_file.go:140      sample/testsuite-gitee.yaml      {"pattern": 1}
found suites: 1
start to run: 'stargazers'
start to send request to https://gitee.com/api/v5/repos/linuxsuren/api-testing/stargazers
start to run: 'branches'
start to send request to https://gitee.com/api/v5/repos/linuxsuren/api-testing/branches
start to run: 'branch'
start to send request to https://gitee.com/api/v5/repos/linuxsuren/api-testing/branches/feat/metrics
2024-05-17T04:34:00.010Z        INFO    run     cmd/run.go:300  routing end with        {"time": "3.106349975s"}
2024/05/17 04:34:00 will send report to:127.0.0.1:7070
failed to Output all reports proto: not found
Consumed: 3.108572285s

I think you need to start a grpc test server with reflection locally, like this:

package main

import (
	"fmt"
	"log"
	"net"

	testWriter "github.com/linuxsuren/api-testing/pkg/runner/writer_templates"
	"google.golang.org/grpc"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/reflection"
	"google.golang.org/grpc/status"
)
func main() {
	s := grpc.NewServer()
	testServer := &testWriter.ReportServer{}
	testWriter.RegisterReportWriterServer(s, testServer)
	reflection.RegisterV1(s)
	lis, err := net.Listen("tcp", ":7070")
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	fmt.Println("Server listening on port: 7070")

	if err := s.Serve(lis); err != nil {
		status.Errorf(codes.Unknown, "serve error: %v", err)
	}
}

and then, run:

atest run --report grpc -p sample/testsuite-gitee.yaml --report-dest 127.0.0.1:7070/writer_templates.ReportWriter/SendReportResult

I can get result like this:

Server listening on port: 7070
2024/05/17 13:21:08 Received report: Name:"stargazers" API:"GET https://gitee.com/api/v5/repos/linuxsuren/api-testing/stargazers" Count:1 Average:1346667166 Max:1346667166 Min:1346667166 QPS:1
2024/05/17 13:21:08 Received report: Name:"branch" API:"GET https://gitee.com/api/v5/repos/linuxsuren/api-testing/branches/feat/metrics" Count:1 Average:309262250 Max:309262250 Min:309262250
2024/05/17 13:21:08 Received report: Name:"branches" API:"GET https://gitee.com/api/v5/repos/linuxsuren/api-testing/branches" Count:1 Average:297139625 Max:297139625 Min:297139625

lizzy-0323 avatar May 17 '24 05:05 lizzy-0323

LGTM

And welcome to be the 21st contributor!

I'm very glad to contribute to the project!

lizzy-0323 avatar May 17 '24 05:05 lizzy-0323