Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
feat: upgrade go agent to v2 (#3845)
Browse files Browse the repository at this point in the history
* feat: upgrade go agent to v2

go.elastic.co/apm v1 has been deprecated for a while. Update the dependency
to v2.

* lint: drop ioutil to fix linting errors

* lint: order imports to fix linting errors
  • Loading branch information
kruskall authored Jul 9, 2024
1 parent 9e798dc commit 6d6c0c2
Show file tree
Hide file tree
Showing 37 changed files with 281 additions and 1,003 deletions.
2 changes: 1 addition & 1 deletion e2e/_suites/fleet/elastic_agent_enroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/elastic/e2e-testing/internal/installer"
"github.com/elastic/e2e-testing/internal/utils"
log "github.com/sirupsen/logrus"
"go.elastic.co/apm"
"go.elastic.co/apm/v2"
)

func (fts *FleetTestSuite) anAttemptToEnrollANewAgentFails() error {
Expand Down
14 changes: 7 additions & 7 deletions e2e/_suites/fleet/fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
flag "github.com/spf13/pflag"
"go.elastic.co/apm"
"go.elastic.co/apm/v2"
)

const testResourcesDir = "./testresources"
Expand Down Expand Up @@ -399,7 +399,7 @@ func InitializeFleetTestScenario(ctx *godog.ScenarioContext) {
ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
log.Tracef("After Fleet scenario: %s", sc.Name)
if err != nil {
e := apm.DefaultTracer.NewError(err)
e := apm.DefaultTracer().NewError(err)
e.Context.SetLabel("scenario", sc.Name)
e.Context.SetLabel("gherkin_type", "scenario")
e.Send()
Expand All @@ -408,7 +408,7 @@ func InitializeFleetTestScenario(ctx *godog.ScenarioContext) {
f := func() {
tx.End()

apm.DefaultTracer.Flush(nil)
apm.DefaultTracer().Flush(nil)
}
defer f()

Expand All @@ -427,7 +427,7 @@ func InitializeFleetTestScenario(ctx *godog.ScenarioContext) {
})
ctx.StepContext().After(func(ctx context.Context, step *godog.Step, status godog.StepResultStatus, err error) (context.Context, error) {
if err != nil {
e := apm.DefaultTracer.NewError(err)
e := apm.DefaultTracer().NewError(err)
e.Context.SetLabel("step", step.Text)
e.Context.SetLabel("gherkin_type", "step")
e.Context.SetLabel("step_status", status.String())
Expand Down Expand Up @@ -510,7 +510,7 @@ func InitializeFleetTestSuite(ctx *godog.TestSuiteContext) {
var suiteContext = context.Background()

// instrumentation
defer apm.DefaultTracer.Flush(nil)
defer apm.DefaultTracer().Flush(nil)
suiteTx = apme2e.StartTransaction("Initialise Fleet", "test.suite")
defer suiteTx.End()
suiteParentSpan = suiteTx.StartSpan("Before Fleet test suite", "test.suite.before", nil)
Expand Down Expand Up @@ -576,15 +576,15 @@ func InitializeFleetTestSuite(ctx *godog.TestSuiteContext) {

ctx.AfterSuite(func() {
f := func() {
apm.DefaultTracer.Flush(nil)
apm.DefaultTracer().Flush(nil)
}
defer f()

// instrumentation
var suiteTx *apm.Transaction
var suiteParentSpan *apm.Span
var suiteContext = context.Background()
defer apm.DefaultTracer.Flush(nil)
defer apm.DefaultTracer().Flush(nil)
suiteTx = apme2e.StartTransaction("Tear Down Fleet", "test.suite")
defer suiteTx.End()
suiteParentSpan = suiteTx.StartSpan("After Fleet test suite", "test.suite.after", nil)
Expand Down
3 changes: 1 addition & 2 deletions e2e/_suites/fleet/system_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -222,7 +221,7 @@ func readJSONFile(file string) (*gabs.Container, error) {
}).Info("Successfully Opened " + file)

defer jsonFile.Close()
data, err := ioutil.ReadAll(jsonFile)
data, err := os.ReadAll(jsonFile)
if err != nil {
return nil, err
}
Expand Down
19 changes: 9 additions & 10 deletions e2e/_suites/kubernetes-autodiscover/autodiscover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -24,7 +23,7 @@ import (
apme2e "github.com/elastic/e2e-testing/internal"
log "github.com/sirupsen/logrus"
flag "github.com/spf13/pflag"
"go.elastic.co/apm"
"go.elastic.co/apm/v2"

"github.com/elastic/e2e-testing/internal/common"
"github.com/elastic/e2e-testing/internal/config"
Expand Down Expand Up @@ -349,7 +348,7 @@ func (m *podsManager) waitForEventsCondition(podName string, conditionFn func(ct
return fmt.Errorf("failed to get pod name: %w", err)
}

tmpDir, err := ioutil.TempDir(os.TempDir(), "test-")
tmpDir, err := os.MkdirTemp(os.TempDir(), "test-")
if err != nil {
return fmt.Errorf("failed to create temporary directory: %w", err)
}
Expand Down Expand Up @@ -533,7 +532,7 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) {
var suiteParentSpan *apm.Span

// instrumentation
defer apm.DefaultTracer.Flush(nil)
defer apm.DefaultTracer().Flush(nil)
suiteTx = apme2e.StartTransaction("Initialise k8s Autodiscover", "test.suite")
defer suiteTx.End()
suiteParentSpan = suiteTx.StartSpan("Before k8s Autodiscover test suite", "test.suite.before", nil)
Expand All @@ -542,7 +541,7 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) {

err := cluster.Initialize(suiteContext, "testdata/kind.yml")
if err != nil {
e := apm.DefaultTracer.NewError(err)
e := apm.DefaultTracer().NewError(err)
e.Send()

log.WithError(err).Fatal("Failed to initialize cluster")
Expand All @@ -554,14 +553,14 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) {

ctx.AfterSuite(func() {
f := func() {
apm.DefaultTracer.Flush(nil)
apm.DefaultTracer().Flush(nil)
}
defer f()

// instrumentation
var suiteTx *apm.Transaction
var suiteParentSpan *apm.Span
defer apm.DefaultTracer.Flush(nil)
defer apm.DefaultTracer().Flush(nil)
suiteTx = apme2e.StartTransaction("Tear Down k8s Autodiscover", "test.suite")
defer suiteTx.End()
suiteParentSpan = suiteTx.StartSpan("After k8s Autodiscover test suite", "test.suite.after", nil)
Expand Down Expand Up @@ -613,7 +612,7 @@ func InitializeScenario(ctx *godog.ScenarioContext) {
})
ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
if err != nil {
e := apm.DefaultTracer.NewError(err)
e := apm.DefaultTracer().NewError(err)
e.Context.SetLabel("scenario", sc.Name)
e.Context.SetLabel("gherkin_type", "scenario")
e.Send()
Expand All @@ -622,7 +621,7 @@ func InitializeScenario(ctx *godog.ScenarioContext) {
f := func() {
tx.End()

apm.DefaultTracer.Flush(nil)
apm.DefaultTracer().Flush(nil)
}
defer f()

Expand All @@ -641,7 +640,7 @@ func InitializeScenario(ctx *godog.ScenarioContext) {
})
ctx.StepContext().After(func(ctx context.Context, step *godog.Step, status godog.StepResultStatus, err error) (context.Context, error) {
if err != nil {
e := apm.DefaultTracer.NewError(err)
e := apm.DefaultTracer().NewError(err)
e.Context.SetLabel("step", step.Text)
e.Context.SetLabel("gherkin_type", "step")
e.Context.SetLabel("step_status", status.String())
Expand Down
14 changes: 7 additions & 7 deletions e2e/templates/suite_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
apme2e "github.com/elastic/e2e-testing/internal"
log "github.com/sirupsen/logrus"
"github.com/spf13/pflag" // godog v0.12.4 (latest)
"go.elastic.co/apm"
"go.elastic.co/apm/v2"
)

var testSuite ${CAPITAL_SUITE}TestSuite
Expand Down Expand Up @@ -69,7 +69,7 @@ func Initialize${CAPITAL_SUITE}Scenarios(ctx *godog.ScenarioContext) {

ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
if err != nil {
e := apm.DefaultTracer.NewError(err)
e := apm.DefaultTracer().NewError(err)
e.Context.SetLabel("scenario", sc.Name)
e.Context.SetLabel("gherkin_type", "scenario")
e.Send()
Expand All @@ -78,7 +78,7 @@ func Initialize${CAPITAL_SUITE}Scenarios(ctx *godog.ScenarioContext) {
f := func() {
tx.End()

apm.DefaultTracer.Flush(nil)
apm.DefaultTracer().Flush(nil)
}
defer f()

Expand All @@ -95,7 +95,7 @@ func Initialize${CAPITAL_SUITE}Scenarios(ctx *godog.ScenarioContext) {
})
ctx.StepContext().After(func(ctx context.Context, step *godog.Step, status godog.StepResultStatus, err error) (context.Context, error) {
if err != nil {
e := apm.DefaultTracer.NewError(err)
e := apm.DefaultTracer().NewError(err)
e.Context.SetLabel("step", st.GetText())
e.Context.SetLabel("gherkin_type", "step")
e.Send()
Expand All @@ -122,7 +122,7 @@ func Initialize${CAPITAL_SUITE}TestSuite(ctx *godog.TestSuiteContext) {
var suiteContext = context.Background()

// instrumentation
defer apm.DefaultTracer.Flush(nil)
defer apm.DefaultTracer().Flush(nil)
suiteTx = apme2e.StartTransaction("Initialise ${CAPITAL_SUITE}", "test.suite")
defer suiteTx.End()
suiteParentSpan = suiteTx.StartSpan("Before ${CAPITAL_SUITE} test suite", "test.suite.before", nil)
Expand All @@ -135,15 +135,15 @@ func Initialize${CAPITAL_SUITE}TestSuite(ctx *godog.TestSuiteContext) {

ctx.AfterSuite(func() {
f := func() {
apm.DefaultTracer.Flush(nil)
apm.DefaultTracer().Flush(nil)
}
defer f()

// instrumentation
var suiteTx *apm.Transaction
var suiteParentSpan *apm.Span
var suiteContext = context.Background()
defer apm.DefaultTracer.Flush(nil)
defer apm.DefaultTracer().Flush(nil)
suiteTx = apme2e.StartTransaction("Tear Down ${CAPITAL_SUITE}", "test.suite")
defer suiteTx.End()
suiteParentSpan = suiteTx.StartSpan("After ${CAPITAL_SUITE} test suite", "test.suite.after", nil)
Expand Down
Loading

0 comments on commit 6d6c0c2

Please sign in to comment.