Skip to content

Conversation

@conallob
Copy link
Contributor

@conallob conallob commented Oct 3, 2025

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:

Rebase this branch against
  https://github.com/rabunkosar-dd/cloudprober/tree/add_aws_support , then
  rebase the branch against upstream, before integrating the feedback provided
  in https://github.com/cloudprober/cloudprober/pull/640#pullrequestreview-18
  17277625

Subsequently, Claude Code also updated the docs and config examples, following the prompt

Update docs/ with details of the AWS discovery mechanism and create an
  example config under @examples/aws/

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/
```
@conallob conallob changed the title Add aws support Add aws support, by rebasing PR #640 against main using Claude Code Oct 4, 2025
@conallob conallob marked this pull request as ready for review October 4, 2025 00:08
@conallob conallob changed the title Add aws support, by rebasing PR #640 against main using Claude Code [targets.aws] Add aws support, by rebasing PR #640 against main using Claude Code Oct 5, 2025
@conallob
Copy link
Contributor Author

Friendly ping?

It's also worth noting that AI did not generate any of this code, it's all by @rabunkosar-dd from #640

@conallob
Copy link
Contributor Author

Second friendly ping?

Copy link
Contributor

@manugarg manugarg left a 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.

Comment on lines 102 to 109
for k := range resTypes {
switch k {
case ResourceTypes.EC2Instances:
c.Ec2Instances = &configpb.EC2Instances{
ReEvalSec: proto.Int32(int32(reEvalSec)),
}

case ResourceTypes.ElastiCacheClusters:
Copy link
Contributor

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.

Copy link
Contributor Author

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

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
```
Copy link
Contributor Author

@conallob conallob left a comment

Choose a reason for hiding this comment

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

PTAL

Comment on lines 102 to 109
for k := range resTypes {
switch k {
case ResourceTypes.EC2Instances:
c.Ec2Instances = &configpb.EC2Instances{
ReEvalSec: proto.Int32(int32(reEvalSec)),
}

case ResourceTypes.ElastiCacheClusters:
Copy link
Contributor Author

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

Comment on lines +46 to +117
// 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),
}
},
}

Copy link
Contributor

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.

Copy link
Contributor

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.

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.

3 participants