-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metrics: add build command duration metric
This adds a build duration metric for the build command with attributes related to the buildx driver, the error type (if any), and which options were used to perform the build from a subset of the options. This also refactors some of the utility methods used by the git tool to determine filepaths into its own separate package so they can be reused in another place. Also adds a test to ensure the resource is initialized correctly and doesn't error. The otel handler logging message is suppressed on buildx invocations so we never see the error if there's a problem with the schema url. It's so easy to mess up the schema url when upgrading OTEL that we need a proper test to make sure we haven't broken the functionality. Signed-off-by: Jonathan A. Sternberg <[email protected]>
- Loading branch information
1 parent
082d5d7
commit 34a406a
Showing
11 changed files
with
175 additions
and
26 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
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
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
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
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
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
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,33 @@ | ||
package metricutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/otel" | ||
) | ||
|
||
func TestResource(t *testing.T) { | ||
setErrorHandler(t) | ||
|
||
// Ensure resource creation doesn't result in an error. | ||
// This is because the schema urls for the various attributes need to be | ||
// the same, but it's really easy to import the wrong package when upgrading | ||
// otel to anew version and the buildx CLI swallows any visible errors. | ||
res := Resource() | ||
|
||
// Ensure an attribute is present. | ||
assert.True(t, res.Set().HasValue("telemetry.sdk.version"), "resource attribute missing") | ||
} | ||
|
||
func setErrorHandler(tb testing.TB) { | ||
tb.Helper() | ||
|
||
errorHandler := otel.GetErrorHandler() | ||
otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) { | ||
tb.Errorf("otel error: %s", err) | ||
})) | ||
tb.Cleanup(func() { | ||
otel.SetErrorHandler(errorHandler) | ||
}) | ||
} |
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,15 @@ | ||
package osutil | ||
|
||
import "os" | ||
|
||
// GetWd retrieves the current working directory. | ||
// | ||
// On Windows, this function will return the long path name | ||
// version of the path. | ||
func GetWd() string { | ||
wd, _ := os.Getwd() | ||
if lp, err := GetLongPathName(wd); err == nil { | ||
return lp | ||
} | ||
return wd | ||
} |
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,9 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package osutil | ||
|
||
// GetLongPathName is a no-op on non-Windows platforms. | ||
func GetLongPathName(path string) (string, error) { | ||
return path, 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