Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions example/compat/logr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package example

import (
"fmt"
"testing"

"github.com/go-logr/logr/testr"
)

func TestLogrTestr(t *testing.T) {
logger := testr.NewWithOptions(t, testr.Options{Verbosity: 2})

logger.Info("starting test", "test", "logr")
logger.V(0).Info("V(0).info")
logger.V(1).Info("V(1).info")
logger.Error(fmt.Errorf("test error"), "error")

childLogger := logger.WithValues("request_id", "12345")
childLogger.Info("child logger message")

loggerWithName := childLogger.WithName("child")
loggerWithName.Info("named child logger")
}

func BenchmarkLogrTestr(b *testing.B) {
t := &testing.T{}
logger := testr.New(t)

for b.Loop() {
// Log operations within the benchmark
logger.Info("benchmark message")
logger.V(1).Info("verbose benchmark")
childLogger := logger.WithValues("id", "test")
childLogger.Info("child message")
}
}
55 changes: 55 additions & 0 deletions example/compat/stdr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package example

import (
"errors"
"log"
"testing"

"github.com/go-logr/stdr"
)

func TestStdr(t *testing.T) {
logger := stdr.New(log.Default())

logger.Info("info message", "key", "value")
logger.Error(errors.New("test error"), "error message")

namedLogger := logger.WithName("myapp")
namedLogger.Info("named logger message")

childLogger := namedLogger.WithValues("request_id", "12345")
childLogger.Info("child logger message")

childLogger.V(1).Info("verbose message")
}

func TestStdrWithOptions(t *testing.T) {
options := stdr.Options{
LogCaller: stdr.Error,
Depth: 1,
}

logger := stdr.NewWithOptions(log.Default(), options)

logger.Info("info with options")
logger.Error(errors.New("err"), "error with options")
}

func BenchmarkStdr(b *testing.B) {
logger := stdr.New(log.Default())

for b.Loop() {
logger.Info("benchmark message", "iteration", b.N)
childLogger := logger.WithValues("id", "test")
childLogger.Info("child message")
}
}

func BenchmarkStdrWithName(b *testing.B) {
logger := stdr.New(log.Default()).WithName("bench")

for b.Loop() {
logger.Info("named benchmark", "count", b.N)
logger.V(1).Info("verbose benchmark")
}
}
4 changes: 3 additions & 1 deletion example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ go 1.24.3

require (
github.com/frankban/quicktest v1.14.6
github.com/go-logr/logr v1.4.3
github.com/go-logr/stdr v1.2.2
github.com/stretchr/testify v1.11.1
github.com/thejerf/slogassert v0.3.4
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
8 changes: 7 additions & 1 deletion example/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down
1 change: 1 addition & 0 deletions go-runner/src/builder/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ mod tests {
#[case::example_with_main("example-with-main")]
#[case::example_with_dot_go_folder("example-with-dot-go-folder")]
#[case::example_with_test_package("example-with-test-package")]
#[case::example_with_excluded_names("example-with-excluded-names")]
#[test_log::test]
fn test_discover_benchmarks(#[case] project_name: &str) {
let project_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
Expand Down
8 changes: 8 additions & 0 deletions go-runner/src/builder/patcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ impl Patcher {
"github.com/frankban/quicktest",
"\"github.com/CodSpeedHQ/codspeed-go/pkg/quicktest\"",
);
find_replace_range(
"github.com/go-logr/logr",
"\"github.com/CodSpeedHQ/codspeed-go/pkg/logr\"",
);
find_replace_range(
"github.com/go-logr/stdr",
"\"github.com/CodSpeedHQ/codspeed-go/pkg/stdr\"",
);

// Apply replacements in reverse order to avoid shifting positions
for (range, replacement) in replacements
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
source: go-runner/src/builder/discovery.rs
expression: packages
---
[
{
"raw_package": "[raw_package]",
"benchmarks": [
{
"name": "BenchmarkProcessData",
"module_path": "example-with-excluded-names",
"import_alias": "benchmarkprocessdata_11906522046485331356",
"qualified_name": "benchmarkprocessdata_11906522046485331356.BenchmarkProcessData",
"file_path": "main_test.go",
"is_external": false
}
]
}
]
1 change: 1 addition & 0 deletions go-runner/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fn assert_results_snapshots(profile_dir: &Path, project_name: &str) {
#[case::example_with_vendor("example-with-vendor")]
#[case::example_with_test_package("example-with-test-package")]
#[case::example_with_replace("example-with-replace")]
#[case::example_with_excluded_names("example-with-excluded-names")]
#[test_log::test]
fn test_build_and_run(#[case] project_name: &str) {
let project_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
source: go-runner/src/integration_tests.rs
expression: results
---
[
{
"creator": {
"name": "codspeed-go",
"version": "[version]",
"pid": "[pid]"
},
"instrument": {
"type": "walltime"
},
"benchmarks": [
{
"name": "BenchmarkProcessData",
"uri": "go-runner/testdata/projects/example-with-excluded-names/main_test.go::BenchmarkProcessData",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
"max_time_ns": null,
"max_rounds": null
},
"stats": "[stats]"
}
]
}
]
2 changes: 1 addition & 1 deletion go-runner/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io;
use std::path::{Path, PathBuf};

pub fn copy_dir_recursively(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
let excludes = vec!["node_modules".into(), "target".into()];
let excludes = vec![];
let includes = vec![];
dircpy::copy_dir_advanced(src, dst, true, true, true, excludes, includes)?;
Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module example-with-excluded-names

go 1.24
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tools

// Process processes data using target and node_modules utilities
func Process(data string) string {
return processTarget(data) + processNodeModules(data)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tools

// NodeModulesHelper is a helper function accessed during testing
func NodeModulesHelper() string {
return "node_modules"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tools

// TargetHelper is a helper function accessed during testing
func TargetHelper() string {
return "target"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tools

// processTarget is called from target.go
func processTarget(data string) string {
return "target:" + data
}

// processNodeModules is called from node_modules.go
func processNodeModules(data string) string {
return "|nm:" + data
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "example-with-excluded-names/internal/tools"

func ProcessData(data string) string {
return tools.Process(data)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"testing"
)

func BenchmarkProcessData(b *testing.B) {
for i := 0; i < b.N; i++ {
ProcessData("example-target")
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/CodSpeedHQ/codspeed-go
go 1.24.3

require (
github.com/go-logr/logr v1.4.3
github.com/google/go-cmp v0.7.0
github.com/kr/pretty v0.3.1
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down
23 changes: 21 additions & 2 deletions pkg/fork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ function replace_in_go_files() {
function fix_project() {
rm -rf .git go.mod go.sum

replace_in_go_files '"testing"' 'testing "github.com/CodSpeedHQ/codspeed-go/compat/testing"'
replace_in_go_files '"testing/slogtest"' 'slogtest "github.com/CodSpeedHQ/codspeed-go/compat/testing/slogtest"'
# Replace imports with patterns that only match in import statements
# Match "testing" at start of line (after whitespace) to avoid string literals
find . -type f -name "*.go" -exec sed -i 's/^[[:space:]]*"testing"$/testing "github.com\/CodSpeedHQ\/codspeed-go\/testing\/testing"/g' {} +
find . -type f -name "*.go" -exec sed -i 's/^[[:space:]]*"testing")/testing "github.com\/CodSpeedHQ\/codspeed-go\/testing\/testing")/g' {} +
find . -type f -name "*.go" -exec sed -i 's/^[[:space:]]*"testing",/testing "github.com\/CodSpeedHQ\/codspeed-go\/testing\/testing",/g' {} +

find . -type f -name "*.go" -exec sed -i 's/^[[:space:]]*"testing\/slogtest"$/slogtest "github.com\/CodSpeedHQ\/codspeed-go\/testing\/testing\/slogtest"/g' {} +
find . -type f -name "*.go" -exec sed -i 's/^[[:space:]]*"testing\/slogtest")/slogtest "github.com\/CodSpeedHQ\/codspeed-go\/testing\/testing\/slogtest")/g' {} +
find . -type f -name "*.go" -exec sed -i 's/^[[:space:]]*"testing\/slogtest",/slogtest "github.com\/CodSpeedHQ\/codspeed-go\/testing\/testing\/slogtest",/g' {} +

go mod tidy
go fmt ./...
Expand All @@ -27,3 +34,15 @@ pushd quicktest
replace_in_go_files '"github.com/frankban/quicktest' '"github.com/CodSpeedHQ/codspeed-go/pkg/quicktest'
fix_project
popd

git clone -b v1.4.3 https://github.com/go-logr/logr.git
pushd logr
replace_in_go_files '"github.com/go-logr/logr' '"github.com/CodSpeedHQ/codspeed-go/pkg/logr'
fix_project
popd

git clone -b v1.2.2 https://github.com/go-logr/stdr.git
pushd stdr
replace_in_go_files '"github.com/go-logr/stdr' '"github.com/CodSpeedHQ/codspeed-go/pkg/stdr'
fix_project
popd
6 changes: 6 additions & 0 deletions pkg/logr/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
32 changes: 32 additions & 0 deletions pkg/logr/.github/workflows/apidiff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run apidiff

on: [ pull_request ]

permissions:
contents: read

jobs:
apidiff:
runs-on: ubuntu-latest
if: github.base_ref
steps:
- name: Install Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
with:
go-version: 1.24.x
- name: Add GOBIN to PATH
run: echo "PATH=$(go env GOPATH)/bin:$PATH" >>$GITHUB_ENV
- name: Install dependencies
run: go install golang.org/x/exp/cmd/apidiff@latest
- name: Checkout old code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.base_ref }}
path: "old"
- name: Checkout new code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: "new"
- name: APIDiff
run: ./_tools/apidiff.sh -d ../old
working-directory: "new"
27 changes: 27 additions & 0 deletions pkg/logr/.github/workflows/assign.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Assign

on:
issues:
types: [opened, reopened]
pull_request_target:
types: [opened, reopened]

permissions:
contents: read

jobs:
assign:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
github.rest.issues.addAssignees({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
assignees: ['thockin', 'pohly']
})
Loading
Loading