Skip to content

Commit

Permalink
Added Prometheus support to Grand Central
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpardo committed Jan 25, 2024
1 parent 6c7eb07 commit ed60ffb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Unreleased

* Implemented a handler allowing changing the ``backendImage`` of ``grandCentral``.

* Added the Prometheus annotations to ``grandCentral`` to allow metrics scrapping on it.


2.33.0 (2023-11-14)
-------------------
Expand Down
1 change: 1 addition & 0 deletions crate/operator/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

GRAND_CENTRAL_RESOURCE_PREFIX = "grand-central"
GRAND_CENTRAL_BACKEND_API_PORT = 5050
GRAND_CENTRAL_PROMETHEUS_PORT = 8000


class CloudProvider(str, enum.Enum):
Expand Down
17 changes: 16 additions & 1 deletion crate/operator/grand_central.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

from crate.operator.constants import (
GRAND_CENTRAL_BACKEND_API_PORT,
GRAND_CENTRAL_PROMETHEUS_PORT,
GRAND_CENTRAL_RESOURCE_PREFIX,
LABEL_NAME,
SHARED_NODE_SELECTOR_KEY,
Expand Down Expand Up @@ -116,10 +117,15 @@ def get_grand_central_deployment(
),
),
]
annotations = {
"prometheus.io/port": str(GRAND_CENTRAL_PROMETHEUS_PORT),
"prometheus.io/scrape": "true",
}
return V1Deployment(
metadata=V1ObjectMeta(
name=f"{GRAND_CENTRAL_RESOURCE_PREFIX}-{name}",
labels=labels,
annotations=annotations,
owner_references=owner_references,
),
spec=V1DeploymentSpec(
Expand All @@ -145,7 +151,11 @@ def get_grand_central_deployment(
V1ContainerPort(
container_port=GRAND_CENTRAL_BACKEND_API_PORT,
name="grand-central",
)
),
V1ContainerPort(
container_port=GRAND_CENTRAL_PROMETHEUS_PORT,
name="prometheus",
),
],
resources=V1ResourceRequirements(
limits={
Expand Down Expand Up @@ -216,6 +226,11 @@ def get_grand_central_service(
port=GRAND_CENTRAL_BACKEND_API_PORT,
target_port=GRAND_CENTRAL_BACKEND_API_PORT,
),
V1ServicePort(
name="prometheus",
port=GRAND_CENTRAL_PROMETHEUS_PORT,
target_port=GRAND_CENTRAL_PROMETHEUS_PORT,
),
],
selector={LABEL_NAME: f"{GRAND_CENTRAL_RESOURCE_PREFIX}-{name}"},
),
Expand Down
28 changes: 28 additions & 0 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from crate.operator.constants import (
API_GROUP,
DATA_PVC_NAME_PREFIX,
GRAND_CENTRAL_PROMETHEUS_PORT,
GRAND_CENTRAL_RESOURCE_PREFIX,
LABEL_COMPONENT,
LABEL_MANAGED_BY,
Expand Down Expand Up @@ -1265,6 +1266,33 @@ async def test_create_with_grand_central_backend_enabled(
== "my-crate-cluster.gc.aks1.eastus.azure.cratedb-dev.net"
)

# Test Prometheus
assert deploy.metadata.annotations["prometheus.io/scrape"] == "true"
assert deploy.metadata.annotations["prometheus.io/port"] == str(
GRAND_CENTRAL_PROMETHEUS_PORT
)
app_prometheus_port = next(
(
port.container_port
for port in deploy.spec.template.spec.containers[0].ports
if port.name == "prometheus"
),
None,
)
assert app_prometheus_port == GRAND_CENTRAL_PROMETHEUS_PORT

service = await core.read_namespaced_service(
namespace=namespace.metadata.name,
name=f"{GRAND_CENTRAL_RESOURCE_PREFIX}-{name}",
)
svc_prometheus_port = next(
(port for port in service.spec.ports if port.name == "prometheus"),
None,
)
assert svc_prometheus_port
assert svc_prometheus_port.port == GRAND_CENTRAL_PROMETHEUS_PORT
assert svc_prometheus_port.target_port == GRAND_CENTRAL_PROMETHEUS_PORT

async def test_preserve_unknown_object_keys(
self, faker, namespace, cratedb_crd, api_client
):
Expand Down

0 comments on commit ed60ffb

Please sign in to comment.