-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Alexander <[email protected]> Co-authored-by: Alexander <[email protected]>
- Loading branch information
1 parent
a3969d0
commit fdef39f
Showing
29 changed files
with
552 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
name: CI Capacity Settlement | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
image_tag: | ||
type: string | ||
default: latest | ||
|
||
jobs: | ||
databricks_ci_build: | ||
uses: Energinet-DataHub/.github/.github/workflows/databricks-build-prerelease.yml@v14 | ||
with: | ||
python_version: 3.11.7 | ||
architecture: x64 | ||
wheel_working_directory: ./source/capacity_settlement | ||
prerelease_prefix: capacity_settlement | ||
|
||
unit_tests: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
# IMPORTANT: When adding a new folder here it should also be added in the `unit_test_check` job! | ||
tests_filter_expression: | ||
- name: Capacity Settlement | ||
paths: capacity_settlement_tests/ | ||
uses: Energinet-DataHub/.github/.github/workflows/python-ci.yml@v14 | ||
with: | ||
job_name: ${{ matrix.tests_filter_expression.name }} | ||
operating_system: dh3-ubuntu-20.04-4core | ||
path_static_checks: ./source/capacity_settlement | ||
# documented here: https://github.com/Energinet-DataHub/opengeh-wholesale/tree/main/source/databricks#styling-and-formatting | ||
ignore_errors_and_warning_flake8: E501,F401,E402,E203,W503 | ||
tests_folder_path: ./source/capacity_settlement/tests | ||
test_report_path: ./source/capacity_settlement/tests | ||
# See .docker/entrypoint.py on how to use the filter expression | ||
tests_filter_expression: ${{ matrix.tests_filter_expression.paths }} | ||
image_tag: ${{ inputs.image_tag }} | ||
|
||
# Check executed unit tests | ||
capacity_settlement_unit_test_check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ github.token }} | ||
|
||
- name: Execute python tests | ||
shell: bash | ||
id: test_count | ||
run: | | ||
# Small hack to get the repository name | ||
repository=${{ github.repository }} | ||
repository_owner=${{ github.repository_owner }} | ||
repository_name=${repository/$repository_owner\//} | ||
# IMPORTANT: When adding a new folder here, one must also add the folder | ||
# to one of the test jobs above! This is because this filter contains the sum of all folders | ||
# from test jobs. | ||
test_path="source/capacity_settlement/tests/" | ||
filter="capacity_settlement_tests/" | ||
chmod +x ./.devcontainer/check_test_count.sh | ||
IMAGE_TAG=${{ inputs.image_tag }} docker compose -f .devcontainer/docker-compose.yml run --rm -u root python-unit-test ./.devcontainer/check_test_count.sh $test_path $filter | ||
mypy_check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.x | ||
- name: Run pip install and mypy check of files in package | ||
shell: bash | ||
run: | | ||
pip install --upgrade pip | ||
pip install mypy types-python-dateutil | ||
mypy ./source/capacity_settlement --disallow-untyped-defs --ignore-missing-imports | ||
black_check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: psf/black@stable | ||
with: | ||
options: --check --diff | ||
src: ./source/capacity_settlement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
1 change: 1 addition & 0 deletions
1
source/capacity_settlement/capacity_settlement/entry_points/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .entry_point import execute |
72 changes: 72 additions & 0 deletions
72
source/capacity_settlement/capacity_settlement/entry_points/entry_point.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import os | ||
import sys | ||
from argparse import Namespace | ||
from collections.abc import Callable | ||
|
||
import telemetry_logging.logging_configuration as config | ||
from opentelemetry.trace import SpanKind | ||
from telemetry_logging.span_recording import span_record_exception | ||
|
||
from capacity_settlement.entry_points.job_args.capacity_settlement_args import ( | ||
CapacitySettlementArgs, | ||
) | ||
from capacity_settlement.entry_points.job_args.capacity_settlement_job_args import ( | ||
parse_command_line_arguments, | ||
parse_job_arguments, | ||
) | ||
|
||
|
||
def execute() -> None: | ||
applicationinsights_connection_string = os.getenv( | ||
"APPLICATIONINSIGHTS_CONNECTION_STRING" | ||
) | ||
|
||
start_with_deps( | ||
applicationinsights_connection_string=applicationinsights_connection_string, | ||
) | ||
|
||
|
||
def start_with_deps( | ||
*, | ||
cloud_role_name: str = "dbr-capacity-settlement", | ||
applicationinsights_connection_string: str | None = None, | ||
parse_command_line_args: Callable[..., Namespace] = parse_command_line_arguments, | ||
parse_job_args: Callable[..., CapacitySettlementArgs] = parse_job_arguments, | ||
) -> None: | ||
"""Start overload with explicit dependencies for easier testing.""" | ||
config.configure_logging( | ||
cloud_role_name=cloud_role_name, | ||
tracer_name="capacity-settlement-job", | ||
applicationinsights_connection_string=applicationinsights_connection_string, | ||
extras={"Subsystem": "measurements"}, | ||
) | ||
|
||
with config.get_tracer().start_as_current_span( | ||
__name__, kind=SpanKind.SERVER | ||
) as span: | ||
# Try/except added to enable adding custom fields to the exception as | ||
# the span attributes do not appear to be included in the exception. | ||
try: | ||
|
||
# The command line arguments are parsed to have necessary information for | ||
# coming log messages | ||
command_line_args = parse_command_line_args() | ||
|
||
# Add extra to structured logging data to be included in every log message. | ||
config.add_extras( | ||
{ | ||
"orchestration-instance-id": command_line_args.orchestration_instance_id, | ||
} | ||
) | ||
span.set_attributes(config.get_extras()) | ||
parse_job_args(command_line_args) | ||
|
||
# Added as ConfigArgParse uses sys.exit() rather than raising exceptions | ||
except SystemExit as e: | ||
if e.code != 0: | ||
span_record_exception(e, span) | ||
sys.exit(e.code) | ||
|
||
except Exception as e: | ||
span_record_exception(e, span) | ||
sys.exit(4) |
Empty file.
7 changes: 7 additions & 0 deletions
7
...capacity_settlement/capacity_settlement/entry_points/job_args/capacity_settlement_args.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from dataclasses import dataclass | ||
from uuid import UUID | ||
|
||
|
||
@dataclass | ||
class CapacitySettlementArgs: | ||
orchestration_instance_id: UUID |
Oops, something went wrong.