Skip to content

Instantly share code, notes, and snippets.

@Stoakes
Created December 27, 2019 20:26

Revisions

  1. Stoakes created this gist Dec 27, 2019.
    10 changes: 10 additions & 0 deletions config.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    {
    "xds_servers": [
    {
    "server_uri": "istio-pilot:15010",
    "channel_creds": [{}]
    }],
    "node": {
    "id": "sidecar~192.168.0.1~xds.default~default.svc.cluster.local"
    }
    }
    48 changes: 48 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    package main

    import (
    "io/ioutil"
    "os"

    "github.com/Stoakes/go-pkg/log"
    "golang.org/x/net/context"
    "google.golang.org/grpc"
    "google.golang.org/grpc/grpclog"
    _ "google.golang.org/grpc/xds/experimental"
    )

    var (
    xdsScheme = "xds-experimental-new"
    helloService = "localhost:8080"
    )

    func main() {
    logg := grpclog.NewLoggerV2(os.Stdout, ioutil.Discard, ioutil.Discard)
    grpclog.SetLoggerV2(logg)
    ctx, cancel := context.WithCancel(context.Background())
    defer cancel()

    log.Setup(ctx, log.Options{
    Debug: true,
    LogLevel: "debug",
    AppName: "xds-demo",
    AppID: "appId",
    Version: "0.0.1",
    })

    log.For(ctx).Info("Connecting to hello service at " + helloService)
    _, err := dial(helloService)
    if err != nil {
    log.For(ctx).Fatalf("Connection to hello-service error :%v", err)
    }

    }

    // Dial dial an headless service with loadBalancing Options
    func dial(targetStr string, dialOpts ...grpc.DialOption) (*grpc.ClientConn, error) {
    log.Bg().Debug("Dialing " + xdsScheme + ":///" + targetStr)
    return grpc.Dial(xdsScheme+":///"+targetStr, []grpc.DialOption{
    grpc.WithBlock(),
    grpc.WithInsecure()}...,
    )
    }
    3 changes: 3 additions & 0 deletions start.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    #!/bin/bash

    GRPC_GO_LOG_SEVERITY_LEVEL=16 GRPC_XDS_BOOTSTRAP=$(pwd)/config.json ./xds-demo