-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(export): make FromFlags & metadata call more reliable and observable
Fixes b/344740239 (edge case with GKE Metadata Server and GKE sandbox). * Added debug logging * Moved risky logic from FromFlags, see code comment why * Updated metadata deps & use timeout-ed context Signed-off-by: bwplotka <bwplotka@google.com>
- Loading branch information
Showing
2 changed files
with
101 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package setup | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/alecthomas/kingpin/v2" | ||
"github.com/go-kit/log" | ||
) | ||
|
||
func TestFromFlags_NoMetadataServer(t *testing.T) { | ||
fake := kingpin.New("test", "test") | ||
newExport := FromFlags(fake, "product") | ||
// Our readines is default (3 * 10s), so ensure FromFlags is never longer than 30s. | ||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer cancel() | ||
|
||
// Fake app invocation. | ||
if _, err := fake.Parse(nil); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Make sure constructor works too. | ||
if _, err := newExport(ctx, log.NewLogfmtLogger(os.Stderr), nil); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
// Regression test for b/344740239 | ||
func TestFromFlags_NoMetadataServer_SandboxIssue(t *testing.T) { | ||
// TODO(bwplotka): TBD | ||
|
||
fake := kingpin.New("test", "test") | ||
newExport := FromFlags(fake, "product") | ||
// Our readines is default (3 * 10s), so ensure FromFlags is never longer than 30s. | ||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer cancel() | ||
|
||
// Fake app invocation. | ||
if _, err := fake.Parse(nil); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Make sure constructor works too. | ||
if _, err := newExport(ctx, log.NewLogfmtLogger(os.Stderr), nil); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |