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

Add grpc diagnostic #3394

Merged
merged 1 commit into from Aug 17, 2023

Conversation

josedonizetti
Copy link
Collaborator

@josedonizetti josedonizetti commented Aug 16, 2023

1. Explain what the PR does

This PR is part of the work to support a v1 for GRPC. This PR implements the diagnostic rpc service. I've tested with -race no data races were found here.

2. Explain how to test it

The below clients can be used to test the GRPC API:

import (
        pb "github.com/aquasecurity/tracee/types/api/v1beta1"
)
func main() {
        var opts []grpc.DialOption
        opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))

        conn, err := grpc.Dial(":4466", opts...)
        if err != nil {
                log.Fatalf("fail to dial: %v", err)
        }

        client := pb.NewDiagnosticServiceClient(conn)

        changelog := &pb.ChangeLogLevelRequest{
                Level: pb.LogLevel_Info,
        }

        _, err = client.ChangeLogLevel(context.Background(), changelog)
        if err != nil {
                log.Fatal(err)
        }

        fmt.Println("Log level changed to DEBUG")
}
func main() {
	var opts []grpc.DialOption
	opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))

	conn, err := grpc.Dial(":4466", opts...)
	if err != nil {
		log.Fatalf("fail to dial: %v", err)
	}

	client := pb.NewDiagnosticServiceClient(conn)

	stacktrace, err := client.GetStacktrace(context.Background(), &pb.GetStacktraceRequest{})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(string(stacktrace.Stacktrace))
}
func main() {
	var opts []grpc.DialOption
	opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))

	conn, err := grpc.Dial(":4466", opts...)
	if err != nil {
		log.Fatalf("fail to dial: %v", err)
	}

	client := pb.NewDiagnosticServiceClient(conn)

	metrics, err := client.GetMetrics(context.Background(), &pb.GetMetricsRequest{})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("EventCount", metrics.EventCount)
	fmt.Println("EventsFiltered", metrics.EventsFiltered)
	fmt.Println("NetCapCount", metrics.NetCapCount)
	fmt.Println("BPFLogsCount", metrics.BPFLogsCount)
	fmt.Println("ErrorCount", metrics.ErrorCount)
	fmt.Println("LostEvCount", metrics.LostEvCount)
	fmt.Println("LostWrCount", metrics.LostWrCount)
	fmt.Println("LostNtCapCount", metrics.LostNtCapCount)
	fmt.Println("LostBPFLogsCount", metrics.LostBPFLogsCount)
}

3. Other comments

depends on #3395

@@ -88,7 +88,7 @@ const (
// Tracee offers aggregation and filtering support on top of any logger implementation complying to it's interface.
type LoggingConfig struct {
Logger LoggerInterface
loggerConfig LoggerConfig
LoggerConfig LoggerConfig
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't like this refactoring, but it had to be done because flags create a LoggingConfig, and if this field wasn't exposed it would be nil, generating a panic when you change the log level. But it is weird to allow the user to create a struct but have methods depending on it, we should enforce it by perhaps having these fields private and a constructor function. Nonetheless, I'll create a separate issue to handle this refactor.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps, in the future, using a constructor with options pattern.

go.mod Outdated Show resolved Hide resolved
@josedonizetti josedonizetti marked this pull request as ready for review August 16, 2023 22:28
Copy link
Member

@geyslan geyslan left a comment

Choose a reason for hiding this comment

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

LGTM

Tested the new three GPRC services.

image

image

For debug ChangeLogLevel I've put a dummy logger.Debugw() and tested changing it to Debug and returning it to Info.

@@ -88,7 +88,7 @@ const (
// Tracee offers aggregation and filtering support on top of any logger implementation complying to it's interface.
type LoggingConfig struct {
Logger LoggerInterface
loggerConfig LoggerConfig
LoggerConfig LoggerConfig
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps, in the future, using a constructor with options pattern.

@josedonizetti josedonizetti merged commit 00db86d into aquasecurity:main Aug 17, 2023
26 checks passed
@josedonizetti josedonizetti deleted the add-grpc-diagnostic branch August 17, 2023 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants