File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 11package diego_logging_client
22
33import (
4+ "cmp"
45 "fmt"
56 "time"
67
@@ -11,6 +12,7 @@ import (
1112// Config is the shared configuration between v1 and v2 clients.
1213type Config struct {
1314 UseV2API bool `json:"loggregator_use_v2_api"`
15+ APIHost string `json:"loggregator_api_host"`
1416 APIPort int `json:"loggregator_api_port"`
1517 CACertPath string `json:"loggregator_ca_path"`
1618 CertPath string `json:"loggregator_cert_path"`
@@ -29,6 +31,10 @@ type Config struct {
2931 AppMetricExclusionFilter []string `json:"loggregator_app_metric_exclusion_filter"`
3032}
3133
34+ func (c Config ) APIAddr () string {
35+ return fmt .Sprintf ("%s:%d" , cmp .Or (c .APIHost , "127.0.0.1" ), c .APIPort )
36+ }
37+
3238// A ContainerMetric records resource usage of an app in a container.
3339type ContainerMetric struct {
3440 ApplicationId string //deprecated
@@ -107,7 +113,7 @@ func newV2IngressClient(config Config) (IngressClient, error) {
107113 }
108114
109115 if config .APIPort != 0 {
110- opts = append (opts , loggregator .WithAddr (fmt . Sprintf ( "127.0.0.1:%d" , config .APIPort )))
116+ opts = append (opts , loggregator .WithAddr (config .APIAddr ( )))
111117 }
112118
113119 //lint:ignore SA1019 - we can't use grpc.WithContextDial until loggregator is updated for grpc.DialContext
Original file line number Diff line number Diff line change @@ -33,6 +33,22 @@ var _ = Describe("DiegoLoggingClient", func() {
3333 metronClientKeyFile = filepath .Join (fixturesPath , "metron" , "client.key" )
3434 })
3535
36+ Context ("Config" , func () {
37+ It ("returns the configured API address" , func () {
38+ config := client.Config {
39+ APIHost : "api.example.com" ,
40+ APIPort : 8080 ,
41+ }
42+ Expect (config .APIAddr ()).To (Equal ("api.example.com:8080" ))
43+ })
44+ It ("returns the default API address when no host is specified" , func () {
45+ config := client.Config {
46+ APIPort : 8080 ,
47+ }
48+ Expect (config .APIAddr ()).To (Equal ("127.0.0.1:8080" ))
49+ })
50+ })
51+
3652 Context ("when the v2 api is used" , func () {
3753 var (
3854 testIngressServer * testhelpers.TestIngressServer
You can’t perform that action at this time.
0 commit comments