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

First cut of adding support for appmesh #9260

Merged
merged 19 commits into from
Feb 6, 2024
Merged

First cut of adding support for appmesh #9260

merged 19 commits into from
Feb 6, 2024

Conversation

Johnlon
Copy link
Contributor

@Johnlon Johnlon commented Jan 26, 2024

Added basic appmesh support.

Also incidentally attempts to provide some useful documentation in the code on how to use the API's and write such an extension.
Perhaps in a later PR this could be written up as a primer or something.

@Johnlon Johnlon requested a review from kapilt as a code owner January 26, 2024 15:59
@Johnlon Johnlon mentioned this pull request Jan 26, 2024
# skip the enum call entirely.
#
# TODO: Propose an improvement where we allow skipping of the
# enum_spec call self.source.get_resources(ids)
Copy link
Collaborator

Choose a reason for hiding this comment

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

a source subclass is free to do that, normally this is not in a query manager, but a describe source subclass, you can grep DescribeSource for extant examples .

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 removed my logic as it meant the pull and event models differred.

@kapilt
Copy link
Collaborator

kapilt commented Jan 27, 2024

Thanks for the pr. there's a couple of failing tests, since config is supported for app mesh the overrides on resources/get_resources need to go into a describe source subclass, also since supported by aws config, cfn_type should be defined in resource_type. it also appears some of the arn_types are invalid, fwiw, we test this against the aws iam documentation re valid arn types. you can run tests locally w/ make test and lint w/ make lint

@kapilt
Copy link
Collaborator

kapilt commented Jan 27, 2024

looking at the arn type issue, the arn_type per custodian is always mesh, but their is a subtype per child, per resource arns in the iam docs https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsappmesh.html#awsappmesh-resources-for-iam-policies

as a result you'll likely need to override get_arns in the child resources.

@Johnlon
Copy link
Contributor Author

Johnlon commented Feb 3, 2024

UPDATE : I've given is a crack fixing the tests - please take look at my commits

hi @kapilt

I can see test_config_resource_support has failed however there isn't any documentation or other commentary in the test to explain it's objectives. What is the test attempting to verify.

I can make the test pass by removing stuff from 'whitelist', but I don't know what I'm doing.


Also what is the meaning of this comment in the same test...
# for several of these we express support as filter or action instead
# of a resource.

And this comment and the others like it ...
# q4 2023 wave 2 (aka reinvent)

@Johnlon
Copy link
Contributor Author

Johnlon commented Feb 3, 2024

I can't run all the test as the moment as they blow up in random places when I run "make test".
I'm guessing it's because I am working on Windows 11 at the moment.
I will have a new machine next week with WSL where I can give it another try.

I don't know why my win11 build blows up in some random tests but I'll look at the windows server build below.

@Johnlon
Copy link
Contributor Author

Johnlon commented Feb 4, 2024

as a result you'll likely need to override get_arns in the child resources.

Hi I see "likely" - is there some doubt about needing to implement? Also is there some API documentation and hopefully some specific acceptance test for my classes (or specifically get_arns) to tdd my solution?

Apologies but I can run some of the tests locally but not the full "make" set. I can show you a log of what I see if needed.

UPDATE: I found the windows build. Sorry the GitHub UI has a scroll bar below that I hadn't noticed that hides the windows stuff. I will look.

FURTHER UPDATE: I changed core query.py to allow "arn" and "id" fields to be paths so that I didn't need to implement get_arns() - please check my logic - I couldn't find tests for query.py to edit - please let me know.

Thanks

…on value not just a field name.

... to allow ....
- Changed appmesh virtual gateway "arn" attribute to be a path to the necessary attribute

Also ...
- Removed my override of get_resources because it resulted in the models in pull and in event modes to be different meaning policies would not be portable.
- Resolved some failing tests.
c7n/query.py Outdated
@@ -625,9 +635,9 @@ def get_arns(self, resources):
id_key = m.id

for r in resources:
_id = r[id_key]
_id = jmespath_search(id_key, r)
Copy link
Collaborator

Choose a reason for hiding this comment

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

preference would be to to implement the get_arns method in the subclass versus putting it on the base, as jmespath execution is actually relatively expensive on cost, versus a key lookup for a high cardinality resources. ie only pay the cost when its actually needed by putting the logic specific to the resource types that need it.

id = name = 'meshName'

# if a resource type is supported by resource group tagging api setting this value get tag filters/actions
universal_taggable = object()
Copy link
Collaborator

Choose a reason for hiding this comment

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

fwiw added this to get default tag filters/actions

class DescribeMesh(DescribeSource):
# override default describe augment to get tags
def augment(self, resources):
return universal_augment(self.manager, resources)
Copy link
Collaborator

Choose a reason for hiding this comment

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

custodian defaults to fetching tags for resources, this describe source customization ensure that for this resource type.


class DescribeGatewayDefinition(ChildDescribeSource):
def __init__(self, manager):
super().__init__(manager)
Copy link
Collaborator

Choose a reason for hiding this comment

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

fwiw, override isn't needed, describe virtual gateway includes the mesh name / parent id.

Copy link
Collaborator

@kapilt kapilt left a comment

Choose a reason for hiding this comment

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

lgtm, thanks

@Johnlon
Copy link
Contributor Author

Johnlon commented Feb 6, 2024

@kapilt Hi I found that the developer instructions here https://cloudcustodian.io/docs/developer/installing.html#developer-installing

Work fine on a Linux but the Makefile doesn't work on Windows as it seems to contain a bunch of non-portable stuff.
Other instructions seem to not work without hacking on windows.

Are there some instructions for building it and running all the tests for Windows? Thanks

@kapilt
Copy link
Collaborator

kapilt commented Feb 6, 2024

@Johnlon I was planning on setting up a windows vm next week to run through some fixes for #9230 I can check the developer workflow on it then.

wrt to this pr, everything seems to work in windows in ci, so I think its good to go.

@kapilt kapilt merged commit 561f595 into cloud-custodian:main Feb 6, 2024
22 checks passed
@Johnlon
Copy link
Contributor Author

Johnlon commented Feb 6, 2024

Wow thanks

How do we get it into next build?

@Johnlon
Copy link
Contributor Author

Johnlon commented Feb 6, 2024

Like I said I have a few more to do and need a bit more understanding on the changes you made and in fact what some of it means.

Btw have some more doco changes I want to record in appmesh before pull

@Johnlon
Copy link
Contributor Author

Johnlon commented Feb 7, 2024

Pushed some.commets

@Johnlon
Copy link
Contributor Author

Johnlon commented Feb 7, 2024

Btw perhaps make a note that python 12 has a problem that prevents it being used in debugger at least on window. I used 3.11.

@Johnlon
Copy link
Contributor Author

Johnlon commented Feb 7, 2024

Windows needs things like ms ask too

@Johnlon
Copy link
Contributor Author

Johnlon commented Feb 7, 2024

Hi I need help writing proper tests for this extension.
If I put random values in certain fields of the extension then the tests still pass. For example "id" on the gateway class can be any value including non strings.
I don't understand how I can get a failing test to confirm the impact of the config.
If I was doing tdd I wouldn't have been able to write the extension I believe.

I suspect part (not all) of the problem is that the placebo library is deficient in that the test library makes no attempt to match the API params to the test data files. It just dumbly replays the files. There isn't even a good way to be absolutely sure the API isn't making excessive calls because it round robins the files. There is no way to be strict in placebo. To be honest placebo is pretty suboptimal compared to proper mocking of responses Vs request params.

Any thoughts?

There are probably other things I'm not understanding that would help me thoroughly functional test all the params on the extension.

Any ideas?

At the moment the coverage is clearly very gappy.

@Johnlon
Copy link
Contributor Author

Johnlon commented Feb 8, 2024

@kapilt Hi need so help if you could.

I haver this branch of appmesh where you can see I have corrupted several of the field with a "!!!" in the values...
https://github.com/Johnlon/cloud-custodian/blob/Detailed-model-tests-AND-PROBLEMS/c7n/resources/appmesh.py

I did this because I was writing much more comprehensive tests include around the API calls made and I want to be sure that every cfg value has purpose and is referenced by a test or influences the outcome of a test,
However, I found a bunch of fields that seem to have no material impact on the behavior of the extension.

What tests if any should be emplyed to demonstrate something that relies on these values, as the fields seem completely redundant right now?


Please also take alook at test_appmesh.py for some clues on the extended testing.

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.

2 participants