Skip to content

Commit

Permalink
Add tests for Log forwarding to Loki (#57)
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Gildein <[email protected]>
  • Loading branch information
rgildein authored Nov 22, 2024
1 parent 6311f7f commit 25c904f
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 215 deletions.
15 changes: 15 additions & 0 deletions python/tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,18 @@ async def published_loki_logs(
log_lines = chunk["values"]
logs.update({line[0]: line[1] for line in log_lines})
return logs


def assert_logs(loki_address: str) -> None:
"""Check the existence of the logs."""
log_gl = urllib.parse.quote('{app="spark", pebble_service="sparkd"}')
query = json.loads(
urllib.request.urlopen(
f"http://{loki_address}:3100/loki/api/v1/query_range?query={log_gl}"
).read()
)

# NOTE: This check depends on previous tests, because without the previous ones
# there will be no logs.
logger.info(f"query: {query}")
assert len(query["data"]["result"]) != 0, "no logs was found"
19 changes: 19 additions & 0 deletions python/tests/integration/test_spark_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from .helpers import (
all_prometheus_exporters_data,
assert_logs,
get_cos_address,
get_secret_data,
juju_sleep,
Expand All @@ -35,6 +36,7 @@
HISTORY_SERVER = "history-server"
PUSHGATEWAY = "pushgateway"
PROMETHEUS = "prometheus"
LOKI = "loki"


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -266,6 +268,23 @@ async def test_spark_metrics_in_prometheus(
assert spark_id == spark_app_selector


@pytest.mark.abort_on_fail
@pytest.mark.asyncio
async def test_spark_logforwaring_to_loki(
ops_test: OpsTest, registry, service_account, cos
):
if not cos:
pytest.skip("Not possible to test without cos")

_, stdout, _ = await ops_test.juju("status")

logger.info(f"Show status: {stdout}")
with ops_test.model_context(COS_ALIAS) as cos_model:
status = await cos_model.get_status()
loki_address = status["applications"][LOKI]["units"][f"{LOKI}/0"]["address"]
assert_logs(loki_address)


@pytest.mark.abort_on_fail
@pytest.mark.asyncio
async def test_history_server_metrics_in_cos(ops_test: OpsTest, cos):
Expand Down
19 changes: 19 additions & 0 deletions python/tests/integration/test_spark_job_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from .helpers import (
all_prometheus_exporters_data,
assert_logs,
construct_azure_resource_uri,
get_cos_address,
get_secret_data,
Expand All @@ -37,6 +38,7 @@
HISTORY_SERVER = "history-server"
PUSHGATEWAY = "pushgateway"
PROMETHEUS = "prometheus"
LOKI = "loki"


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -263,6 +265,23 @@ async def test_job_in_prometheus(ops_test: OpsTest, registry, service_account, c
assert spark_id == spark_app_selector


@pytest.mark.abort_on_fail
@pytest.mark.asyncio
async def test_spark_logforwaring_to_loki(
ops_test: OpsTest, registry, service_account, cos
):
if not cos:
pytest.skip("Not possible to test without cos")

_, stdout, _ = await ops_test.juju("status")

logger.info(f"Show status: {stdout}")
with ops_test.model_context(COS_ALIAS) as cos_model:
status = await cos_model.get_status()
loki_address = status["applications"][LOKI]["units"][f"{LOKI}/0"]["address"]
assert_logs(loki_address)


@pytest.mark.abort_on_fail
@pytest.mark.asyncio
async def test_history_server_metrics_in_cos(ops_test: OpsTest, cos):
Expand Down
122 changes: 51 additions & 71 deletions releases/3.4/terraform/base/applications.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,159 +2,139 @@
# See LICENSE file for licensing details.

resource "juju_application" "history_server" {
name = "history-server"

model = var.model
name = "history-server"
model = var.model

charm {
name = "spark-history-server-k8s"
channel = "3.4/edge"
revision = 30
name = "spark-history-server-k8s"
channel = "3.4/edge"
revision = 33
}

resources = {
spark-history-server-image = 17 # 3.4.2
spark-history-server-image = "ghcr.io/canonical/charmed-spark@sha256:1d9949dc7266d814e6483f8d9ffafeff32f66bb9939e0ab29ccfd9d5003a583a" # 3.4.2
}

units = 1

units = 1
constraints = "arch=amd64"

}

resource "juju_application" "s3" {
name = "s3"

model = var.model
name = "s3"
model = var.model

charm {
name = "s3-integrator"
channel = "latest/edge"
name = "s3-integrator"
channel = "latest/edge"
revision = 17
}

config = {
path = "spark-events"
bucket = var.s3.bucket
endpoint = var.s3.endpoint
path = "spark-events"
bucket = var.s3.bucket
endpoint = var.s3.endpoint
}

units = 1

units = 1
constraints = "arch=amd64"

}


resource "juju_application" "kyuubi" {

name = "kyuubi"

model = var.model
name = "kyuubi"
model = var.model

charm {
name = "kyuubi-k8s"
channel = "latest/edge"
name = "kyuubi-k8s"
channel = "latest/edge"
revision = 27
}

resources = {
kyuubi-image = "ghcr.io/canonical/charmed-spark-kyuubi@sha256:9268d19a6eef91914e874734b320fab64908faf0f7adb8856be809bc60ecd1d0"
kyuubi-image = "ghcr.io/canonical/charmed-spark-kyuubi@sha256:9268d19a6eef91914e874734b320fab64908faf0f7adb8856be809bc60ecd1d0"
}

config = {
namespace = var.model
namespace = var.model
service-account = var.kyuubi_user
}

units = 3
trust = true

units = 3
trust = true
constraints = "arch=amd64"
}

resource "juju_application" "zookeeper" {

name = "zookeeper"

model = var.model
name = "zookeeper"
model = var.model

charm {
name = "zookeeper-k8s"
channel = "3/edge"
name = "zookeeper-k8s"
channel = "3/edge"
revision = 59
}

resources = {
zookeeper-image = 31
}

units = 3
units = 3
constraints = "arch=amd64"
}

resource "juju_application" "kyuubi_users" {
name = "kyuubi-users"

model = var.model
name = "kyuubi-users"
model = var.model

charm {
name = "postgresql-k8s"
channel = "14/stable"
name = "postgresql-k8s"
channel = "14/stable"
revision = 281
}

resources = {
postgresql-image = 159
postgresql-image = 159
}

units = 1
trust = true

units = 1
trust = true
constraints = "arch=amd64"

}

resource "juju_application" "metastore" {
name = "metastore"

model = var.model
name = "metastore"
model = var.model

charm {
name = "postgresql-k8s"
channel = "14/stable"
name = "postgresql-k8s"
channel = "14/stable"
revision = 281
}

resources = {
postgresql-image = 159
postgresql-image = 159
}

units = 1
trust = true

units = 1
trust = true
constraints = "arch=amd64"

}

resource "juju_application" "hub" {
name = "integration-hub"

model = var.model
name = "integration-hub"
model = var.model

charm {
name = "spark-integration-hub-k8s"
channel = "latest/edge"
revision = 20
name = "spark-integration-hub-k8s"
channel = "latest/edge"
revision = 22
}

resources = {
integration-hub-image = 3
integration-hub-image = 3
}

units = 1
trust = true

units = 1
trust = true
constraints = "arch=amd64"

}
}
Loading

0 comments on commit 25c904f

Please sign in to comment.