Categorygithub.com/hudl/fargo
modulepackage
1.4.0
Repository: https://github.com/hudl/fargo.git
Documentation: pkg.go.dev

# README

fargo

Netflix Eureka client in golang. Named for the show Eureka.

c = fargo.NewConn("http://127.0.0.1:8080/eureka/v2")
c.GetApps() // returns a map[String]fargo.Application

Testing

Tests can be executed using docker container. See the below section to build and start all the required containers. Once the Eureka containers are running, and fargo image is built then you can run the command as follows:

Run:

docker run --rm -v "$PWD":/go/src/github.com/hudl/fargo -w /go/src/github.com/hudl/fargo hudloss/fargo:master go test -v ./...

Note: If you are running bash for Windows add MSYS_NO_PATHCONV=1 at the beginning.

The tests may need to be run a couple of times to allow changes to propagate between the two Eureka servers. If the tests are failing, try running them again approximately 30 seconds later.

If you are adding new packages to godep you may want to update the hudloss/fargo image first.

Known Issues

Until this PR is in an official vagrant release, the Fedora 19 opscode box will fail when setting up private networks in vagrant 1.2.5 and later.

FAQ

Q: Is this a full client?

A: Not yet. It's very much a work in progress, and it's also being built with consideration for Go idioms, which means some Java-isms will never be included.

Q: Does it cache?

A: No, it does not support caching records.

Q: Can I integrate this into my Go app and have it manage hearbeats to Eureka?

A: Glad you asked, of course you can. Just grab an application (for this example, "TESTAPP")

// register a couple instances, and then set up to only heartbeat one of them
e, _ := fargo.NewConnFromConfigFile("/etc/fargo.gcfg")
app, _ := e.GetApp("TESTAPP")
// starts a goroutine that updates the application on poll interval
e.UpdateApp(&app)
for {
    for _, ins := range app.Instances {
        fmt.Printf("%s, ", ins.HostName)
    }
    fmt.Println(len(app.Instances))
    <-time.After(10 * time.Second)
}
// You'll see all the instances at first, and within a minute or two all the
// ones that aren't heartbeating will disappear from the list. Note that after
// calling `UpdateApp` there's no need to manually update

TODO

  • Actually do something with AWS availability zone info
  • Currently the load balancing is random, and does not give preference to servers within a zone.
  • Make releases available on gopkg.in

Hacking

Just Let Me Import Already

go get github.com/hudl/fargo


package main

import (
    "github.com/hudl/fargo"
)

func main() {
    e, _ := fargo.NewConnFromConfigFile("/etc/fargo.gcfg")
    e.AppWatchChannel
}

Adding Stuff

go test is your friend. I use the excellent goconvey library in addition to the standard lib's testing package. If you add something, write a test. If something is broken, write a test that reproduces your issue or post repro steps to the issues on this repository. The tests require that you have a eureka install and are designed to run against the included vagrant specs.

Verifying Releases

We're on semver and tag releases accordingly. The releases are signed and can be verified with git tag --verify vA.B.C.

Using Docker

Fargo is tested against two eureka versions, v1.1.147 and v1.3.1. To support testing, we provide Docker containers that supply Eureka locally. Here's how to get started.

  1. Clone Fargo
  2. If you don't have it, install Docker.
# Defaults to 1.1.147, can be set to 1.3.1
EUREKA_VERSION=1.1.147

cp docker-compose.override.yml.dist docker-compose.override.yml

docker-compose up -d

# Run the tests

Contributors

  • Ryan S. Brown (ryansb)
  • Carl Quinn (cquinn)

MIT License

The MIT License (MIT). Please see License File for more information.

# Packages

No description provided by the author

# Functions

HTTPResponseStatusCode extracts the HTTP status code for the response from Eureka that motivated the supplied error, if any.
NewConn is a default connection with just a list of ServiceUrls.
NewConnFromConfig will, given a Config struct, return a connection based on those options.
NewConnFromConfigFile sets up a connection object based on a config in specified path.
ReadConfig from a file location.
Shuffled requests randomizing the order of the sequence of instances returned, using the default shared rand.Source.
ShuffledWith requests randomizing the order of the sequence of instances returned, using the supplied source of random numbers.
ThatAreUp restricts the set of instances returned to only those with status UP.
WithStatus restricts the set of instances returned to only those with the given status.

# Constants

Datacenter names.
Supported statuses.
Datacenter names.
Supported statuses.
Supported statuses.
Supported statuses.
Supported statuses.

# Variables

No description provided by the author
EurekaURLSlugs is a map of resource names->Eureka URLs.
No description provided by the author

# Structs

AmazonMetadataType is information about AZ's, AMI's, and the AWS instance.
Application deserializeable from Eureka XML.
No description provided by the author
An AppSource holds a periodically updated copy of a Eureka application.
AppUpdate is the outcome of an attempt to get a fresh snapshot of a Eureka application's state, together with an error that may have occurred in that attempt.
Config is a base struct to be read by code.google.com/p/gcfg.
DataCenterInfo indicates which type of data center hosts this instance and conveys details about the instance's environment.
EurekaConnection is the settings required to make Eureka requests.
GetAppResponseJson wraps an Application for deserializing from Eureka JSON.
GetAppsResponse lets us deserialize the eureka/v2/apps response XML.
GetAppsResponseJson lets us deserialize the eureka/v2/apps response JSON—a wrapped GetAppsResponse.
Instance [de]serializeable [to|from] Eureka [XML|JSON].
InstanceMetadata represents the eureka metadata, which is arbitrary XML.
An InstanceSetSource holds a periodically updated set of instances registered with Eureka.
InstanceSetUpdate is the outcome of an attempt to get a fresh snapshot of a Eureka VIP address's set of instances, together with an error that may have occurred in that attempt.
LeaseInfo tells us about the renewal from Eureka, including how old it is.
No description provided by the author
RegisterInstanceJson lets us serialize the eureka/v2/apps/<ins> request JSON—a wrapped Instance.

# Type aliases

InstanceQueryOption is a customization supplied to instance query functions like GetInstancesByVIPAddress to tailor the set of instances returned.
StatusType is an enum of the different statuses allowed by Eureka.