Skip to content

Commit

Permalink
Add support for gRPC checks
Browse files Browse the repository at this point in the history
Adds the glue necessary for the agent to start accepting and executing
gRPC checks.
  • Loading branch information
ka3de committed Nov 28, 2023
1 parent adb9589 commit 9e56c40
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
5 changes: 5 additions & 0 deletions internal/prober/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/grafana/synthetic-monitoring-agent/internal/k6runner"
"github.com/grafana/synthetic-monitoring-agent/internal/model"
"github.com/grafana/synthetic-monitoring-agent/internal/prober/dns"
"github.com/grafana/synthetic-monitoring-agent/internal/prober/grpc"
"github.com/grafana/synthetic-monitoring-agent/internal/prober/http"
"github.com/grafana/synthetic-monitoring-agent/internal/prober/icmp"
"github.com/grafana/synthetic-monitoring-agent/internal/prober/k6"
Expand Down Expand Up @@ -86,6 +87,10 @@ func (f proberFactory) New(ctx context.Context, logger zerolog.Logger, check mod
err = fmt.Errorf("k6 checks are not enabled")
}

case sm.CheckTypeGrpc:
p, err = grpc.NewProber(ctx, check.Check, logger)
target = check.Target

default:
return nil, "", fmt.Errorf("unsupported check type")
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/accounting/accounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func GetCheckAccountingClass(check synthetic_monitoring.Check) (string, error) {

case synthetic_monitoring.CheckTypeTraceroute:

case synthetic_monitoring.CheckTypeGrpc:
if check.Settings.Grpc.Tls {
key += "_ssl"
}

default:
return "", ErrUnhandledCheck
}
Expand Down
25 changes: 24 additions & 1 deletion pkg/pb/synthetic_monitoring/checks_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const (
CheckTypeTraceroute CheckType = 4
CheckTypeK6 CheckType = 5
CheckTypeMultiHttp CheckType = 6
CheckTypeGrpc CheckType = 7
)

type CheckClass int32
Expand Down Expand Up @@ -199,6 +200,9 @@ func (c Check) Type() CheckType {
case c.Settings.Multihttp != nil:
return CheckTypeMultiHttp

case c.Settings.Grpc != nil:
return CheckTypeGrpc

default:
panic("unhandled check type")
}
Expand All @@ -210,7 +214,7 @@ func (c Check) Class() CheckClass {

func (c CheckType) Class() CheckClass {
switch c {
case CheckTypeDns, CheckTypeHttp, CheckTypePing, CheckTypeTcp, CheckTypeTraceroute:
case CheckTypeDns, CheckTypeHttp, CheckTypePing, CheckTypeTcp, CheckTypeTraceroute, CheckTypeGrpc:
return CheckClassProtocol

case CheckTypeK6, CheckTypeMultiHttp:
Expand Down Expand Up @@ -289,6 +293,10 @@ func (c Check) validateTarget() error {
// not true that the target must be a valid URL.
// validation of URLs is the responsibility of the MultihttpEntryRequest
return nil

case CheckTypeGrpc:
return validateHostPort(c.Target)

default:
panic("unhandled check type")
}
Expand Down Expand Up @@ -400,6 +408,9 @@ func (c AdHocCheck) Type() CheckType {
case c.Settings.Multihttp != nil:
return CheckTypeMultiHttp

case c.Settings.Grpc != nil:
return CheckTypeGrpc

default:
panic("unhandled check type")
}
Expand Down Expand Up @@ -486,6 +497,9 @@ func (c AdHocCheck) validateTarget() error {
case CheckTypeMultiHttp:
return nil

case CheckTypeGrpc:
return validateHostPort(c.Target)

default:
panic("unhandled check type")
}
Expand Down Expand Up @@ -533,6 +547,11 @@ func (s CheckSettings) Validate() error {
validateFn = s.Multihttp.Validate
}

if s.Grpc != nil {
settingsCount++
validateFn = s.Grpc.Validate
}

if settingsCount != 1 {
return ErrInvalidCheckSettings
}
Expand Down Expand Up @@ -651,6 +670,10 @@ func (s *MultiHttpSettings) Validate() error {
return nil
}

func (s *GrpcSettings) Validate() error {
return nil
}

func hasUniqueValues[U any, V comparable](slice []U, fn func(U) V) bool {
set := make(map[V]struct{})

Expand Down
12 changes: 8 additions & 4 deletions pkg/pb/synthetic_monitoring/string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9e56c40

Please sign in to comment.