Skip to content

Commit

Permalink
Add user logs URL to linear
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar committed Jun 5, 2024
1 parent d1fde68 commit 1d20d7c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
46 changes: 46 additions & 0 deletions grafana.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"encoding/json"
"net/url"
"strconv"
"time"
)

type grafanaQuery struct {
Expr string `json:"expr"`
QueryType string `json:"queryType"`
}

type grafanaRange struct {
From string `json:"from"`
To string `json:"to"`
}

type grafanaRequest struct {
Datasource string `json:"datasource"`
Queries []grafanaQuery `json:"queries"`
Range grafanaRange `json:"range"`
}

func makeGrafanaLogsURL(username string) (string, error) {
now := time.Now().UTC()
from := now.Add(-time.Minute * 15)
to := now.Add(time.Minute * 15)

expr := `{username="` + username + `",env="prod"} | unpack`
req := grafanaRequest{
Datasource: "f21b0c24-8614-42eb-827b-fcbd230dd8d3",
Queries: []grafanaQuery{{expr, "range"}},
Range: grafanaRange{
From: strconv.Itoa(int(from.UnixMilli())),
To: strconv.Itoa(int(to.UnixMilli())),
},
}
jsonStr, err := json.Marshal(req)
if err != nil {
return "", err
}
url := "https://grafana.beeper-tools.com/explore?orgId=1&left=" + url.QueryEscape(string(jsonStr))
return url, nil
}
5 changes: 5 additions & 0 deletions submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,11 @@ func (s *submitServer) buildGenericIssueRequest(ctx context.Context, p parsedPay
fmt.Fprintf(bodyBuf, "\n### [Rageshake Logs](%s)", listingURL)
if isVerified {
fmt.Fprintf(bodyBuf, " | [User Admin](https://admin.beeper.com/user/%s)", username)
if userLogsURL, err := makeGrafanaLogsURL(username); err != nil {
zerolog.Ctx(ctx).Err(err).Msg("Error generating grafana URL")
} else {
fmt.Fprintf(bodyBuf, " | [User Logs](%s)", userLogsURL)
}
}

title = buildReportTitle(username, p)
Expand Down

0 comments on commit 1d20d7c

Please sign in to comment.