Skip to content

Commit

Permalink
Smoke ci (#71)
Browse files Browse the repository at this point in the history
* add CI to validate cosl against worker and coordinator (tempo only for now)

* silenced debug databag log if empty

---------

Co-authored-by: michael <michael.dmitry98@gmail.com>
  • Loading branch information
PietroPasotti and michaeldmitry authored Sep 12, 2024
1 parent aad960e commit d52a372
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 4 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/distributed-solutions-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Distributed Solutions Tests

on:
push:
branches:
- main
pull_request:
workflow_call:

jobs:
test-distributed-charms:
runs-on: ubuntu-latest
continue-on-error: true

strategy:
fail-fast: false
matrix:
include:
- repo: canonical/tempo-coordinator-k8s-operator
- repo: canonical/tempo-worker-k8s-operator

steps:
- name: Checkout the ${{ matrix.repo }} repository
uses: actions/checkout@v4
with:
fetch-depth: 1
repository: ${{ matrix.repo }}
ref: main

- name: Update 'cosl' dependency in test charm to this branch
run: |
sed -i -e "/^cosl[ ><=]/d" -e "/canonical\/cos-lib/d" -e "/#egg=cosl/d" requirements.txt
echo -e "\ngit+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@${{ github.head_ref || github.ref_name }}#egg=cosl" >> requirements.txt
- name: Install dependencies (tox & yq)
run: pip install tox~=4.2 && sudo snap install yq

- name: Add charmcraft build dependencies (git)
run: yq e '.parts.charm.build-packages += ["git"]' -i charmcraft.yaml

- name: Run the charm's unit & scenario tests
id: unit
run: tox -e unit,scenario

- name: Run the charm's static analysis checks
id: static
run: tox -e static-charm,static-lib

- name: Setup Charmcraft's pip cache
uses: actions/cache@v4
with:
path: /home/runner/snap/charmcraft/common/cache/charmcraft/
key: charmcraft-cache-${{ github.job }}-${{ strategy.job-index }}-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: charmcraft-cache

- name: Get IP range
id: ip_range
run: |
echo "ip_range=$(ip -4 -j route get 2.2.2.2 | jq -r '.[] | .prefsrc')/32" >> $GITHUB_OUTPUT
- name: Setup operator environment (k8s)
uses: charmed-kubernetes/actions-operator@main
with:
juju-channel: 3.4/stable
provider: microk8s
channel: 1.26-strict/stable
microk8s-group: snap_microk8s
microk8s-addons: "hostpath-storage dns metallb:${{ steps.ip_range.outputs.ip_range }}"
charmcraft-channel: "2.x/stable"

- name: Run the charm's integration tests
run: tox -vve integration
if: steps.unit.outcome == 'success' && steps.static.outcome == 'success'
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
results/
.tox/
.nox/
.coverage
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ include = ["py.typed"]
# Testing tools configuration
[tool.coverage.run]
branch = true
parallel = true
omit = ["tests/**", "lib/**"]

[tool.coverage.report]
show_missing = true
Expand Down
3 changes: 2 additions & 1 deletion src/cosl/coordinated_workers/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def load(cls, databag: _RawDatabag):
return cls.model_validate_json(json.dumps(data)) # type: ignore
except pydantic.ValidationError as e:
msg = f"failed to validate databag: {databag}"
log.debug(msg, exc_info=True)
if databag:
log.debug(msg, exc_info=True)
raise DataValidationError(msg) from e

def dump(self, databag: Optional[_RawDatabag] = None, clear: bool = True) -> _RawDatabag:
Expand Down
9 changes: 8 additions & 1 deletion src/cosl/loki_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,18 @@ def build_labels(self, record: logging.LogRecord) -> Dict[str, str]:
labels[self.level_label] = record.levelname.lower()
labels[self.logger_label] = record.name

extra_labels = getattr(record, "labels", {})
# if the user implemented a logrecord subclass with a .labels attributes, attempt to
# respect it and add those labels on top of those registered on the LokiEmitter class.
extra_labels: Any = getattr(record, "labels", {})
if not isinstance(extra_labels, dict):
return labels

label_name: Any
label_value: Any
for label_name, label_value in extra_labels.items():
if not isinstance(label_name, str) or not isinstance(label_value, str):
return labels

cleared_name = self.format_label(label_name)
if cleared_name:
labels[cleared_name] = label_value
Expand Down
9 changes: 8 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,11 @@ setenv =
commands =
python -m doctest {[vars]src_path}/cosl/mandatory_relation_pairs.py
/usr/bin/env sh -c 'stat cos-tool-amd64 > /dev/null 2>&1 || curl -L -O https://github.com/canonical/cos-tool/releases/latest/download/cos-tool-amd64'
pytest --cov-report=html:.cover --cov {[vars]src_path} -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tst_path}
pytest {tty:--color=yes} --cov={[vars]src_path} --cov-config={tox_root}/pyproject.toml \
; for us
--cov-report=html:{tox_root}/results/html-cov/ \
; for tiobe
--cov-report=xml:{tox_root}/results/coverage-{env_name}.xml \
; for sparta
--cov-report=json:{tox_root}/results/tox-{env_name}.json \
--junit-xml={tox_root}/results/test-results-{env_name}.xml {posargs}

0 comments on commit d52a372

Please sign in to comment.