Skip to content

Commit

Permalink
GO-4693 Add os projection (#1942)
Browse files Browse the repository at this point in the history
  • Loading branch information
fat-fellow authored Dec 12, 2024
1 parent a5257b5 commit f4ad2c8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/perfstand/internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"
Expand All @@ -22,6 +23,7 @@ const NetworkStaging = "staging"
type Event struct {
MethodName string `json:"method_name"`
Duration int64 `json:"duration"`
Os string `json:"os"`
MiddlewareVersion string `json:"middleware_version"`
Network string `json:"network"`
}
Expand All @@ -35,6 +37,16 @@ func GetMiddlewareVersion() (string, error) {
return middlewareVersion, nil
}

func GetOs() (string, error) {
if runtime.GOOS == "windows" {
return "windows", nil
}
if runtime.GOOS == "darwin" {
return "macos", nil
}
return "", fmt.Errorf("unknown os " + runtime.GOOS)
}

func SendResultsToHttp(apiKey string, events []Event) error {
payload := map[string]interface{}{
"api_key": apiKey,
Expand Down Expand Up @@ -242,13 +254,18 @@ func Convert(res map[string]*MethodResult) ([]Event, error) {
if err != nil {
return nil, err
}
osName, err := GetOs()
if err != nil {
return nil, err
}

var events []Event
for _, value := range res {
for _, duration := range value.Measurements {
events = append(events, Event{
MethodName: value.MethodName,
Duration: duration,
Os: osName,
MiddlewareVersion: middlewareVersion,
Network: value.NetworkMode,
})
Expand Down

0 comments on commit f4ad2c8

Please sign in to comment.