Skip to content

[CI] Add support to test packages with basic subscription #13377

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

Merged
merged 54 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9679c7c
Add support to run Elastic stack with other licenses
mrodm Apr 1, 2025
6e586b7
Add support to report issues related to subscription
mrodm Apr 1, 2025
495da16
Refactor to build common summary and string from dataError
mrodm Apr 1, 2025
e74ae7e
Refactor to buld common error links data from its object
mrodm Apr 1, 2025
081ffd3
Add option to enable verbose mode
mrodm Apr 1, 2025
969e38b
Test setting subscription basic - to be removed
mrodm Apr 1, 2025
cf0da7b
Rename function
mrodm Apr 1, 2025
099dea6
Check first if owners is not nil in summary template
mrodm Apr 2, 2025
2247914
Test with trial subscription
mrodm Apr 2, 2025
d7e479c
Test with other packages with other scenarios
mrodm Apr 2, 2025
b37ac87
Test again with basic subscription
mrodm Apr 2, 2025
3c114bd
Add target mage for subscription validation
mrodm Apr 2, 2025
0ee660e
Add some more packages to test
mrodm Apr 2, 2025
51bbb78
Test with bash functions
mrodm Apr 2, 2025
5d03168
Try with mage targets - added missing installation
mrodm Apr 2, 2025
1dc0401
Test all packages with basic license
mrodm Apr 2, 2025
69edc0a
Not shown files from git-diff checks
mrodm Apr 2, 2025
bee404b
Show annotation with skipped files
mrodm Apr 2, 2025
7252015
Fix collapsed annotation
mrodm Apr 2, 2025
571eca9
Test annotation
mrodm Apr 3, 2025
ce0b4a7
Just show skipped packages
mrodm Apr 3, 2025
d1a7db4
Test elastic-package PR 2511 - 62704d87
mrodm Apr 3, 2025
5522c3d
Update version in .go-version file
mrodm Apr 3, 2025
28e6578
Revert changes moved to other PRs
mrodm Apr 4, 2025
067f900
Test all packages with basic license
mrodm Apr 4, 2025
139851c
Merge upstream/main into test_packages_basic_subscription
mrodm Apr 7, 2025
f3fee7c
Include summary data into description data too
mrodm Apr 7, 2025
0a2b778
Add stack version entry if it has empty string
mrodm Apr 7, 2025
6805016
Test updating just one package
mrodm Apr 7, 2025
999aa58
Add collapsed blocks in trigger step
mrodm Apr 7, 2025
b9173ae
Remove one collapsed block
mrodm Apr 7, 2025
eaed4c4
Remove comments and changes for debugging
mrodm Apr 7, 2025
63fcf64
Test creation of GH issues
mrodm Apr 7, 2025
87e64da
Add default values
mrodm Apr 8, 2025
ef66216
Remove step to test with LogsDB and basic subscription
mrodm Apr 8, 2025
3f606bb
Add comment
mrodm Apr 8, 2025
4b5a98d
Remove kibana from test packages
mrodm Apr 8, 2025
51e2db1
Rename function
mrodm Apr 8, 2025
592acb2
Remove changes for debugging
mrodm Apr 8, 2025
8934110
Remove show skipped packages as annotation
mrodm Apr 8, 2025
8461649
Revert changes in go.mod go.sum
mrodm Apr 8, 2025
fcfc90a
Remove whitespace
mrodm Apr 8, 2025
2dd8413
Update go.mod
mrodm Apr 8, 2025
3c93e90
Revert .go-version file
mrodm Apr 8, 2025
fe32361
Use stdout to indicate whether or not it is supported
mrodm Apr 8, 2025
7560c46
Test some packages
mrodm Apr 8, 2025
ae345bb
Update error management
mrodm Apr 8, 2025
5f301e4
Add debug messages
mrodm Apr 8, 2025
4eea916
Test with elastic-pacakge v0.111.0
mrodm Apr 8, 2025
d32eb44
Add collapsed block
mrodm Apr 8, 2025
092b361
Revert "Test with elastic-pacakge v0.111.0"
mrodm Apr 9, 2025
1e3ee5c
Revert "Test some packages"
mrodm Apr 9, 2025
383240f
Fix typo
mrodm Apr 9, 2025
44080a4
Remove daily step
mrodm Apr 9, 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
2 changes: 2 additions & 0 deletions .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ git config --global core.pager 'cat'
export UPLOAD_SAFE_LOGS=${UPLOAD_SAFE_LOGS:-"0"}
export SERVERLESS=${SERVERLESS:-"false"}
export STACK_VERSION=${STACK_VERSION:-""}
export ELASTIC_SUBSCRIPTION=${ELASTIC_SUBSCRIPTION:-""}
export STACK_LOGSDB_ENABLED=${STACK_LOGSDB_ENABLED:-"false"}
export FORCE_CHECK_ALL=${FORCE_CHECK_ALL:-"false"}
export PUBLISH_COVERAGE_REPORTS=${PUBLISH_COVERAGE_REPORTS:-"false"}

Expand Down
27 changes: 27 additions & 0 deletions .buildkite/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ API_BUILDKITE_PIPELINES_URL="https://api.buildkite.com/v2/organizations/elastic/
COVERAGE_FORMAT="generic"
COVERAGE_OPTIONS="--test-coverage --coverage-format=${COVERAGE_FORMAT}"

FATAL_ERROR="Fatal Error"

running_on_buildkite() {
if [[ "${BUILDKITE:-"false"}" == "true" ]]; then
return 0
Expand Down Expand Up @@ -509,9 +511,15 @@ prepare_stack() {
fi

if [ "${STACK_LOGSDB_ENABLED:-false}" == "true" ]; then
echoerr "- Enable LogsDB"
args="${args} -U stack.logsdb_enabled=true"
fi

if [ "${ELASTIC_SUBSCRIPTION:-""}" != "" ]; then
echoerr "- Set Subscription ${ELASTIC_SUBSCRIPTION}"
args="${args} -U stack.elastic_subscription=${ELASTIC_SUBSCRIPTION}"
fi

if [[ "${STACK_VERSION}" =~ ^7\.17 ]]; then
# Required starting with STACK_VERSION 7.17.21
export ELASTIC_AGENT_IMAGE_REF_OVERRIDE="docker.elastic.co/beats/elastic-agent-complete:${STACK_VERSION}-amd64"
Expand Down Expand Up @@ -668,6 +676,16 @@ get_to_changeset() {
echo "${to}"
}

is_subscription_compatible() {
local reason=""

if ! reason=$(mage -d "${WORKSPACE}" -w . isSubscriptionCompatible) ; then
return 1
fi
echo "${reason}"
return 0
Comment on lines +682 to +686
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It would return failure if there is any failure (e.g. failed to read YAML file), and success in any other case (zero value).
When it returns success, the message echoed will show whether or not it is compatible (true or false).

}

is_pr_affected() {
local package="${1}"
local from="${2}"
Expand Down Expand Up @@ -698,6 +716,15 @@ is_pr_affected() {
return 1
fi
fi
local compatible=""
if ! compatible=$(is_subscription_compatible); then
echo "${FATAL_ERROR}"
return 1
fi
if [[ "${compatible}" == "false" ]]; then
echo "[${package}] PR is not affected: subscription not compatible with ${ELASTIC_SUBSCRIPTION}"
return 1
fi
Comment on lines +720 to +727
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For both cases, this function will return failure (code 1). Depending on the message echoed, the caller method should take one or other action.


if [[ "${FORCE_CHECK_ALL}" == "true" ]];then
echo "[${package}] PR is affected: \"force_check_all\" parameter enabled"
Expand Down
25 changes: 21 additions & 4 deletions .buildkite/scripts/test_integrations_with_serverless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if [ ! -d packages ]; then
exit 1
fi

echo "--- Install requirements"
add_bin_path

with_yq
Expand All @@ -60,6 +61,7 @@ sleep 120
echo "Done."

# setting range of changesets to check differences
echo "--- Get from and to changesets"
from="$(get_from_changeset)"
if [[ "${from}" == "" ]]; then
echo "Missing \"from\" changset".
Expand All @@ -76,15 +78,28 @@ any_package_failing=0

pushd packages > /dev/null
for package in $(list_all_directories); do
echo "--- [$package] check if it is required to be tested"
pushd "${package}" > /dev/null
skip_package=false
failure=false
if ! reason=$(is_pr_affected "${package}" "${from}" "${to}") ; then
echo "${reason}"
skip_package=true
if [[ "${reason}" == "${FATAL_ERROR}" ]]; then
failure=true
fi
fi
popd > /dev/null
if [[ "${failure}" == "true" ]]; then
echo "Unexpected failure checking ${package}"
exit 1
fi

echo "${reason}"

if [[ "${skip_package}" == "true" ]]; then
echo "- ${reason}" >> "${SKIPPED_PACKAGES_FILE_PATH}"
popd > /dev/null
continue
fi
echo "${reason}"
popd > /dev/null

if ! process_package "${package}" "${FAILED_PACKAGES_FILE_PATH}" ; then
any_package_failing=1
Expand All @@ -94,10 +109,12 @@ popd > /dev/null

if running_on_buildkite ; then
if [ -f "${SKIPPED_PACKAGES_FILE_PATH}" ]; then
echo "--- Create Skip Buildkite annotation"
create_collapsed_annotation "Skipped packages in ${SERVERLESS_PROJECT}" "${SKIPPED_PACKAGES_FILE_PATH}" "info" "ctx-skipped-packages-${SERVERLESS_PROJECT}"
fi

if [ -f "${FAILED_PACKAGES_FILE_PATH}" ]; then
echo "--- Create Failed Buildkite annotation"
create_collapsed_annotation "Failed packages in ${SERVERLESS_PROJECT}" "${FAILED_PACKAGES_FILE_PATH}" "error" "ctx-failed-packages-${SERVERLESS_PROJECT}"
fi
fi
Expand Down
19 changes: 16 additions & 3 deletions .buildkite/scripts/trigger_integrations_in_parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ source .buildkite/scripts/common.sh

set -euo pipefail

echo "--- Install requirements"
add_bin_path
with_yq
with_mage

pushd packages > /dev/null
PACKAGE_LIST=$(list_all_directories)
Expand All @@ -22,8 +24,8 @@ steps:
EOF

# Get from and to changesets to avoid repeating the same queries for each package

# setting range of changesets to check differences
echo "--- Get from and to changesets"
from="$(get_from_changeset)"
if [[ "${from}" == "" ]]; then
echo "Missing \"from\" changset".
Expand Down Expand Up @@ -51,15 +53,24 @@ packages_to_test=0

for package in ${PACKAGE_LIST}; do
# check if needed to create an step for this package
echo "--- [$package] check if it is required to be tested"
pushd "packages/${package}" > /dev/null
skip_package="false"
failure="false"
if ! reason=$(is_pr_affected "${package}" "${from}" "${to}") ; then
skip_package="true"
if [[ "${reason}" == "${FATAL_ERROR}" ]]; then
failure=true
fi
fi
echoerr "${reason}"
popd > /dev/null
if [[ "${failure}" == "true" ]]; then
echo "Unexpected failure checking ${package}"
exit 1
fi

if [[ "$skip_package" == "true" ]] ; then
echoerr "${reason}"
if [[ "${skip_package}" == "true" ]] ; then
continue
fi

Expand Down Expand Up @@ -87,8 +98,10 @@ EOF
done

if [ ${packages_to_test} -eq 0 ]; then
echo "--- Create Buildkite annotation no packages to be tested"
buildkite-agent annotate "No packages to be tested" --context "ctx-no-packages" --style "warning"
exit 0
fi

echo "--- Upload Buildkite pipeline"
cat ${PIPELINE_FILE} | buildkite-agent pipeline upload
48 changes: 48 additions & 0 deletions dev/citools/packagemanifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package citools

import (
"fmt"

"github.com/elastic/go-ucfg"
"github.com/elastic/go-ucfg/yaml"
)

// kibanaConditions defines conditions for Kibana (e.g. required version).
type kibanaConditions struct {
Version string `config:"version" json:"version" yaml:"version"`
}

// elasticConditions defines conditions related to Elastic subscriptions or partnerships.
type elasticConditions struct {
Subscription string `config:"subscription" json:"subscription" yaml:"subscription"`
}

// conditions define requirements for different parts of the Elastic stack.
type conditions struct {
Kibana kibanaConditions `config:"kibana" json:"kibana" yaml:"kibana"`
Elastic elasticConditions `config:"elastic" json:"elastic" yaml:"elastic"`
}

type packageManifest struct {
Name string `config:"name" json:"name" yaml:"name"`
License string `config:"license" json:"license" yaml:"license"`
Conditions conditions `config:"conditions" json:"conditions" yaml:"conditions"`
}

func readPackageManifest(path string) (*packageManifest, error) {
cfg, err := yaml.NewConfigWithFile(path, ucfg.PathSep("."))
if err != nil {
return nil, fmt.Errorf("reading file failed (path: %s): %w", path, err)
}

var manifest packageManifest
err = cfg.Unpack(&manifest)
if err != nil {
return nil, fmt.Errorf("unpacking package manifest failed (path: %s): %w", path, err)
}
return &manifest, nil
}
47 changes: 47 additions & 0 deletions dev/citools/subscription.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package citools

import (
"fmt"
)

func packageSubscription(path string) (string, error) {
manifest, err := readPackageManifest(path)
if err != nil {
return "", err
}

packageSubscription := manifest.Conditions.Elastic.Subscription
if packageSubscription == "" {
packageSubscription = manifest.License
}
if packageSubscription == "" {
packageSubscription = "basic"
}

return packageSubscription, nil
}

func IsSubscriptionCompatible(stackSubscription, path string) (bool, error) {
pkgSubscription, err := packageSubscription(path)
if err != nil {
return false, fmt.Errorf("failed to read subscription from manifest: %w", err)
}

if stackSubscription == "trial" {
// All subscriptions supported
return true, nil
}

if stackSubscription == "basic" {
if pkgSubscription != "basic" {
return false, nil
}
return true, nil
}

return false, fmt.Errorf("unknown subscription %s", stackSubscription)
}
Loading