Compare commits

...

17 Commits

Author SHA1 Message Date
grambbledook
539553f3ef run with toolexec
Some checks failed
test-ci-instrumentation-workflow / build (push) Has been cancelled
2025-12-17 19:37:58 +01:00
grambbledook
a7d91b66e8 test run win latest api 2025-12-17 17:00:33 +01:00
grambbledook
fe1d0ea060 add step number to tracing params
Some checks failed
test-ci-instrumentation-workflow / build (push) Has been cancelled
2025-12-11 19:10:59 +01:00
grambbledook
80887ca570 set the tracing id ocrrectly 2025-12-11 19:09:47 +01:00
grambbledook
35a2c187ea rename wf 2025-12-11 19:09:47 +01:00
grambbledook
cf3f5d2309 get ids 2025-12-11 19:09:47 +01:00
grambbledook
7648fa81b3 run grafana build with instrumentation 2025-12-11 19:09:47 +01:00
grambbledook
b680bb527a fix cmd 2025-12-11 19:09:47 +01:00
grambbledook
ba4ef80c8a run go-plugin-cache 2025-12-11 19:09:47 +01:00
grambbledook
77cc8008e1 add default log 2025-12-11 19:09:47 +01:00
grambbledook
a70d8eca68 add args tp logs 2025-12-11 19:09:47 +01:00
grambbledook
b74856c857 minor fix 2025-12-11 19:09:47 +01:00
grambbledook
108df86698 cat toolexec.log 2025-12-11 19:09:47 +01:00
grambbledook
815a4aac59 log to file 2025-12-11 19:09:47 +01:00
grambbledook
97aeb6be2e change foo output 2025-12-11 19:09:47 +01:00
grambbledook
c87df1304f update foo 2025-12-11 19:09:47 +01:00
grambbledook
fc01f9a032 run go foo during the buiild 2025-12-11 19:09:47 +01:00
4 changed files with 226 additions and 1 deletions

View File

@@ -0,0 +1,107 @@
name: test-ci-instrumentation-workflow
on:
push:
branches:
- grambbledook/test-toolexec-instrumentation
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Checkout Go Cache Plugin
uses: actions/checkout@v5
with:
repository: 'grafana/go-cache-plugin'
ref: grambbledook/local-cache-and-metrics
persist-credentials: false
path: gocacheplugin
- name: Checkout Go Cache Plugin - toolexec
uses: actions/checkout@v5
with:
repository: 'grafana/go-cache-plugin'
ref: grambbledook/toolexec
persist-credentials: false
path: gocacheplugin-toolexec
- name: Setup Go
uses: actions/setup-go@v6.0.0
with:
go-version-file: go.mod
cache: true
- name: Build Go Cache Plugin
run: |
cd ./gocacheplugin/cmd/go-cache-plugin
GOWORK=off go build -o go-cache-plugin
cd ../../..
cd ./gocacheplugin-toolexec/cmd/go-toolexec
GOWORK=off go build -o go-toolexec
cd ../../..
cp ./gocacheplugin/cmd/go-cache-plugin/go-cache-plugin ./
cp ./gocacheplugin-toolexec/cmd/go-toolexec/go-toolexec ./
- name: Start Go Cache Plugin
env:
GOCACHE_LOCAL_ONLY: true
GOCACHE_DIR: /tmp/gocache
GOCACHE_MODPROXY_NOCACHE: true
GOCACHE_ENABLE_TRACING: true
GOCACHE_TRACING_TRACE_FILE: trace-modcache.log
# OTEL_COLLECTOR_ADDRESS: localhost:4319
RUN_ID: ${{ github.run_id }}
RUN_ATTEMPT: ${{ github.run_attempt }}
JOB_NAME: ${{ github.job }}
STEP_NAME: Build Grafana
STEP_NUMBER: 8
run: |
./go-cache-plugin serve --plugin 5930 --http=localhost:5970 --modproxy &
echo $! > go-cache-plugin.pid
- name: Build Grafana
continue-on-error: true
env:
GOCACHE_LOCAL_ONLY: true
GOCACHE_DIR: /tmp/gocache
GOCACHE_ENABLE_TRACING: true
GOCACHE_TRACING_TRACE_FILE: trace-gocache.log
TOOLEXEC_TRACING_TRACE_FILE: trace-toolexec.log
RUN_ID: ${{ github.run_id }}
RUN_ATTEMPT: ${{ github.run_attempt }}
JOB_NAME: ${{ github.job }}
STEP_NAME: Build Grafana
STEP_NUMBER: 8
run: |
GOPROXY=http://localhost:5970/mod GOCACHEPROG="./go-cache-plugin connect 5930" make build-go
- name: Cleanup
run: |
kill $(cat go-cache-plugin.pid)
- name: Cat GOMOD traces
run: |
echo "====GO MODPROXY TRACES====="
cat trace-modcache.log
echo "==========================="
- name: Cat GOCACHEPROG traces
run: |
echo "====GO GOCACHEPROG TRACES====="
cat trace-gocache.log
echo "=============================="
- name: Cat GOTOOLEXEC traces
run: |
echo "====GO GOTOOLEXEC TRACES====="
cat trace-toolexec.log
echo "============================="

3
goinst/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module goinst
go 1.25.3

115
goinst/main.go Normal file
View File

@@ -0,0 +1,115 @@
package main
import (
"log"
"os"
"os/exec"
"strings"
"time"
)
var (
Asm = "asm"
Compile = "compile"
Link = "link"
)
var logger *log.Logger
func main() {
if len(os.Args) < 2 {
log.Fatal("Usage: toolexec <tool> [args...]")
}
f, err := os.OpenFile("toolexec.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()
logger = log.New(f, "", log.LstdFlags)
tool := os.Args[1]
args := os.Args[2:]
start := time.Now()
cmd := exec.Command(tool, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
elapsed := time.Since(start)
switch getTool(tool) {
case Asm:
printAsm(elapsed)
case Compile:
printCompile(elapsed)
case Link:
printLink(elapsed)
default:
printDefault(elapsed)
}
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
os.Exit(exitErr.ExitCode())
} else {
logger.Fatal("Error:", err)
}
}
}
func printAsm(elapsed time.Duration) {
logger.Println("==========Asm=========")
logger.Printf(" tool: %s", Asm)
logger.Printf(" package: %s", os.Args[len(os.Args)-1])
logger.Printf(" elapsed: %s", elapsed)
logger.Println("======================")
logger.Println("")
}
func printCompile(elapsed time.Duration) {
logger.Println("========Compile=======")
logger.Printf(" tool: %s", Compile)
logger.Printf(" package: %s", getPackage(os.Args))
logger.Printf(" elapsed: %s", elapsed)
logger.Println("======================")
logger.Println("")
}
func printLink(elapsed time.Duration) {
logger.Println("========LINK========")
logger.Printf(" tool: %s", Link)
logger.Printf(" package: %s", os.Args[len(os.Args)-1])
logger.Printf(" elapsed: %s", elapsed)
logger.Println("======================")
logger.Println("")
}
func printDefault(elapsed time.Duration) {
logger.Println("========Default========")
logger.Println(" args: %v", os.Args)
logger.Println("")
logger.Printf(" elapsed: %s", elapsed)
logger.Println("======================")
logger.Println("")
}
func getTool(tool string) string {
parts := strings.Split(tool, "/")
return parts[len(parts)-1]
}
func getPackage(args []string) string {
for i, v := range args {
if i+1 == len(args) {
break
}
if v == "-p" {
return args[i+1]
}
}
return "unknown"
}

View File

@@ -207,7 +207,7 @@ func doBuild(binaryName, pkg string, opts BuildOpts) error {
// We should not publish Grafana as a Go module, disabling vcs changes the version to (devel)
// and works better with SBOM and Vulnerability Scanners.
args = append(args, "-buildvcs=false")
args = append(args, "-toolexec=\"./go-toolexec\"")
args = append(args, "-o", binary)
args = append(args, pkg)