-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08261de
commit 46359bf
Showing
27 changed files
with
531 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
name: Setup go | ||
on: [ workflow_call ] | ||
|
||
jobs: | ||
- name: Setup go | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: '^1.13.1' | ||
- name: Install protoc-gen-go-grpc | ||
run: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
name: Setup protobuf | ||
on: [ workflow_call ] | ||
|
||
jobs: | ||
- name: Setup protobuf | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: arduino/setup-protoc@v3 | ||
name: Install Protoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
name: Setup TS | ||
on: [ workflow_call ] | ||
|
||
jobs: | ||
- name: Setup TS | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: pnpm/action-setup@v4 | ||
name: Install pnpm | ||
with: | ||
version: 9 | ||
run_install: false | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
cache: 'pnpm' | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Install protoc-gen-js | ||
run: pnpm install -g protoc-gen-js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Test go | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: | ||
- go/** | ||
- proto/** | ||
pull_request: | ||
branches: [ "main" ] | ||
paths: | ||
- go/** | ||
- proto/** | ||
workflow_dispatch: | ||
|
||
jobs: | ||
- name: Test go | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- uses: ./.github/workflows/template/setup-go-template.yaml | ||
|
||
- name: Test | ||
run: make proto test-go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Test TS | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: | ||
- ts/** | ||
- proto/** | ||
pull_request: | ||
branches: [ "main" ] | ||
paths: | ||
- ts/** | ||
- proto/** | ||
workflow_dispatch: | ||
|
||
jobs: | ||
- name: Test TS | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- uses: ./.github/workflows/template/setup-ts-template.yaml | ||
|
||
- name: Test | ||
run: make proto test-ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
# mode=grpcwebtext prevents client from receiving all the messages at once when using streaming | ||
|
||
.PHONY: build proto go ts | ||
|
||
build: proto go ts | ||
build: proto build-go build-ts | ||
|
||
proto: | ||
protoc --go_out=./go/api --go_opt=paths=source_relative --go-grpc_out=./go/api --go-grpc_opt=paths=source_relative --proto_path ./proto ./proto/api.proto | ||
protoc -I=./proto api.proto \ | ||
--js_out=import_style=commonjs,binary:./ts/components/api \ | ||
--grpc-web_out=import_style=typescript,mode=grpcwebtext:./ts/components/api | ||
|
||
go: | ||
build-go: | ||
cd go && go build . | ||
|
||
ts: | ||
build-ts: | ||
cd ts && pnpm build | ||
|
||
test: test-ts test-go | ||
|
||
test-go: | ||
cd go && go test ./... | ||
|
||
test-ts: | ||
cd ts && npm test | ||
|
||
clean: | ||
rm -rf ts/out | ||
cd go && go clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package assets | ||
|
||
import "embed" | ||
|
||
//go:embed mock-data | ||
var MockData embed.FS |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package general | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"net/http" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
"github.com/moderato-app/live-pprof/api" | ||
"github.com/moderato-app/live-pprof/internal" | ||
) | ||
|
||
type GeneralServer struct { | ||
api.UnimplementedGeneralServer | ||
} | ||
|
||
func NewGeneralServer() *GeneralServer { | ||
return &GeneralServer{} | ||
} | ||
|
||
func (m *GeneralServer) DetectURL(req *api.DetectURLRequest, stream api.General_DetectURLServer) error { | ||
internal.Sugar.Debug("DetectURL req:", req) | ||
wg := sync.WaitGroup{} | ||
mts := [...]internal.MetricsType{ | ||
internal.MetricsTypeHeap, | ||
internal.MetricsTypeCPU, | ||
internal.MetricsTypeAllocs, | ||
internal.MetricsTypeGoroutine, | ||
} | ||
|
||
urls := make([]string, 0, 5) | ||
urls = append(urls, req.Url) | ||
for _, mt := range mts { | ||
url, err := internal.MetricsURL(req.Url, mt, true) | ||
if err != nil { | ||
internal.Sugar.Error(err) | ||
panic(err) | ||
} | ||
urls = append(urls, url) | ||
} | ||
|
||
for _, url := range urls { | ||
wg.Add(1) | ||
go func(url string) { | ||
defer wg.Done() | ||
ctx, cancel := context.WithTimeout(stream.Context(), 3*time.Second) | ||
defer cancel() | ||
result, err := detect(ctx, url) | ||
var errMsg *string | ||
if err != nil { | ||
msg := err.Error() | ||
errMsg = &msg | ||
} | ||
resp := api.DetectURLResponse{ | ||
Endpoint: url, | ||
HttpResult: result, | ||
Error: errMsg, | ||
} | ||
err = stream.Send(&resp) | ||
if err != nil { | ||
internal.Sugar.Error(err) | ||
} | ||
}(url) | ||
} | ||
wg.Wait() | ||
return nil | ||
} | ||
|
||
func detect(ctx context.Context, url string) (*api.HTTPResult, error) { | ||
client := &http.Client{} | ||
internal.Sugar.Debugf("GET %s", url) | ||
|
||
method := http.MethodGet | ||
|
||
// don't fetch /profile endpoint since only returns data in pb.gz format | ||
if strings.Contains(url, "/profile?seconds=") { | ||
method = http.MethodHead | ||
} | ||
req, err := http.NewRequestWithContext(ctx, method, url, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer func() { _ = resp.Body.Close() }() | ||
|
||
data, err := io.ReadAll(resp.Body) | ||
|
||
if resp.StatusCode < 200 || resp.StatusCode > 399 { | ||
internal.Sugar.Info("resp.Body: \n" + string(data)) | ||
} | ||
|
||
bodyStr := string(data) | ||
|
||
return &api.HTTPResult{ | ||
StatusCode: int32(resp.StatusCode), | ||
StatusText: resp.Status, | ||
Body: &bodyStr, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.