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
8 changes: 7 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package diego_logging_client

import (
"cmp"
"fmt"
"time"

Expand All @@ -11,6 +12,7 @@ import (
// Config is the shared configuration between v1 and v2 clients.
type Config struct {
UseV2API bool `json:"loggregator_use_v2_api"`
APIHost string `json:"loggregator_api_host"`
APIPort int `json:"loggregator_api_port"`
CACertPath string `json:"loggregator_ca_path"`
CertPath string `json:"loggregator_cert_path"`
Expand All @@ -29,6 +31,10 @@ type Config struct {
AppMetricExclusionFilter []string `json:"loggregator_app_metric_exclusion_filter"`
}

func (c Config) APIAddr() string {
return fmt.Sprintf("%s:%d", cmp.Or(c.APIHost, "127.0.0.1"), c.APIPort)
}

// A ContainerMetric records resource usage of an app in a container.
type ContainerMetric struct {
ApplicationId string //deprecated
Expand Down Expand Up @@ -107,7 +113,7 @@ func newV2IngressClient(config Config) (IngressClient, error) {
}

if config.APIPort != 0 {
opts = append(opts, loggregator.WithAddr(fmt.Sprintf("127.0.0.1:%d", config.APIPort)))
opts = append(opts, loggregator.WithAddr(config.APIAddr()))
}

//lint:ignore SA1019 - we can't use grpc.WithContextDial until loggregator is updated for grpc.DialContext
Expand Down
16 changes: 16 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ var _ = Describe("DiegoLoggingClient", func() {
metronClientKeyFile = filepath.Join(fixturesPath, "metron", "client.key")
})

Context("Config", func() {
It("returns the configured API address", func() {
config := client.Config{
APIHost: "api.example.com",
APIPort: 8080,
}
Expect(config.APIAddr()).To(Equal("api.example.com:8080"))
})
It("returns the default API address when no host is specified", func() {
config := client.Config{
APIPort: 8080,
}
Expect(config.APIAddr()).To(Equal("127.0.0.1:8080"))
})
})

Context("when the v2 api is used", func() {
var (
testIngressServer *testhelpers.TestIngressServer
Expand Down