Skip to content

Commit

Permalink
Add tests for Log forwarding to Loki
Browse files Browse the repository at this point in the history
This PR provides simple tests for checking the that Loki contain some
logs from Spark job.

Update TF plan and bundles to use history-revision rev33 due #53 and
integration-hub rev22, since this revision provides new relation.

related: [charmed-spark-rock#114](canonical/charmed-spark-rock#114)

Signed-off-by: Robert Gildein <[email protected]>
  • Loading branch information
rgildein committed Nov 19, 2024
1 parent 983adc0 commit 6816c74
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 215 deletions.
29 changes: 29 additions & 0 deletions python/tests/integration/test_spark_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
HISTORY_SERVER = "history-server"
PUSHGATEWAY = "pushgateway"
PROMETHEUS = "prometheus"
LOKI = "loki"


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -266,6 +267,34 @@ 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"]

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(rgildein): 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"


@pytest.mark.abort_on_fail
@pytest.mark.asyncio
async def test_history_server_metrics_in_cos(ops_test: OpsTest, cos):
Expand Down
29 changes: 29 additions & 0 deletions python/tests/integration/test_spark_job_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
HISTORY_SERVER = "history-server"
PUSHGATEWAY = "pushgateway"
PROMETHEUS = "prometheus"
LOKI = "loki"


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -263,6 +264,34 @@ 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"]

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(rgildein): 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"


@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 6816c74

Please sign in to comment.