Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support send report to a gRPC server #431

Merged
merged 9 commits into from
May 17, 2024

Conversation

lizzy-0323
Copy link
Contributor

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

@CLAassistant
Copy link

CLAassistant commented May 15, 2024

CLA assistant check
All committers have signed the CLA.

@lizzy-0323 lizzy-0323 changed the title Dev feat: support send report to a gRPC server May 15, 2024
@lizzy-0323 lizzy-0323 closed this May 15, 2024
@LinuxSuRen
Copy link
Owner

why closed it?

@lizzy-0323 lizzy-0323 reopened this May 16, 2024
@lizzy-0323
Copy link
Contributor Author

lizzy-0323 commented May 16, 2024

why closed it?

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

@LinuxSuRen LinuxSuRen added the enhancement New feature or request label May 16, 2024
pkg/runner/writer_grpc.go Outdated Show resolved Hide resolved
cmd/run.go Outdated Show resolved Hide resolved
UnimplementedReportWriterServer
}

func (s *ReportServer) SendReportResult(ctx context.Context, req *ReportResultRepeated) (*Empty, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this server?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this server is used for testing, when receiving the report, it will print it.

Copy link

sonarcloud bot commented May 17, 2024

Quality Gate Passed Quality Gate passed

Issues
8 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@LinuxSuRen
Copy link
Owner

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

@lizzy-0323
Copy link
Contributor Author

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

Copy link
Owner

@LinuxSuRen LinuxSuRen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

And welcome to be the 21st contributor!

@LinuxSuRen LinuxSuRen merged commit 50798ff into LinuxSuRen:master May 17, 2024
14 of 15 checks passed
@lizzy-0323
Copy link
Contributor Author

LGTM

And welcome to be the 21st contributor!

I'm very glad to contribute to the project!

@LinuxSuRen LinuxSuRen added the ospp 开源之夏 https://summer-ospp.ac.cn/ label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ospp 开源之夏 https://summer-ospp.ac.cn/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support sending test report to a gRPC server
3 participants