Skip to content

Commit

Permalink
Fix race condition when running tests for pkg/skaffold/instrumentation (
Browse files Browse the repository at this point in the history
#5267)

* move responsibility of checking online status

* include explanation for URL pinged
  • Loading branch information
MarlonGamez authored Jan 21, 2021
1 parent ebfcc99 commit da0d63d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/skaffold/skaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ExitCoder interface {
}

func main() {
instrumentation.SetOnlineStatus()
var code int
if err := app.Run(os.Stdout, os.Stderr); err != nil {
if errors.Is(err, context.Canceled) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/instrumentation/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ func init() {
meteredCommands.Insert("build", "delete", "deploy", "dev", "debug", "filter", "generate_pipeline", "render", "run", "test")
doesBuild.Insert("build", "render", "dev", "debug", "run")
doesDeploy.Insert("deploy", "dev", "debug", "run")
}

// SetOnlineStatus issues a GET request to see if the user is online.
// http://clients3.google.com/generate_204 is a well-known URL that returns an empty page and HTTP status 204
// More info can be found here: https://www.chromium.org/chromium-os/chromiumos-design-docs/network-portal-detection
func SetOnlineStatus() {
go func() {
if shouldExportMetrics {
r, err := http.Get("http://clients3.google.com/generate_204")
Expand Down

0 comments on commit da0d63d

Please sign in to comment.