|
| 1 | +name: E2E - Ruby Layer |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + logzio_api_url: |
| 7 | + description: "Logz.io API base URL (default https://api.logz.io)" |
| 8 | + required: false |
| 9 | + default: "https://api.logz.io" |
| 10 | + aws_region: |
| 11 | + description: "AWS Region" |
| 12 | + required: false |
| 13 | + default: "us-east-1" |
| 14 | + |
| 15 | + push: |
| 16 | + branches: |
| 17 | + - feat/unified-lambda-layer |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +env: |
| 23 | + AWS_REGION: ${{ inputs.aws_region || 'us-east-1' }} |
| 24 | + AWS_DEFAULT_REGION: ${{ inputs.aws_region || 'us-east-1' }} |
| 25 | + ARCHITECTURE: amd64 |
| 26 | + FUNCTION_NAME: one-layer-e2e-test-ruby |
| 27 | + LAYER_BASE_NAME: otel-ruby-extension-e2e |
| 28 | + SERVICE_NAME: logzio-e2e-ruby-service |
| 29 | + LOGZIO_REGION: us |
| 30 | + |
| 31 | +jobs: |
| 32 | + build-layer: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - name: Checkout |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Set up Go (for Collector) |
| 39 | + uses: actions/setup-go@v5 |
| 40 | + with: |
| 41 | + go-version-file: collector/go.mod |
| 42 | + |
| 43 | + - name: Set up Docker |
| 44 | + uses: crazy-max/ghaction-setup-docker@v3 |
| 45 | + |
| 46 | + - name: Build combined Ruby layer (amd64) |
| 47 | + run: | |
| 48 | + cd ruby |
| 49 | + ARCHITECTURE=${ARCHITECTURE} ./build-combined.sh |
| 50 | +
|
| 51 | + - name: Upload layer artifact |
| 52 | + uses: actions/upload-artifact@v4 |
| 53 | + with: |
| 54 | + name: otel-ruby-extension-layer.zip |
| 55 | + path: ruby/build/otel-ruby-extension-layer.zip |
| 56 | + |
| 57 | + publish-update-invoke: |
| 58 | + runs-on: ubuntu-latest |
| 59 | + needs: build-layer |
| 60 | + outputs: |
| 61 | + layer_arn: ${{ steps.publish.outputs.layer_arn }} |
| 62 | + e2e_label: ${{ steps.vars.outputs.e2e_label }} |
| 63 | + steps: |
| 64 | + - name: Checkout |
| 65 | + uses: actions/checkout@v4 |
| 66 | + |
| 67 | + - name: Download layer artifact |
| 68 | + uses: actions/download-artifact@v4 |
| 69 | + with: |
| 70 | + name: otel-ruby-extension-layer.zip |
| 71 | + |
| 72 | + - name: Configure AWS (User Credentials) |
| 73 | + uses: aws-actions/configure-aws-credentials@v4 |
| 74 | + with: |
| 75 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 76 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 77 | + aws-region: ${{ env.AWS_REGION }} |
| 78 | + |
| 79 | + - name: Publish layer version |
| 80 | + id: publish |
| 81 | + shell: bash |
| 82 | + run: | |
| 83 | + set -euo pipefail |
| 84 | + LAYER_NAME="${LAYER_BASE_NAME}-amd64" |
| 85 | + ARN=$(aws lambda publish-layer-version \ |
| 86 | + --layer-name "$LAYER_NAME" \ |
| 87 | + --license-info "Apache-2.0" \ |
| 88 | + --compatible-architectures x86_64 \ |
| 89 | + --compatible-runtimes ruby3.2 ruby3.3 \ |
| 90 | + --zip-file fileb://otel-ruby-extension-layer.zip \ |
| 91 | + --query 'LayerVersionArn' --output text) |
| 92 | + echo "layer_arn=$ARN" >> "$GITHUB_OUTPUT" |
| 93 | +
|
| 94 | + - name: Prepare variables |
| 95 | + id: vars |
| 96 | + run: | |
| 97 | + echo "e2e_label=ruby-e2e-${GITHUB_RUN_ID}" >> "$GITHUB_OUTPUT" |
| 98 | +
|
| 99 | + - name: Check function exists and get current config |
| 100 | + run: | |
| 101 | + echo "Checking if function exists and its current configuration..." |
| 102 | + aws lambda get-function-configuration --function-name "${FUNCTION_NAME}" --query '{Role:Role,KMSKeyArn:KMSKeyArn,State:State,LastUpdateStatus:LastUpdateStatus}' --output table || { |
| 103 | + echo "❌ Function ${FUNCTION_NAME} does not exist or is not accessible." |
| 104 | + exit 1 |
| 105 | + } |
| 106 | + |
| 107 | + echo "Current environment variables:" |
| 108 | + aws lambda get-function-configuration --function-name "${FUNCTION_NAME}" --query 'Environment.Variables' --output json || echo "No environment variables set" |
| 109 | + |
| 110 | + - name: Update Lambda configuration |
| 111 | + run: | |
| 112 | + echo "Updating function configuration..." |
| 113 | + aws lambda update-function-configuration \ |
| 114 | + --function-name "${FUNCTION_NAME}" \ |
| 115 | + --layers "${{ steps.publish.outputs.layer_arn }}" \ |
| 116 | + --environment "Variables={AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler,OPENTELEMETRY_COLLECTOR_CONFIG_URI=/opt/collector-config/config.e2e.yaml,OTEL_SERVICE_NAME=${SERVICE_NAME},OTEL_TRACES_SAMPLER=always_on,OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf,OTEL_RESOURCE_ATTRIBUTES=deployment.environment=${{ steps.vars.outputs.e2e_label }},ENVIRONMENT=${{ steps.vars.outputs.e2e_label }},LOGZIO_REGION=${LOGZIO_REGION},LOGZIO_LOGS_TOKEN=${{ secrets.LOGZIO_LOGS_TOKEN }},LOGZIO_TRACES_TOKEN=${{ secrets.LOGZIO_TRACES_TOKEN }},LOGZIO_METRICS_TOKEN=${{ secrets.LOGZIO_METRICS_TOKEN }}}" |
| 117 | + |
| 118 | + echo "Waiting for function update to complete..." |
| 119 | + aws lambda wait function-updated --function-name "${FUNCTION_NAME}" |
| 120 | + |
| 121 | + echo "Updated configuration:" |
| 122 | + aws lambda get-function-configuration --function-name "${FUNCTION_NAME}" --query '{Layers:Layers[].Arn,Environment:Environment.Variables}' --output json |
| 123 | +
|
| 124 | + - name: Invoke function multiple times |
| 125 | + run: | |
| 126 | + echo "Invoking function first time..." |
| 127 | + aws lambda invoke --function-name "${FUNCTION_NAME}" --payload '{}' --cli-binary-format raw-in-base64-out response1.json |
| 128 | + echo "First invocation response:" |
| 129 | + cat response1.json |
| 130 | + echo "" |
| 131 | + |
| 132 | + echo "Invoking function second time..." |
| 133 | + aws lambda invoke --function-name "${FUNCTION_NAME}" --payload '{}' --cli-binary-format raw-in-base64-out response2.json |
| 134 | + echo "Second invocation response:" |
| 135 | + cat response2.json |
| 136 | + echo "" |
| 137 | + |
| 138 | + echo "Sleeping for 5 seconds before additional invocations..." |
| 139 | + sleep 5 |
| 140 | +
|
| 141 | + echo "Invoking function third time..." |
| 142 | + aws lambda invoke --function-name "${FUNCTION_NAME}" --payload '{}' --cli-binary-format raw-in-base64-out response3.json |
| 143 | + echo "Third invocation response:" |
| 144 | + cat response3.json |
| 145 | + echo "" |
| 146 | +
|
| 147 | + echo "Invoking function fourth time..." |
| 148 | + aws lambda invoke --function-name "${FUNCTION_NAME}" --payload '{}' --cli-binary-format raw-in-base64-out response4.json |
| 149 | + echo "Fourth invocation response:" |
| 150 | + cat response4.json |
| 151 | + echo "" |
| 152 | +
|
| 153 | + echo "Invoking function fifth time..." |
| 154 | + aws lambda invoke --function-name "${FUNCTION_NAME}" --payload '{}' --cli-binary-format raw-in-base64-out response5.json |
| 155 | + echo "Fifth invocation response:" |
| 156 | + cat response5.json |
| 157 | + echo "" |
| 158 | +
|
| 159 | + - name: Check CloudWatch logs |
| 160 | + run: | |
| 161 | + echo "Checking recent CloudWatch logs for the function..." |
| 162 | + LOG_GROUP_NAME="/aws/lambda/${FUNCTION_NAME}" |
| 163 | + |
| 164 | + # Get recent log events (last 5 minutes) |
| 165 | + aws logs filter-log-events \ |
| 166 | + --log-group-name "$LOG_GROUP_NAME" \ |
| 167 | + --start-time $(date -d '5 minutes ago' +%s)000 \ |
| 168 | + --query 'events[].message' \ |
| 169 | + --output text || { |
| 170 | + echo "❌ Could not fetch CloudWatch logs. Log group might not exist or no recent logs." |
| 171 | + echo "Checking if log group exists..." |
| 172 | + aws logs describe-log-groups --log-group-name-prefix "$LOG_GROUP_NAME" --query 'logGroups[].logGroupName' --output text |
| 173 | + } |
| 174 | +
|
| 175 | + verify-e2e: |
| 176 | + runs-on: ubuntu-latest |
| 177 | + needs: publish-update-invoke |
| 178 | + steps: |
| 179 | + - name: Checkout |
| 180 | + uses: actions/checkout@v4 |
| 181 | + |
| 182 | + - name: Set up Go |
| 183 | + uses: actions/setup-go@v5 |
| 184 | + with: |
| 185 | + go-version: '1.21' |
| 186 | + |
| 187 | + - name: Run E2E verification tests |
| 188 | + working-directory: e2e_tests |
| 189 | + env: |
| 190 | + LOGZIO_API_KEY: ${{ secrets.LOGZIO_API_KEY }} |
| 191 | + LOGZIO_API_URL: ${{ inputs.logzio_api_url || 'https://api.logz.io' }} |
| 192 | + LOGZIO_API_METRICS_KEY: ${{ secrets.LOGZIO_API_METRICS_KEY }} |
| 193 | + LOGZIO_METRICS_QUERY_URL: ${{ inputs.logzio_api_url || 'https://api.logz.io' }} |
| 194 | + LOGZIO_API_TRACES_KEY: ${{ secrets.LOGZIO_API_TRACES_KEY }} |
| 195 | + E2E_TEST_ENVIRONMENT_LABEL: ${{ needs.publish-update-invoke.outputs.e2e_label }} |
| 196 | + EXPECTED_LAMBDA_FUNCTION_NAME: one-layer-e2e-test-ruby |
| 197 | + EXPECTED_SERVICE_NAME: ${{ env.SERVICE_NAME }} |
| 198 | + GITHUB_RUN_ID: ${{ github.run_id }} |
| 199 | + AWS_REGION: ${{ env.AWS_REGION }} |
| 200 | + run: | |
| 201 | + go mod tidy |
| 202 | + go test ./... -v -tags=e2e -run TestE2ERunner |
| 203 | +
|
| 204 | + cleanup: |
| 205 | + if: always() |
| 206 | + runs-on: ubuntu-latest |
| 207 | + needs: [publish-update-invoke, verify-e2e] |
| 208 | + steps: |
| 209 | + - name: Configure AWS (User Credentials) |
| 210 | + uses: aws-actions/configure-aws-credentials@v4 |
| 211 | + with: |
| 212 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 213 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 214 | + aws-region: ${{ inputs.aws_region || 'us-east-1' }} |
| 215 | + - name: Delete published layer version |
| 216 | + if: ${{ needs.publish-update-invoke.outputs.layer_arn != '' }} |
| 217 | + shell: bash |
| 218 | + run: | |
| 219 | + ARN="${{ needs.publish-update-invoke.outputs.layer_arn }}" |
| 220 | + LAYER_NAME=$(echo "$ARN" | cut -d: -f7) |
| 221 | + LAYER_VERSION=$(echo "$ARN" | cut -d: -f8) |
| 222 | + aws lambda delete-layer-version --layer-name "$LAYER_NAME" --version-number "$LAYER_VERSION" || echo "Failed to delete layer version." |
| 223 | +
|
| 224 | +
|
0 commit comments