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

[O11y][Couchbase] Fix system tests #9896

Merged
merged 8 commits into from
May 22, 2024

Conversation

aliabbas-elastic
Copy link
Contributor

Proposed commit message

Fixes the flaky tests which result in error message one or more errors found in documents stored in metrics-couchbase.xdcr-ep data stream: [0] found error.message in event: [invalid character 'R' looking for beginning of value]

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have added an entry to my package's changelog.yml file.
    • Not updating the changelog as this change doesn't relate to the changes that should be visible at user's end
  • I have verified that Kibana version constraints are current according to guidelines.

How to test this PR locally

  1. elastic-package check
  2. elastic-package stack up -d -v
  3. elastic-package test -v

Related issues

Screenshots

--- Test results for package: couchbase - START ---
╭───────────┬─────────────────┬───────────┬───────────────────────────┬────────┬─────────────────╮
│ PACKAGE   │ DATA STREAM     │ TEST TYPE │ TEST NAME                 │ RESULT │    TIME ELAPSED │
├───────────┼─────────────────┼───────────┼───────────────────────────┼────────┼─────────────────┤
│ couchbase │ bucket          │ system    │ default (variant: v7.1.0) │ PASS   │   54.538326822s │
│ couchbase │ cache           │ system    │ default (variant: v7.1.0) │ PASS   │ 1m13.962378817s │
│ couchbase │ cbl_replication │ system    │ default (variant: v7.1.0) │ PASS   │ 1m14.540847808s │
│ couchbase │ cluster         │ system    │ default (variant: v7.1.0) │ PASS   │   52.595722263s │
│ couchbase │ database_stats  │ system    │ default (variant: v7.1.0) │ PASS   │ 1m16.059139553s │
│ couchbase │ miscellaneous   │ system    │ default (variant: v7.1.0) │ PASS   │ 1m18.292679447s │
│ couchbase │ node            │ system    │ default (variant: v7.1.0) │ PASS   │   1m0.69584239s │
│ couchbase │ query_index     │ system    │ default (variant: v7.1.0) │ PASS   │   57.233809413s │
│ couchbase │ resource        │ system    │ default (variant: v7.1.0) │ PASS   │   54.237537472s │
│ couchbase │ xdcr            │ system    │ default (variant: v7.1.0) │ PASS   │   57.845970643s │
╰───────────┴─────────────────┴───────────┴───────────────────────────┴────────┴─────────────────╯
--- Test results for package: couchbase - END   ---
Done

@elasticmachine
Copy link

elasticmachine commented May 16, 2024

🚀 Benchmarks report

To see the full report comment with /test benchmark fullreport

@aliabbas-elastic aliabbas-elastic marked this pull request as ready for review May 16, 2024 14:03
@aliabbas-elastic aliabbas-elastic requested a review from a team as a code owner May 16, 2024 14:03
@aliabbas-elastic
Copy link
Contributor Author

/test

@@ -5,13 +5,16 @@ do
done

# add "beer-sample" bucket from sampleBuckets
curl -v -u Administrator:password -X POST http://127.0.0.1:8091/sampleBuckets/install -d '["beer-sample"]'
until [ "$(curl -v -u Administrator:password -X POST http://localhost:8091/sampleBuckets/install -d '["beer-sample"]' -o /dev/null -w '%{http_code}')" -eq 202 ]
Copy link
Member

Choose a reason for hiding this comment

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

A lot of variables are repeating. Let's rewrite this script to be more readable, robust and maintainable.

ADMIN_USER="Administrator"
ADMIN_PASSWORD="password"
CB_HOST="localhost"
CB_PORT="8091"
BUCKET_NAME="beer-sample"
XDCR_CLUSTER_NAME="cluster"
XDCR_HOSTNAME="127.0.0.1"
REPLICATION_FROM_BUCKET="beer-sample"
REPLICATION_TO_CLUSTER="cluster"
REPLICATION_TO_BUCKET="travel-sample"

We can also use a single var for the host i.e., localhost or 127.0.0.1. Currently, both are there.

Also, if you wrap it in functions, this scripts looks cleaner.

is_couchbase_ready() {
  curl --silent --fail "http://${ADMIN_USER}:${ADMIN_PASSWORD}@${CB_HOST}:${CB_PORT}/pools/default" >/dev/null 2>&1
}

# To call the function
is_couchbase_ready

As no output from curl is necessary, redirect the standard streams to /dev/null. Health checks are typically written in this manner to avoid unnecessary actions.

Another sample function to make it more readable:

# Function to add sample bucket
add_cb_sample_bucket() {
  local bucket_name="$1"
  local http_code
  http_code=$(curl --silent --output /dev/null --write-out "%{http_code}" \
    --user "${ADMIN_USER}:${ADMIN_PASSWORD}" \
    --header "Content-Type: application/json" \
    --request POST \
    --data "[\"${bucket_name}\"]" \
    "http://${CB_HOST}:${CB_PORT}/sampleBuckets/install")

  if [[ "${http_code}" -eq 202 ]]; then
    return 0
  else
    return 1
  fi
}

And call it like:

while ! add_cb_sample_bucket "${BUCKET_NAME}"; do
  sleep 5
done

With this approach, the script looks much cleaner and also maintainable. Let me know what you think?

until [ "$(curl -v -u Administrator:password -X POST http://localhost:8091/sampleBuckets/install -d '["beer-sample"]' -o /dev/null -w '%{http_code}')" -eq 202 ]
do
sleep 5s
done

# using couchbase-cli run xdcr-setup for the cluster
couchbase-cli xdcr-setup -c 127.0.0.1 -u Administrator -p password --create --xdcr-cluster-name cluster --xdcr-hostname 127.0.0.1 --xdcr-username Administrator --xdcr-password password

# wait till the xdcr-setup creates cluster
Copy link
Member

Choose a reason for hiding this comment

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

Probably it is better to write that you are waiting for bucket to be ready. Comment is not clear here.

Copy link
Member

Choose a reason for hiding this comment

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

This is a command to check if bucket is ready.

@@ -7,7 +7,7 @@ services:
- ./files/setup.sh:/setup.sh
- ./files/entrypoint.sh:/entrypoint.sh
healthcheck:
test: ["CMD", "curl", "-f", "http://admin:password@localhost:8091/pools/default/"]
test: ["CMD", "curl", "-f", "http://Administrator:password@localhost:8091/pools/default/buckets/beer-sample/stats"]
Copy link
Member

Choose a reason for hiding this comment

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

let's add -s as well here. silent and fail to all curl

Copy link
Member

@shmsr shmsr left a comment

Choose a reason for hiding this comment

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

Script could still be better but let's do it some other time. For now, this is good. Thanks for addressing the comments.

@aliabbas-elastic
Copy link
Contributor Author

/test

Copy link
Collaborator

@kush-elastic kush-elastic left a comment

Choose a reason for hiding this comment

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

LGTM!

@aliabbas-elastic
Copy link
Contributor Author

/test

1 similar comment
@aliabbas-elastic
Copy link
Contributor Author

/test

Co-authored-by: subham sarkar <sarkar.subhams2@gmail.com>
@aliabbas-elastic
Copy link
Contributor Author

/test

@elasticmachine
Copy link

💚 Build Succeeded

History

cc @aliabbas-elastic

Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@shmsr shmsr merged commit d2a7417 into elastic:main May 22, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants