-
Notifications
You must be signed in to change notification settings - Fork 710
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[e2e] Emit a duration-scoped grafana link for each test
- Loading branch information
Showing
5 changed files
with
89 additions
and
4 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 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,58 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package e2e | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet" | ||
|
||
ginkgo "github.com/onsi/ginkgo/v2" | ||
) | ||
|
||
// The ginkgo event handlers defined in this file will be automatically | ||
// applied to all ginkgo suites importing this package. | ||
|
||
// The UUID of the network that should be used to compose the metrics link | ||
// for the current spec. | ||
var NetworkUUIDForCurrentSpec string | ||
|
||
// This event handler attempts to ensure that the UUID of the network | ||
// targeted by the current spec is retained for use by the AfterEach | ||
// handler. If the test uses a private network, it can override this value by | ||
// setting NetworkUUIDForCurrentSpec directly. | ||
// | ||
// TODO(marun) Make this conditional on metrics collection being enabled | ||
var _ = ginkgo.BeforeEach(func() { | ||
tc := NewTestContext() | ||
env := GetEnv(tc) | ||
if env == nil { | ||
// Not possible to discover the uuid of the test network in this | ||
// event handler without a global env. | ||
return | ||
} | ||
NetworkUUIDForCurrentSpec = env.GetNetwork().UUID | ||
}) | ||
|
||
// This event handler attempts to emit a metrics link scoped to the duration | ||
// of the current spec. | ||
// | ||
// TODO(marun) Make this conditional on metrics collection being enabled | ||
var _ = ginkgo.AfterEach(func() { | ||
if len(NetworkUUIDForCurrentSpec) == 0 { | ||
// Composition of the metrics link requires a network UUID | ||
return | ||
} | ||
specReport := ginkgo.CurrentSpecReport() | ||
startTime := specReport.StartTime.UnixMilli() | ||
// Extend the end time by the metrics scrape duration to ensure the | ||
// specified duration includes all details relevant to a given test. | ||
endTime := specReport.StartTime.Add(networkShutdownDelay).UnixMilli() | ||
metricsLink := tmpnet.MetricsLinkForNetwork( | ||
NetworkUUIDForCurrentSpec, | ||
strconv.FormatInt(startTime, 10), | ||
strconv.FormatInt(endTime, 10), | ||
) | ||
NewTestContext().Outf("Test Metrics: %s\n", metricsLink) | ||
}) |
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