Code Monkey home page Code Monkey logo

discovery's Introduction

discovery

Go Report Card Documentation license

Border0 service discovery framework and library.

Example: Discover EC2, ECS, and RDS Resources

Assume that the following variables are defined as follows:

ctx := context.Background()

cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
	// handle error
}

Then,

// initialize a new one off engine
engine := engines.NewOneOffEngine(
	engines.OneOffEngineOptionWithDiscoverers(
		discoverers.NewAwsEc2Discoverer(cfg),
		discoverers.NewAwsEcsDiscoverer(cfg),
		discoverers.NewAwsRdsDiscoverer(cfg),
		// ... LAN, docker, k8s, gcp compute, azure vms, etc ...
	),
)

// create channels for discovery results
results := make(chan *discovery.Result, 10)

// run engine
go engine.Run(ctx, results)

// process results as they come in
for result := range results {
	// ... do something ...
}

Example: Continuously Discover EC2, ECS, and RDS Resources

Assume that the following variables are defined as follows:

Assume that ctx (type context.Context) is defined by some upstream code

cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
	// handle error
}

Then,

// initialize a new continuous engine
engine := engines.NewContinuousEngine(
	engines.WithDiscoverer(
		discoverers.NewAwsEc2Discoverer(cfg),
		engines.WithInitialInterval(time.Second*2),
	),
	engines.WithDiscoverer(
		discoverers.NewAwsEcsDiscoverer(cfg),
		engines.WithInitialInterval(time.Second*2),
	),
	engines.WithDiscoverer(
		discoverers.NewAwsRdsDiscoverer(cfg),
		engines.WithInitialInterval(time.Second*2),
	),
)

// create channels for discovery results
results := make(chan *discovery.Result, 10)

// run engine
go engine.Run(ctx, results)

// process results as they come in
for result := range results {
	// ... do something ...
}

Example: Discover EC2 Instances In Multiple AWS Regions

Assume that the following variables are defined as follows:

awsRegions := []string{"us-east-1", "us-east-2", "us-west-2", "eu-west-1"}

ctx := context.Background()
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
	// handle error
}

Then,

// define an ec2 discoverer for each region
ds := []discovery.Discoverer{}
for _, region := range regions {
	cfg.Region = region

	ds = append(ds, discoverers.NewAwsEc2Discoverer(cfg))
}

// initialize a new one off engine with the discoverers
engine := engines.NewOneOffEngine(
	engines.OneOffEngineOptionWithDiscoverers(ds...),
)

// create channels for discovery results
results := make(chan *discovery.Result, 10)

// run engine
go engine.Run(ctx, results)

// process results as they come in
for result := range results {
	// ... do something ...
}

discovery's People

Contributors

adrianosela avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

Pedro Andrade avatar Rollie Ma avatar Andree Toonk avatar Greg Duraj avatar  avatar

discovery's Issues

Use Pagination in (List) AWS API Calls

Currently, we only get one page of results.

The aws go sdk v2 introduced a nice way to handle paginated results. e.g. for ECS clusters:

    client := ecs.NewFromConfig(cfg)

    // initialize the ListClustersPaginator with the ListClustersInput
    paginator := ecs.NewListClustersPaginator(client, &ecs.ListClustersInput{})

    // Loop until there are no more pages left
    for paginator.HasMorePages() {
        output, err := paginator.NextPage(context.TODO())
        if err != nil {
            log.Fatalf("failed to get a page, %v", err)
        }

        // process the page's results
        fmt.Println("Page results:", output.ClusterArns)
    }

    if paginator.Err() != nil {
        log.Fatalf("error occurred during pagination, %v", paginator.Err())
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.