Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functionaltests: add first test case #14935

Merged
merged 29 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
874c46a
github-actions: support for functional-tests
v1v Dec 13, 2024
5ba3747
add functionaltests framework
endorama Dec 27, 2024
1707372
goimports
endorama Dec 27, 2024
265c38f
add license
endorama Dec 30, 2024
81f1b8b
remove apm-perf override
endorama Dec 30, 2024
8edc826
remove comment
endorama Dec 30, 2024
a490d4f
support prod region
endorama Dec 31, 2024
999d77a
production -> pro
endorama Dec 31, 2024
c14da87
fix production region
endorama Dec 31, 2024
b34e570
Merge branch 'main' into functionaltests
endorama Dec 31, 2024
8747630
Apply suggestions from code review
endorama Jan 7, 2025
a031acb
fix target cli flag
endorama Dec 31, 2024
bcc83e3
remove NewConfig
endorama Jan 8, 2025
06dd665
return errs from ingest
endorama Jan 8, 2025
e182ae3
require in ecAPICheck
endorama Jan 9, 2025
fd73107
wait until wrote
endorama Jan 9, 2025
410fab3
reuse ec_deployment infra tf module
endorama Dec 31, 2024
991a9f1
goimports
endorama Jan 9, 2025
34530df
fix RunBlockingWait
endorama Jan 9, 2025
28e468c
manually install terraform in ubuntu-latest
endorama Jan 9, 2025
c48e063
check all data streams doc count
endorama Jan 9, 2025
e00ef0a
add debugging info to assertDatastreams
endorama Jan 9, 2025
52a22a6
ac -> ecc
endorama Jan 15, 2025
3ae84c4
remove constants
endorama Jan 15, 2025
d6a6146
remove docsPerDatastream
endorama Jan 15, 2025
0a02a50
enable self monitoring for EC deployment
endorama Jan 16, 2025
db94233
assert elasticsearch logs
endorama Jan 16, 2025
b97cf14
remove print
endorama Jan 17, 2025
7e6ec11
Merge branch 'main' into functionaltests
endorama Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions functionaltests/8_15_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/elastic/apm-server/functionaltests/internal/terraform"
"github.com/elastic/go-elasticsearch/v8/typedapi/types"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -67,28 +68,28 @@ func TestUpgrade_8_15_4_to_8_16_0(t *testing.T) {

t.Logf("created deployment %s", escfg.KibanaURL)

ac, err := esclient.New(escfg)
ecc, err := esclient.New(escfg)
require.NoError(t, err)

t.Log("creating APM API key")
apikey, err := ac.CreateAPMAPIKey(ctx, t.Name())
apikey, err := ecc.CreateAPMAPIKey(ctx, t.Name())
require.NoError(t, err)

g := gen.New(escfg.APMServerURL, apikey)
g.Logger = zaptest.NewLogger(t, zaptest.Level(zap.InfoLevel))

previous, err := getDocsCountPerDS(t, ctx, ac)
previous, err := getDocsCountPerDS(t, ctx, ecc)
require.NoError(t, err)

g.RunBlockingWait(ctx, ac, expectedIngestForASingleRun(), previous, 1*time.Minute)
g.RunBlockingWait(ctx, ecc, expectedIngestForASingleRun(), previous, 1*time.Minute)

beforeUpgradeCount, err := getDocsCountPerDS(t, ctx, ac)
beforeUpgradeCount, err := getDocsCountPerDS(t, ctx, ecc)
require.NoError(t, err)
assertDocCount(t, beforeUpgradeCount, previous, expectedIngestForASingleRun())

t.Log("check data streams")
var dss []types.DataStream
dss, err = ac.GetDataStream(ctx, "*apm*")
dss, err = ecc.GetDataStream(ctx, "*apm*")
require.NoError(t, err)
assertDatastreams(t, checkDatastreamWant{
Quantity: 8,
Expand All @@ -104,7 +105,7 @@ func TestUpgrade_8_15_4_to_8_16_0(t *testing.T) {
t.Logf("time elapsed: %s", time.Now().Sub(start))

t.Log("check number of documents after upgrade")
afterUpgradeCount, err := getDocsCountPerDS(t, ctx, ac)
afterUpgradeCount, err := getDocsCountPerDS(t, ctx, ecc)
require.NoError(t, err)
// We assert that no changes happened in the number of documents after upgrade
// to ensure the state didn't change before running the next ingestion round
Expand All @@ -113,7 +114,7 @@ func TestUpgrade_8_15_4_to_8_16_0(t *testing.T) {
assertDocCount(t, afterUpgradeCount, esclient.APMDataStreamsDocCount{}, beforeUpgradeCount)

t.Log("check data streams after upgrade, no rollover expected")
dss, err = ac.GetDataStream(ctx, "*apm*")
dss, err = ecc.GetDataStream(ctx, "*apm*")
require.NoError(t, err)
assertDatastreams(t, checkDatastreamWant{
Quantity: 8,
Expand All @@ -123,18 +124,18 @@ func TestUpgrade_8_15_4_to_8_16_0(t *testing.T) {
IndicesManagedBy: []string{"Data stream lifecycle"},
}, dss)

g.RunBlockingWait(ctx, ac, expectedIngestForASingleRun(), previous, 1*time.Minute)
g.RunBlockingWait(ctx, ecc, expectedIngestForASingleRun(), previous, 1*time.Minute)

t.Log("check number of documents")
afterUpgradeIngestionCount, err := getDocsCountPerDS(t, ctx, ac)
afterUpgradeIngestionCount, err := getDocsCountPerDS(t, ctx, ecc)
require.NoError(t, err)
assertDocCount(t, afterUpgradeIngestionCount, afterUpgradeCount, expectedIngestForASingleRun())

// Confirm datastreams are
// v managed by DSL if created after 8.15.0
// x managed by ILM if created before 8.15.0
t.Log("check data streams and verify lazy rollover happened")
dss2, err := ac.GetDataStream(ctx, "*apm*")
dss2, err := ecc.GetDataStream(ctx, "*apm*")
require.NoError(t, err)
assertDatastreams(t, checkDatastreamWant{
Quantity: 8,
Expand All @@ -145,6 +146,7 @@ func TestUpgrade_8_15_4_to_8_16_0(t *testing.T) {
}, dss2)
t.Logf("time elapsed: %s", time.Now().Sub(start))

// check ES logs, there should be no errors
// TODO: how to get these from Elastic Cloud? Is it possible?
res, err := ecc.GetESErrorLogs(ctx)
require.NoError(t, err)
assert.Zero(t, res.Hits.Total.Value)
}
4 changes: 4 additions & 0 deletions functionaltests/TestUpgrade_8_15_4_to_8_16_0/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module "ec_deployment" {
deployment_template = "aws-storage-optimized"
deployment_name_prefix = var.name

// self monitoring is enabled so we can inspect Elasticsearch
// logs from tests.
observability_deployment = "self"

apm_server_size = "1g"

elasticsearch_size = "4g"
Expand Down
34 changes: 34 additions & 0 deletions functionaltests/internal/esclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"github.com/elastic/go-elasticsearch/v8"
"github.com/elastic/go-elasticsearch/v8/typedapi/core/search"
"github.com/elastic/go-elasticsearch/v8/typedapi/esql/query"
"github.com/elastic/go-elasticsearch/v8/typedapi/security/createapikey"
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
Expand Down Expand Up @@ -157,3 +158,36 @@ line 1:1: Unknown index [traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs-

return res, nil
}

// GetESErrorLogs retrieves Elasticsearch error logs.
// The search query is on the Index used by Elasticsearch monitoring to store logs.
func (c *Client) GetESErrorLogs(ctx context.Context) (*search.Response, error) {
res, err := c.es.Search().
Index("elastic-cloud-logs-8").
Request(&search.Request{
Query: &types.Query{
Bool: &types.BoolQuery{
Must: []types.Query{
{
Match: map[string]types.MatchQuery{
"service.type": {Query: "elasticsearch"},
},
},
{
Match: map[string]types.MatchQuery{
"log.level": {Query: "ERROR"},
},
},
},
},
},
}).Do(ctx)
if err != nil {
return search.NewResponse(), fmt.Errorf("cannot run search query: %w", err)
}

fmt.Printf("%+v\n", res)
fmt.Println(res.Hits.Total.Value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these meant to be printed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no they were not. Removed in b97cf14


return res, nil
}
13 changes: 3 additions & 10 deletions functionaltests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ var cleanupOnFailure *bool = flag.Bool("cleanup-on-failure", true, "Whether to r
// We use 'pro' for production as that is the key used to retrieve EC_API_KEY from secret storage.
var target *string = flag.String("target", "pro", "The target environment where to run tests againts. Valid values are: qa, pro")

// https://www.elastic.co/guide/en/cloud/current/ec-regions-templates-instances.html
const testRegionQA = "aws-eu-west-1"
const testRegionProduction = "eu-west-1"

// expectedIngestForASingleRun() represent the expected number of ingested document after a
// single run of ingest().
// Only non aggregation data streams are included, as aggregation ones differs on different
Expand All @@ -53,10 +49,6 @@ func expectedIngestForASingleRun() esclient.APMDataStreamsDocCount {
}
}

// docsPerDatastream is a utility type to map esclient.ApmDocCount to a format
// easier to perform assertions on.
type docsPerDatastream map[string]int

// getDocsCountPerDS retrieves document count.
func getDocsCountPerDS(t *testing.T, ctx context.Context, ecc *esclient.Client) (esclient.APMDataStreamsDocCount, error) {
t.Helper()
Expand Down Expand Up @@ -113,12 +105,13 @@ func assertDatastreams(t *testing.T, expected checkDatastreamWant, actual []type

// regionFrom returns the appropriate region to run test
// againts based on specified target.
// https://www.elastic.co/guide/en/cloud/current/ec-regions-templates-instances.html
func regionFrom(target string) string {
switch target {
case "qa":
return testRegionQA
return "aws-eu-west-1"
case "pro":
return testRegionProduction
return "eu-west-1"
default:
panic("target value is not accepted")
}
Expand Down
Loading