Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions tests/test_unstable/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import logging
import random
from collections.abc import Generator
from io import StringIO
from pathlib import Path

import pytest
import yaml

from cognite.client import CogniteClient
from cognite.client.exceptions import CogniteNotFoundError
from cognite.extractorutils.metrics import PrometheusPusher
from cognite.extractorutils.statestore.watermark import LocalStateStore, RawStateStore
from cognite.extractorutils.unstable.configuration.loaders import load_file
from cognite.extractorutils.unstable.configuration.loaders import ConfigFormat, load_io
from cognite.extractorutils.unstable.configuration.models import (
ConnectionConfig,
LocalStateStoreConfig,
Expand Down Expand Up @@ -298,30 +298,26 @@ def counting_push(self: "PrometheusPusher") -> None:
assert call_count["count"] > 0


def test_pushgatewayconfig_none_credentials_from_yaml(tmp_path: Path) -> None:
yaml_config = {
"push_gateways": [
{
"host": "http://localhost:9091",
"job_name": "test-job",
"clear_after": None,
}
],
"cognite": None,
"server": None,
}
yaml_file = tmp_path / "metrics_config.yaml"
with open(yaml_file, "w") as f:
yaml.dump(yaml_config, f)
def test_pushgatewayconfig_none_credentials_from_yaml() -> None:
config_str = """
push-gateways:
- host: "http://localhost:9091"
job_name: "test-job"
clear_after: null
username: null
cognite: null
server: null
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing I wanted to verify was that this works without explicitly setting x: null, so leave those out. We generally don't encourage explicitly setting things to null in yaml configs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, password is not set explicitly to null, so this is working (I want to verify if explicitly setting to null is also working i.e. username).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then add another test where you don't set them to null explicitly. Setting them to null is the exception, not the rule, and I would prefer if tests verified the intended usage as well as any corner cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing I wanted to verify was that this works without explicitly setting x: null, so leave those out. We generally don't encourage explicitly setting things to null in yaml configs.

Made the changes, I got your point why we do require to set the defaults and not passing null explicitly.


metrics_config = load_file(yaml_file, MetricsConfig)
"""

config = metrics_config.push_gateways[0]
stream = StringIO(config_str)
config = load_io(stream, ConfigFormat.YAML, MetricsConfig)
metrics_config = config.push_gateways[0]
pusher = PrometheusPusher(
job_name=config.job_name,
username=config.username,
password=config.password,
url=config.host,
job_name=metrics_config.job_name,
username=metrics_config.username,
password=metrics_config.password,
url=metrics_config.host,
push_interval=30,
thread_name="TestPusher",
cancellation_token=None,
Expand Down
Loading