Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add checks and log_targets to ops.testing #1268

Merged
merged 23 commits into from
Jul 2, 2024

Conversation

amandahla
Copy link
Contributor

@amandahla amandahla commented Jun 21, 2024

Add checks and log_targets to ops.testing add_layer so it is possible to test it via Harness.

Fixes #1112

@amandahla amandahla changed the title Add checks to ops.testing fix: Add checks to ops.testing Jun 21, 2024
@amandahla amandahla changed the title fix: Add checks to ops.testing fix: Add checks and log_targets to ops.testing Jun 26, 2024
Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

Thanks for this. The structure is very good, but there are a few minor issues with the types and the merging logic.

@dimaqq
Copy link
Contributor

dimaqq commented Jun 27, 2024

[misunderstood smth, yanked comment]

Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

Code looks good now, approving! Just a couple of nit issues in the tests. I'll also ask another Charm Tech team member to review.

amandahla and others added 3 commits July 1, 2024 09:28
Co-authored-by: Ben Hoyt <benhoyt@gmail.com>
Co-authored-by: Ben Hoyt <benhoyt@gmail.com>
Co-authored-by: Ben Hoyt <benhoyt@gmail.com>
@amandahla amandahla changed the title fix: Add checks and log_targets to ops.testing fix: add checks and log_targets to ops.testing Jul 1, 2024
@amandahla amandahla changed the title fix: add checks and log_targets to ops.testing fix: add checks to ops.testing Jul 1, 2024
@amandahla
Copy link
Contributor Author

off topic: Why the PR title validation fails if I change it to "fix: add checks and log_targets to ops.testing"?

@benhoyt benhoyt changed the title fix: add checks to ops.testing fix: add checks and log_targets to ops.testing Jul 1, 2024
@benhoyt
Copy link
Collaborator

benhoyt commented Jul 1, 2024

off topic: Why the PR title validation fails if I change it to "fix: add checks and log_targets to ops.testing"?

@amandahla Must have been a glitch -- I just changed it back to that now, and it ran fine. We'll keep an eye on it.

@benhoyt benhoyt requested a review from tonyandrewmeyer July 1, 2024 21:02
@benhoyt
Copy link
Collaborator

benhoyt commented Jul 1, 2024

@amandahla We require two reviews for PRs on this repo, so I've asked one more Charm Tech reviewer to review this (probably in the next couple of days), but it's looking good!

Copy link
Contributor

@tonyandrewmeyer tonyandrewmeyer left a comment

Choose a reason for hiding this comment

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

A couple of small suggestions, but looks great, thanks!

Comment on lines +4291 to +4320
client.add_layer(
'foo',
pebble.Layer("""\
log-targets:
baz:
override: replace
type: loki
location: https://example123.com:3100/loki/api/v1/push
services:
- foo
labels:
key1: value1
"""),
combine=True,
)
plan = client.get_plan()
assert (
textwrap.dedent("""\
log-targets:
baz:
labels:
key1: value1
location: https://example123.com:3100/loki/api/v1/push
override: replace
services:
- foo
type: loki
""")
== plan.to_yaml()
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is asserting that the plan is equal to the second layer, right? Because override: replace was used.

I think the test would be clearer (and more resilient) if it made that explicit. Something like (untested):

Suggested change
client.add_layer(
'foo',
pebble.Layer("""\
log-targets:
baz:
override: replace
type: loki
location: https://example123.com:3100/loki/api/v1/push
services:
- foo
labels:
key1: value1
"""),
combine=True,
)
plan = client.get_plan()
assert (
textwrap.dedent("""\
log-targets:
baz:
labels:
key1: value1
location: https://example123.com:3100/loki/api/v1/push
override: replace
services:
- foo
type: loki
""")
== plan.to_yaml()
)
layer = pebble.Layer("""\
log-targets:
baz:
override: replace
type: loki
location: https://example123.com:3100/loki/api/v1/push
services:
- foo
labels:
key1: value1
"""
)
client.add_layer(
'foo',
layer,
combine=True,
)
plan = client.get_plan()
assert layer.to_yaml() == plan.to_yaml()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dont have a strong opinion about it so I don't mind changing it but to me the existing code looks explicit too :)
I follow the pattern in the test_add_layer_combine_override_replace. I'm afraid that changing just one of them would look confusing.

amandahla and others added 7 commits July 2, 2024 09:25
Co-authored-by: Tony Meyer <tony.meyer@gmail.com>
Co-authored-by: Tony Meyer <tony.meyer@gmail.com>
Co-authored-by: Tony Meyer <tony.meyer@gmail.com>
Presumption that next time will be ops 2.15.0 :)
@benhoyt benhoyt merged commit 5a21cd2 into canonical:main Jul 2, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Combine Pebble layers in testing get_plan; merge "checks" and "log-targets"
4 participants