-
Notifications
You must be signed in to change notification settings - Fork 106
[targets.aws] Add aws support, by rebasing PR #640 against main using Claude Code #1153
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
base: main
Are you sure you want to change the base?
Conversation
c834d54 to
843e40b
Compare
https://github.com/cloudprober/cloudprober/actions/runs/18236026696/job/51929810505?pr=1153 with the following prompt: ``` Fix up go build issues as identified by https://github.com/cloudprober/cloud prober/actions/runs/18236026696/job/51929810505?pr=1153 ```
Claude Code was given the prompt: ``` Update docs/ with details of the AWS discovery mechanism and create an example config under @examples/aws/ ```
|
Friendly ping? It's also worth noting that AI did not generate any of this code, it's all by @rabunkosar-dd from #640 |
|
Second friendly ping? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking this long. I had entered half the comment, but didn't get time to finish. They are the same comments as on the original PR.
internal/rds/aws/aws.go
Outdated
| for k := range resTypes { | ||
| switch k { | ||
| case ResourceTypes.EC2Instances: | ||
| c.Ec2Instances = &configpb.EC2Instances{ | ||
| ReEvalSec: proto.Int32(int32(reEvalSec)), | ||
| } | ||
|
|
||
| case ResourceTypes.ElastiCacheClusters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's too early to define this function, e.g. I am not even sure if we'll need to add ReEvalSec to all different resource types. It'll be better to try to implement one of the resource type (perhaps in a different PR) and see what all do we need. Then we can add more resource types in a single PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored this function to use a map instead of a switch statement
…e file, they're not used anymore
Co-authored-by: Claude Code v2.0.27 + Claude Sonnet 4.5, with the prompt: ``` Refactor code under @internal/rds/aws to reduce the functionity down to only discover EC2, RDS and Endpoint targets ```
…to improve test coverage Co-authored-by: Claude Code v2.0.28 + Claude Sonnet 4.5, with the prompt: ``` Refactor `DefaultProviderConfig()` in @internal/rds/aws to not just be a wrapper around a switch statement. Refactor @internal/rds/aws/aws_test.go to improve test coverage ```
8a37932 to
4d1640e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL
internal/rds/aws/aws.go
Outdated
| for k := range resTypes { | ||
| switch k { | ||
| case ResourceTypes.EC2Instances: | ||
| c.Ec2Instances = &configpb.EC2Instances{ | ||
| ReEvalSec: proto.Int32(int32(reEvalSec)), | ||
| } | ||
|
|
||
| case ResourceTypes.ElastiCacheClusters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored this function to use a map instead of a switch statement
| // ResourceTypes declares resource types supported by the AWS provider. | ||
| var ResourceTypes = struct { | ||
| EC2Instances, RDSClusters, RDSInstances string | ||
| }{ | ||
| "ec2_instances", | ||
| "rds_clusters", | ||
| "rds_instances", | ||
| } | ||
|
|
||
| type lister interface { | ||
| listResources(req *pb.ListResourcesRequest) ([]*pb.Resource, error) | ||
| } | ||
|
|
||
| // Provider implements a AWS provider for a ResourceDiscovery server. | ||
| type Provider struct { | ||
| listers map[string]lister | ||
| } | ||
|
|
||
| // ListResources returns the list of resources based on the given request. | ||
| func (p *Provider) ListResources(req *pb.ListResourcesRequest) (*pb.ListResourcesResponse, error) { | ||
| lr := p.listers[req.GetResourcePath()] | ||
| if lr == nil { | ||
| return nil, fmt.Errorf("unknown resource type: %s", req.GetResourcePath()) | ||
| } | ||
|
|
||
| resources, err := lr.listResources(req) | ||
| return &pb.ListResourcesResponse{Resources: resources}, err | ||
| } | ||
|
|
||
| func initAWSProject(c *configpb.ProviderConfig, l *logger.Logger) (map[string]lister, error) { | ||
| resourceLister := make(map[string]lister) | ||
|
|
||
| // TODO when resources are added | ||
|
|
||
| return resourceLister, nil | ||
| } | ||
|
|
||
| // New creates a AWS provider for RDS server, based on the provided config. | ||
| func New(c *configpb.ProviderConfig, l *logger.Logger) (*Provider, error) { | ||
| resourceLister, err := initAWSProject(c, l) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &Provider{ | ||
| listers: resourceLister, | ||
| }, nil | ||
| } | ||
|
|
||
| // configSetter is a function type that sets a specific resource configuration | ||
| // in the ProviderConfig. | ||
| type configSetter func(*configpb.ProviderConfig, int32) | ||
|
|
||
| // resourceConfigSetters maps resource types to their corresponding config setter functions. | ||
| var resourceConfigSetters = map[string]configSetter{ | ||
| ResourceTypes.EC2Instances: func(c *configpb.ProviderConfig, reEvalSec int32) { | ||
| c.Ec2Instances = &configpb.EC2Instances{ | ||
| ReEvalSec: proto.Int32(reEvalSec), | ||
| } | ||
| }, | ||
| ResourceTypes.RDSInstances: func(c *configpb.ProviderConfig, reEvalSec int32) { | ||
| c.RdsInstances = &configpb.RDSInstances{ | ||
| ReEvalSec: proto.Int32(reEvalSec), | ||
| } | ||
| }, | ||
| ResourceTypes.RDSClusters: func(c *configpb.ProviderConfig, reEvalSec int32) { | ||
| c.RdsClusters = &configpb.RDSClusters{ | ||
| ReEvalSec: proto.Int32(reEvalSec), | ||
| } | ||
| }, | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please do all this later, after implementing resource types, if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's wait for example, until after resource types are implemented. Same for all other examples.
Clone of #640 , and take 2 of #1075
Implements #7
To manage the rebase of a stale branch against cloudprober/cloudprober main, I turned to the git expert Claude Code, with the instructions:
Subsequently, Claude Code also updated the docs and config examples, following the prompt