Skip to content

Commit

Permalink
Add CheckClass to identify protocol vs scripted checks
Browse files Browse the repository at this point in the history
Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
  • Loading branch information
mem committed May 30, 2023
1 parent 0b5d449 commit 9f632d1
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 157 deletions.
4 changes: 4 additions & 0 deletions pkg/accounting/accounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func GetCheckAccountingClass(check synthetic_monitoring.Check) (string, error) {
key += "_ssl"
}

case synthetic_monitoring.CheckTypeK6:

case synthetic_monitoring.CheckTypeMultiHttp:

case synthetic_monitoring.CheckTypePing:

case synthetic_monitoring.CheckTypeTcp:
Expand Down
63 changes: 24 additions & 39 deletions pkg/pb/synthetic_monitoring/checks_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// messages used to communicate with synthetic-monitoring-api.
package synthetic_monitoring

//go:generate go run github.com/dmarkham/enumer -type=CheckType,CheckClass -trimprefix=CheckType,CheckClass -transform=snake -output=string.go

import (
"errors"
"fmt"
Expand Down Expand Up @@ -154,50 +156,20 @@ const (
CheckTypeMultiHttp CheckType = 6
)

var (
checkType_name = map[CheckType]string{
CheckTypeDns: "dns",
CheckTypeHttp: "http",
CheckTypePing: "ping",
CheckTypeTcp: "tcp",
CheckTypeTraceroute: "traceroute",
CheckTypeK6: "k6",
CheckTypeMultiHttp: "multi_http",
}

checkType_value = map[string]CheckType{
"dns": CheckTypeDns,
"http": CheckTypeHttp,
"ping": CheckTypePing,
"tcp": CheckTypeTcp,
"traceroute": CheckTypeTraceroute,
"k6": CheckTypeK6,
"multi_http": CheckTypeMultiHttp,
}
)

func (t CheckType) String() string {
str, found := checkType_name[t]
if !found {
panic("unhandled check type")
}
type CheckClass int32

return str
}
const (
CheckClassProtocol CheckClass = 0
CheckClassScripted CheckClass = 1
)

func CheckTypeFromString(in string) (CheckType, bool) {
if checkType, found := checkType_value[in]; found {
return checkType, true
}

// lowercase input, try again
in = strings.ToLower(in)

if checkType, found := checkType_value[in]; found {
return checkType, true
ct, err := CheckTypeString(in)
if err != nil {
return 0, false
}

return 0, false
return ct, true
}

func (c Check) Type() CheckType {
Expand Down Expand Up @@ -228,6 +200,19 @@ func (c Check) Type() CheckType {
}
}

func (c Check) Class() CheckClass {
switch c.Type() {
case CheckTypeDns, CheckTypeHttp, CheckTypePing, CheckTypeTcp, CheckTypeTraceroute:
return CheckClassProtocol

case CheckTypeK6, CheckTypeMultiHttp:
return CheckClassScripted

default:
panic("unhandled check class")
}
}

func (c Check) Validate() error {
if c.TenantId == BadID {
return ErrInvalidTenantId
Expand Down

0 comments on commit 9f632d1

Please sign in to comment.