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

App for TA collector mtls e2e tests #3120

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
17 changes: 17 additions & 0 deletions .chloggen/publish-test-e2e-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
swiatekm marked this conversation as resolved.
Show resolved Hide resolved
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: github action e2e test image

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Docker image for a simple server with a metrics endpoint that has authentication required"

# One or more tracking issues related to the change
issues: [1669]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Used for testing the feature that enables mTLS between the TA and the collector for scraping endpoints that have authentication
5 changes: 5 additions & 0 deletions .github/workflows/publish-test-e2e-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ jobs:
with:
path: nodejs
platforms: linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
metrics-basic-auth:
uses: ./.github/workflows/reusable-publish-test-e2e-images.yaml
with:
path: metrics-basic-auth
platforms: linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
10 changes: 10 additions & 0 deletions tests/test-e2e-apps/metrics-basic-auth/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.11-slim

COPY requirements.txt .
RUN pip install -r requirements.txt

COPY app.py .

EXPOSE 9123

CMD ["python", "app.py"]
36 changes: 36 additions & 0 deletions tests/test-e2e-apps/metrics-basic-auth/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
os.environ['PROMETHEUS_DISABLE_CREATED_SERIES'] = 'true'

from flask import Flask, Response, request
from prometheus_client import Gauge, generate_latest, REGISTRY, PROCESS_COLLECTOR, PLATFORM_COLLECTOR, GC_COLLECTOR

app = Flask(__name__)

REGISTRY.unregister(PROCESS_COLLECTOR)
REGISTRY.unregister(PLATFORM_COLLECTOR)
REGISTRY.unregister(GC_COLLECTOR)

secure = Gauge('authenticated', 'Client was authenticated')
secure.set(1)

USERNAME = "user"
PASSWORD = "t0p$ecreT"

def check_auth(username, password):
return username == USERNAME and password == PASSWORD

def authenticate():
return Response(
'Could not verify your access level for that URL.\n'
'You have to login with proper credentials', 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'})

@app.route('/metrics')
def metrics():
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return authenticate()
return Response(generate_latest(), mimetype='text/plain')

if __name__ == '__main__':
app.run(host='0.0.0.0', port=9123)
2 changes: 2 additions & 0 deletions tests/test-e2e-apps/metrics-basic-auth/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==2.3.3
prometheus_client==0.20.0
Loading