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

feat: enable metrics collection on docker compose example vec-409 #73

Closed
wants to merge 9 commits into from
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ cython_debug/
.vscode/
.DS_Store

# Aerospike specific
features.conf

# Example metadata
targets.json

# Kubernetes default generated dir
/kubernetes/generated
15 changes: 15 additions & 0 deletions .internal/metrics/config/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
global:
scrape_interval: 30s

scrape_configs:
- job_name: 'proximus'
file_sd_configs:
- files:
- '/etc/prometheus/targets.json'
metrics_path: '/manage/rest/v1/prometheus'

remote_write:
- url: 'https://avs-prometheus.aerospike.com/api/v1/write'
basic_auth:
username: 'avs-metrics'
password: 'avs-metrics-reporting'
62 changes: 62 additions & 0 deletions .internal/metrics/scripts/update_targets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import json
import ipaddress


DEFAULT_IP = "aerospike-vector-search"
DEFAULT_PORT = 5040


def ensure_requests_installed():
"""
Checks if the 'requests' library is installed. If not, it installs the library.
"""
try:
import requests
print("The 'requests' library is already installed.")
except ImportError:
import subprocess
import sys
print("The 'requests' library is not installed. Installing now...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "requests"])
print("The 'requests' library has been installed successfully.")


def get_public_ip():
"""
Fetches the public IP of the host using the external service ifconfig.me.
"""
try:
response = requests.get("https://ifconfig.me", timeout=5)
response.raise_for_status() # Raise an error for HTTP codes 4xx/5xx
return response.text.strip()
except Exception as e:
print(f"Error fetching public IP: {e}")
return None


def update_targets_file(ip_address, file_path="config/targets.json"):
targets = [
{
"targets": [f"{DEFAULT_IP}:{DEFAULT_PORT}"],
"labels": {
"instance": f"{ip_address}:{DEFAULT_PORT}",
},
}
]
with open(file_path, "w") as f:
json.dump(targets, f, indent=2)


if __name__ == "__main__":
ensure_requests_installed()
import requests
ip = get_public_ip()
try:
ipaddress.ip_address(ip)
print(f"Resolved external IP address: {ip}")
except ValueError:
print(f"Unable to resolve external IP address: {ip}")
print(f"using default IP address instead: {DEFAULT_IP}")
ip = DEFAULT_IP

update_targets_file(ip)
30 changes: 30 additions & 0 deletions docker/docker-compose-asdb-6.4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,36 @@ services:
# networks:
# - svc

# Services used to monitor the Aerospike Vector Search cluster.
# This collects basic usage metrics so that Aerospike can better understand AVS is being used.
# If you would like to disable this, you can remove the following services.

update-targets:
image: python:3.9-alpine
volumes:
- ../.internal/metrics/scripts/update_targets.py:/scripts/update_targets.py
- ../.internal/metrics/config:/config
entrypoint: ["sh", "-c", "python3 /scripts/update_targets.py"]
networks:
- svc

prometheus:
image: prom/prometheus:v2.45.0
volumes:
- ../.internal/metrics/config:/etc/prometheus
command:
- "--config.file=/etc/prometheus/prometheus.yml"
ports:
- "9090:9090"
depends_on:
update-targets:
condition: service_completed_successfully
aerospike-vector-search:
condition: service_healthy
networks:
- svc


networks:
svc:
name: svc
Expand Down
62 changes: 36 additions & 26 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
version: "3.9"

networks:
svc:
name: svc

services:
aerospike-cluster:
image: aerospike/aerospike-server-enterprise:7.0.0.5
Expand All @@ -12,52 +17,57 @@ services:
volumes:
- ${PWD}/config:/etc/aerospike
healthcheck:
# test: [ "CMD", "asinfo", "-U", "admin", "-P", "admin", "-p", "3000", "-v", "build" ]
test: [ "CMD", "asinfo", "-p", "3000", "-v", "build" ]
interval: 30s
timeout: 20s
retries: 3
networks:
- svc

aerospike-vector-search:
image: aerospike/aerospike-vector-search:0.11.1
container_name: "aerospike-vector-search"
depends_on:
aerospike-cluster:
condition: service_healthy
ports:
- "5000:5000"
- "5040:5040"
networks:
- svc
- "5000:5000"
- "5040:5040"
volumes:
- ${PWD}/config:/etc/aerospike-vector-search
healthcheck:
test: ["CMD", "curl", "-f", "http://aerospike-vector-search:5040/manage/rest/v1"]
interval: 30s
timeout: 20s
retries: 3
networks:
- svc

# aerospike-client:
# image: aerospike/aerospike-tools:10.2.1
# container_name: "aerospike-client"
# depends_on:
# aerospike-cluster:
# condition: service_healthy
# command: [
# "asadm",
# "-U", "admin",
# "-P", "admin",
# "-e", 'enable; manage acl create user tester password psw roles truncate sindex-admin user-admin data-admin read-write read write read-write-udf sys-admin udf-admin',
# "--no-config-file",
# "-h", "aerospike-cluster",
# "-p", "3000"
# ]
# networks:
# - svc

networks:
svc:
name: svc
# Services used to monitor the Aerospike Vector Search cluster.
# This collects basic usage metrics so that Aerospike can better understand AVS is being used.
# If you would like to disable this, you can remove the following services.

update-targets:
image: python:3.9-alpine
volumes:
- ../.internal/metrics/scripts/update_targets.py:/scripts/update_targets.py
- ../.internal/metrics/config:/config
entrypoint: ["sh", "-c", "python3 /scripts/update_targets.py"]
networks:
- svc

prometheus:
image: prom/prometheus:v2.45.0
volumes:
- ../.internal/metrics/config:/etc/prometheus
command:
- "--config.file=/etc/prometheus/prometheus.yml"
ports:
- "9090:9090"
depends_on:
update-targets:
condition: service_completed_successfully
aerospike-vector-search:
condition: service_healthy
networks:
- svc
37 changes: 33 additions & 4 deletions prism-image-search/docker-compose-asdb-6.4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
interval: 5s
timeout: 20s
retries: 10
avs:
aerospike-vector-search:
image: aerospike/aerospike-vector-search:0.11.1
environment:
FEATURE_KEY: "${FEATURE_KEY:-./container-volumes/avs/etc/aerospike-vector-search/features.conf}"
Expand All @@ -31,26 +31,55 @@ services:
- ./container-volumes/avs/etc/aerospike-vector-search:/etc/aerospike-vector-search
- ${FEATURE_KEY:-./container-volumes/avs/etc/aerospike-vector-search/features.conf}:/etc/aerospike-vector-search/features.conf:ro
healthcheck:
test: ["CMD", "curl", "-f", "http://avs:5040/manage/rest/v1"]
test: ["CMD", "curl", "-f", "http://aerospike-vector-search:5040/manage/rest/v1"]
interval: 5s
timeout: 20s
retries: 10
app:
image: "aerospike/prism-search-example:latest"
depends_on:
avs:
aerospike-vector-search:
condition: service_healthy
ports:
- "8080:8080"
networks:
- avs-demo
environment:
AVS_HOST: avs
AVS_HOST: aerospike-vector-search
AVS_PORT: "5000"
APP_NUM_QUOTES: "5000"
GRPC_DNS_RESOLVER: native
volumes:
- ./container-volumes/prism/images:/prism/static/images/data

# Services used to monitor the Aerospike Vector Search cluster.
# This collects basic usage metrics so that Aerospike can better understand AVS is being used.
# If you would like to disable this, you can remove the following services.

update-targets:
image: python:3.9-alpine
volumes:
- ../.internal/metrics/scripts/update_targets.py:/scripts/update_targets.py
- ../.internal/metrics/config:/config
entrypoint: ["sh", "-c", "python3 /scripts/update_targets.py"]
networks:
- avs-demo

prometheus:
image: prom/prometheus:v2.45.0
volumes:
- ../.internal/metrics/config:/etc/prometheus
command:
- "--config.file=/etc/prometheus/prometheus.yml"
ports:
- "9090:9090"
depends_on:
update-targets:
condition: service_completed_successfully
aerospike-vector-search:
condition: service_healthy
networks:
- avs-demo

networks:
avs-demo: {}
37 changes: 33 additions & 4 deletions prism-image-search/docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
interval: 5s
timeout: 20s
retries: 10
avs:
aerospike-vector-search:
image: aerospike/aerospike-vector-search:0.11.1
environment:
FEATURE_KEY: "${FEATURE_KEY:-./container-volumes/avs/etc/aerospike-vector-search/features.conf}"
Expand All @@ -32,26 +32,55 @@ services:
- ./container-volumes/avs/etc/aerospike-vector-search:/etc/aerospike-vector-search
- ${FEATURE_KEY:-./container-volumes/avs/etc/aerospike-vector-search/features.conf}:/etc/aerospike-vector-search/features.conf:ro
healthcheck:
test: ["CMD", "curl", "-f", "http://avs:5040/manage/rest/v1"]
test: ["CMD", "curl", "-f", "http://aerospike-vector-search:5040/manage/rest/v1"]
interval: 5s
timeout: 20s
retries: 10
app:
image: "prism:latest"
depends_on:
avs:
aerospike-vector-search:
condition: service_healthy
ports:
- "8080:8080"
networks:
- avs-demo
environment:
AVS_HOST: avs
AVS_HOST: aerospike-vector-search
AVS_PORT: "5000"
APP_NUM_QUOTES: "5000"
GRPC_DNS_RESOLVER: native
volumes:
- ./container-volumes/prism/images:/prism/static/images/data

# Services used to monitor the Aerospike Vector Search cluster.
# This collects basic usage metrics so that Aerospike can better understand AVS is being used.
# If you would like to disable this, you can remove the following services.

update-targets:
image: python:3.9-alpine
volumes:
- ../.internal/metrics/scripts/update_targets.py:/scripts/update_targets.py
- ../.internal/metrics/config:/config
entrypoint: ["sh", "-c", "python3 /scripts/update_targets.py"]
networks:
- avs-demo

prometheus:
image: prom/prometheus:v2.45.0
volumes:
- ../.internal/metrics/config:/etc/prometheus
command:
- "--config.file=/etc/prometheus/prometheus.yml"
ports:
- "9090:9090"
depends_on:
update-targets:
condition: service_completed_successfully
aerospike-vector-search:
condition: service_healthy
networks:
- avs-demo

networks:
avs-demo: {}
Loading
Loading