Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sd/etcd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ClientOptions struct {
Key string
CaCert string
DialTimeout time.Duration
DialKeepAline time.Duration
DialKeepAlive time.Duration
HeaderTimeoutPerRequest time.Duration
}

Expand Down Expand Up @@ -83,7 +83,7 @@ func NewClient(ctx context.Context, machines []string, options ClientOptions) (C
Dial: func(network, addr string) (net.Conn, error) {
dial := &net.Dialer{
Timeout: options.DialTimeout,
KeepAlive: options.DialKeepAline,
KeepAlive: options.DialKeepAlive,
}
return dial.Dial(network, addr)
},
Expand Down
6 changes: 3 additions & 3 deletions sd/etcd/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestNewClient(t *testing.T) {
Key: "",
CaCert: "",
DialTimeout: (2 * time.Second),
DialKeepAline: (2 * time.Second),
DialKeepAlive: (2 * time.Second),
HeaderTimeoutPerRequest: (2 * time.Second),
}

Expand All @@ -40,7 +40,7 @@ func TestOptions(t *testing.T) {
Key: "",
CaCert: "",
DialTimeout: (2 * time.Second),
DialKeepAline: (2 * time.Second),
DialKeepAlive: (2 * time.Second),
HeaderTimeoutPerRequest: (2 * time.Second),
})

Expand All @@ -60,7 +60,7 @@ func TestOptions(t *testing.T) {
Key: "blank.key",
CaCert: "blank.cacert",
DialTimeout: (2 * time.Second),
DialKeepAline: (2 * time.Second),
DialKeepAlive: (2 * time.Second),
HeaderTimeoutPerRequest: (2 * time.Second),
})

Expand Down
69 changes: 69 additions & 0 deletions sd/etcd/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package etcd

import (
"fmt"
"time"
"io"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/endpoint"
"golang.org/x/net/context"
)

// Package sd/etcd provides a wrapper around the coroes/etcd key value store (https://github.com/coreos/etcd)
// This example assumes the user has an instance of etcd installed and running locally on port 2379
func Example() {

var (
prefix = "/services/foosvc/" // known at compile time
instance = "1.2.3.4:8080" // taken from runtime or platform, somehow
key = prefix + instance
value = "http://" + instance // based on our transport
)

client, err := NewClient(context.Background(), []string{"http://:2379"}, ClientOptions{
DialTimeout: 2 * time.Second,
DialKeepAlive: 2 * time.Second,
HeaderTimeoutPerRequest: 2 * time.Second,
})

// Instantiate new instance of *Registrar passing in test data
registrar := NewRegistrar(client, Service{
Key: key,
Value: value,
}, log.NewNopLogger())
// Register new test data to etcd
registrar.Register()

//Retrieve entries from etcd
_, err = client.GetEntries(key)
if err != nil {
fmt.Println(err)
}

factory := func(string) (endpoint.Endpoint, io.Closer, error) {
return endpoint.Nop, nil, nil
}
subscriber, _ := NewSubscriber(client, prefix, factory, log.NewNopLogger())

endpoints, err := subscriber.Endpoints()
if err != nil {
fmt.Printf("err: %v", err)
}
fmt.Println(len(endpoints)) // hopefully 1

// Deregister first instance of test data
registrar.Deregister()

endpoints, err = subscriber.Endpoints()
if err != nil {
fmt.Printf("err: %v", err)
}
fmt.Println(len(endpoints)) // hopefully 0

// Verify test data no longer exists in etcd
_, err = client.GetEntries(key)
if err != nil {
fmt.Println(err)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(Comment pending discussion)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure. We can discuss here or slack. Whichever you prefer

}
2 changes: 1 addition & 1 deletion sd/etcd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestMain(m *testing.M) {
Key: "",
CaCert: "",
DialTimeout: (2 * time.Second),
DialKeepAline: (2 * time.Second),
DialKeepAlive: (2 * time.Second),
HeaderTimeoutPerRequest: (2 * time.Second),
}

Expand Down