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 8.17 tests #15310

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
169 changes: 32 additions & 137 deletions functionaltests/8_15_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,148 +18,43 @@
package functionaltests

import (
"context"
"testing"
"time"

"go.uber.org/zap"
"go.uber.org/zap/zaptest"

"github.com/elastic/apm-server/functionaltests/internal/ecclient"
"github.com/elastic/apm-server/functionaltests/internal/esclient"
"github.com/elastic/apm-server/functionaltests/internal/gen"
"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"
)

func TestUpgrade_8_15_4_to_8_16_0(t *testing.T) {
ecAPICheck(t)

start := time.Now()
ctx := context.Background()

t.Log("creating deploment with terraform")
tf, err := terraform.New(t, t.Name())
require.NoError(t, err)
ecTarget := terraform.Var("ec_target", *target)
ecRegion := terraform.Var("ec_region", regionFrom(*target))
version := terraform.Var("stack_version", "8.15.4")
name := terraform.Var("name", t.Name())
require.NoError(t, tf.Apply(ctx, ecTarget, ecRegion, version, name))
t.Logf("time elapsed: %s", time.Now().Sub(start))

t.Cleanup(func() {
if !t.Failed() || (t.Failed() && *cleanupOnFailure) {
t.Log("cleanup terraform resources")
require.NoError(t, tf.Destroy(ctx, ecTarget, ecRegion, name, version))
} else {
t.Log("test failed and cleanup-on-failure is false, skipping cleanup")
}
runESSUpgradeTest(t, essUpgradeTestCase{
from: "8.15.4",
to: "8.16.0",

beforeUpgradeAfterIngest: checkDatastreamWant{
Quantity: 8,
PreferIlm: false,
DSManagedBy: lifecycleDSL,
IndicesPerDs: 1,
IndicesManagedBy: []checkDatastreamIndex{
{ManagedBy: lifecycleDSL},
},
},
afterUpgradeBeforeIngest: checkDatastreamWant{
Quantity: 8,
PreferIlm: false,
DSManagedBy: lifecycleDSL,
IndicesPerDs: 1,
IndicesManagedBy: []checkDatastreamIndex{
{ManagedBy: lifecycleDSL},
},
},
afterUpgradeAfterIngest: checkDatastreamWant{
Quantity: 8,
PreferIlm: false,
DSManagedBy: lifecycleDSL,
IndicesPerDs: 2,
IndicesManagedBy: []checkDatastreamIndex{
{ManagedBy: lifecycleDSL},
{ManagedBy: lifecycleDSL},
},
},
})

var deploymentID string
require.NoError(t, tf.Output("deployment_id", &deploymentID))
var escfg esclient.Config
tf.Output("apm_url", &escfg.APMServerURL)
tf.Output("es_url", &escfg.ElasticsearchURL)
tf.Output("username", &escfg.Username)
tf.Output("password", &escfg.Password)
tf.Output("kb_url", &escfg.KibanaURL)

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

c, err := ecclient.New(endpointFrom(*target))
require.NoError(t, err)

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

t.Log("creating APM API key")
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, ecc)
require.NoError(t, err)

require.NoError(t, g.RunBlockingWait(ctx, c, deploymentID))
t.Logf("time elapsed: %s", time.Now().Sub(start))

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 = ecc.GetDataStream(ctx, "*apm*")
require.NoError(t, err)
assertDatastreams(t, checkDatastreamWant{
Quantity: 8,
PreferIlm: false,
DSManagedBy: "Data stream lifecycle",
IndicesPerDs: 1,
IndicesManagedBy: []string{"Data stream lifecycle"},
}, dss)
t.Logf("time elapsed: %s", time.Now().Sub(start))

t.Log("upgrade to 8.16.0")
require.NoError(t, tf.Apply(ctx, ecTarget, ecRegion, name, terraform.Var("stack_version", "8.16.0")))
t.Logf("time elapsed: %s", time.Now().Sub(start))

t.Log("check number of documents after upgrade")
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
// and further assertions.
// We don't expect any change here unless something broke during the upgrade.
assertDocCount(t, afterUpgradeCount, esclient.APMDataStreamsDocCount{}, beforeUpgradeCount)

t.Log("check data streams after upgrade, no rollover expected")
dss, err = ecc.GetDataStream(ctx, "*apm*")
require.NoError(t, err)
assertDatastreams(t, checkDatastreamWant{
Quantity: 8,
PreferIlm: false,
DSManagedBy: "Data stream lifecycle",
IndicesPerDs: 1,
IndicesManagedBy: []string{"Data stream lifecycle"},
}, dss)

require.NoError(t, g.RunBlockingWait(ctx, c, deploymentID))
t.Logf("time elapsed: %s", time.Now().Sub(start))

t.Log("check number of documents")
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 := ecc.GetDataStream(ctx, "*apm*")
require.NoError(t, err)
assertDatastreams(t, checkDatastreamWant{
Quantity: 8,
PreferIlm: false,
DSManagedBy: "Data stream lifecycle",
IndicesPerDs: 2,
IndicesManagedBy: []string{"Data stream lifecycle", "Data stream lifecycle"},
}, dss2)
t.Logf("time elapsed: %s", time.Now().Sub(start))

res, err := ecc.GetESErrorLogs(ctx)
require.NoError(t, err)
if !assert.Zero(t, res.Hits.Total.Value, "expected no error logs, but found some") {
t.Log("found error logs:")
for _, h := range res.Hits.Hits {
t.Log(string(h.Source_))
}
}
}
20 changes: 20 additions & 0 deletions functionaltests/TestUpgradeTo8170_plain/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module "ec_deployment" {
source = "../../testing/infra/terraform/modules/ec_deployment"
region = var.ec_region

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"
elasticsearch_zone_count = 1

stack_version = var.stack_version

tags = merge(local.ci_tags, module.tags.tags)
}
19 changes: 19 additions & 0 deletions functionaltests/TestUpgradeTo8170_plain/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
output "apm_url" {
value = module.ec_deployment.apm_url
}

output "es_url" {
value = module.ec_deployment.elasticsearch_url
}

output "username" {
value = module.ec_deployment.elasticsearch_username
}
output "password" {
value = module.ec_deployment.elasticsearch_password
sensitive = true
}

output "kb_url" {
value = module.ec_deployment.kibana_url
}
20 changes: 20 additions & 0 deletions functionaltests/TestUpgradeTo8170_plain/tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "time_static" "created_date" {}

locals {
ci_tags = {
environment = var.ENVIRONMENT
repo = var.REPO
branch = var.BRANCH
build = var.BUILD_ID
created_date = coalesce(var.CREATED_DATE, time_static.created_date.unix)
}
project = "apm-server-functionaltest"
}

module "tags" {
source = "../../testing/infra/terraform/modules/tags"
# use the convention for team/shared owned resources if we are running in CI.
# assume this is an individually owned resource otherwise.
project = local.project
}

21 changes: 21 additions & 0 deletions functionaltests/TestUpgradeTo8170_plain/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
terraform {
required_version = ">= 0.12.29"

required_providers {
ec = {
source = "elastic/ec"
version = "0.5.1"
}
}
}

locals {
api_endpoints = {
qa = "https://public-api.qa.cld.elstc.co"
pro = "https://api.elastic-cloud.com"
}
}

provider "ec" {
endpoint = local.api_endpoints[var.ec_target]
}
47 changes: 47 additions & 0 deletions functionaltests/TestUpgradeTo8170_plain/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
variable "ec_target" {
type = string
description = "The Elastic Cloud environment to target"
validation {
condition = contains(["qa", "pro"], var.ec_target)
error_message = "Valid values are (qa, pro)."
}
}

variable "ec_region" {
type = string
description = "The Elastic Cloud region to target"
}

variable "name" {
type = string
description = "The deployment name"
}

variable "stack_version" {
type = string
description = "The Elasticsearch version to bootstrap"
}

# CI variables
variable "BRANCH" {
description = "Branch name or pull request for tagging purposes"
default = "unknown-branch"
}

variable "BUILD_ID" {
description = "Build ID in the CI for tagging purposes"
default = "unknown-build"
}

variable "CREATED_DATE" {
description = "Creation date in epoch time for tagging purposes"
default = ""
}

variable "ENVIRONMENT" {
default = "unknown-environment"
}

variable "REPO" {
default = "unknown-repo-name"
}
20 changes: 20 additions & 0 deletions functionaltests/TestUpgradeTo8170_reroute/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module "ec_deployment" {
source = "../../testing/infra/terraform/modules/ec_deployment"
region = var.ec_region

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"
elasticsearch_zone_count = 1

stack_version = var.stack_version

tags = merge(local.ci_tags, module.tags.tags)
}
19 changes: 19 additions & 0 deletions functionaltests/TestUpgradeTo8170_reroute/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
output "apm_url" {
value = module.ec_deployment.apm_url
}

output "es_url" {
value = module.ec_deployment.elasticsearch_url
}

output "username" {
value = module.ec_deployment.elasticsearch_username
}
output "password" {
value = module.ec_deployment.elasticsearch_password
sensitive = true
}

output "kb_url" {
value = module.ec_deployment.kibana_url
}
20 changes: 20 additions & 0 deletions functionaltests/TestUpgradeTo8170_reroute/tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "time_static" "created_date" {}

locals {
ci_tags = {
environment = var.ENVIRONMENT
repo = var.REPO
branch = var.BRANCH
build = var.BUILD_ID
created_date = coalesce(var.CREATED_DATE, time_static.created_date.unix)
}
project = "apm-server-functionaltest"
}

module "tags" {
source = "../../testing/infra/terraform/modules/tags"
# use the convention for team/shared owned resources if we are running in CI.
# assume this is an individually owned resource otherwise.
project = local.project
}

21 changes: 21 additions & 0 deletions functionaltests/TestUpgradeTo8170_reroute/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
terraform {
required_version = ">= 0.12.29"

required_providers {
ec = {
source = "elastic/ec"
version = "0.5.1"
}
}
}

locals {
api_endpoints = {
qa = "https://public-api.qa.cld.elstc.co"
pro = "https://api.elastic-cloud.com"
}
}

provider "ec" {
endpoint = local.api_endpoints[var.ec_target]
}
Loading