Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Update nozzle dependencies #113

Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/stackdriver-nozzle/.envrc.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# http://direnv.net

export FIREHOSE_ENDPOINT=https://api.bosh-lite.com
export FIREHOSE_EVENTS_TO_STACKDRIVER_LOGGING=HttpStart,HttpStop,HttpStartStop,LogMessage,ValueMetric,CounterEvent,Error,ContainerMetric
export FIREHOSE_EVENTS_TO_STACKDRIVER_LOGGING=HttpStartStop,LogMessage,ValueMetric,CounterEvent,Error,ContainerMetric
export FIREHOSE_EVENTS_TO_STACKDRIVER_MONITORING=ValueMetric,CounterEvent,ContainerMetric
export FIREHOSE_USERNAME=admin
export FIREHOSE_PASSWORD=admin
Expand Down
2 changes: 1 addition & 1 deletion src/stackdriver-nozzle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ go get github.com/cloudfoundry-community/stackdriver-tools/src/stackdriver-nozzl
- `FIREHOSE_ENDPOINT` - the CF API endpoint; e.g., `https://api.bosh-lite.com'
- `FIREHOSE_EVENTS_TO_STACKDRIVER_LOGGING` - comma-separated list of events to pass to Stackdriver Logging;
valid events are `LogMessage`, `ValueMetric`, `CounterEvent`, `Error`,
`ContainerMetric`, `HttpStart`, `HttpStop`, and `HttpStartStop`
`ContainerMetric`, and `HttpStartStop`
- `FIREHOSE_EVENTS_TO_STACKDRIVER_MONITORING` - comma-separated list of events to pass to Stackdriver Monitoring;
valid events are `ValueMetric`, `CounterEvent`, and `ContainerMetric`
- `FIREHOSE_USERNAME` - CF username; defaults to `admin`
Expand Down
18 changes: 10 additions & 8 deletions src/stackdriver-nozzle/cloudfoundry/app_info_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ type appInfoRepository struct {
func (air *appInfoRepository) GetAppInfo(guid string) AppInfo {
appInfo, ok := air.cache[guid]
if !ok {
app := air.cfClient.AppByGuid(guid)
appInfo = AppInfo{
AppName: app.Name,
SpaceGUID: app.SpaceData.Entity.Guid,
SpaceName: app.SpaceData.Entity.Name,
OrgGUID: app.SpaceData.Entity.OrgData.Entity.Guid,
OrgName: app.SpaceData.Entity.OrgData.Entity.Name,
app, err := air.cfClient.AppByGuid(guid)
if err != nil {
appInfo = AppInfo{
AppName: app.Name,
SpaceGUID: app.SpaceData.Entity.Guid,
SpaceName: app.SpaceData.Entity.Name,
OrgGUID: app.SpaceData.Entity.OrgData.Entity.Guid,
OrgName: app.SpaceData.Entity.OrgData.Entity.Name,
}
air.cache[guid] = appInfo
}
air.cache[guid] = appInfo
}
return appInfo
}
Expand Down
4 changes: 2 additions & 2 deletions src/stackdriver-nozzle/cloudfoundry/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func (ct *cfClientTokenRefresh) RefreshAuthToken() (token string, err error) {
//
// TODO: Track https://github.com/cloudfoundry-community/go-cfclient/issues/34 for
// updates on proper refresh token handling.
token = ct.cfClient.GetToken()
if token == "" {
token, err = ct.cfClient.GetToken()
if token == "" && err == nil {
err = fmt.Errorf("Fatal: error getting refresh token")
}
return
Expand Down
5 changes: 4 additions & 1 deletion src/stackdriver-nozzle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ func newApp() *app {
Username: c.Username,
Password: c.Password,
SkipSslValidation: c.SkipSSL}
cfClient := cfclient.NewClient(cfConfig)
cfClient, err := cfclient.NewClient(cfConfig)
if err != nil {
logger.Error("cfClient", err)
}

var appInfoRepository cloudfoundry.AppInfoRepository
if c.ResolveAppMetadata {
Expand Down
2 changes: 0 additions & 2 deletions src/stackdriver-nozzle/nozzle/filter_sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ var _ = Describe("SinkFilter", func() {

BeforeEach(func() {
allEventTypes = []events.Envelope_EventType{
events.Envelope_HttpStart,
events.Envelope_HttpStop,
events.Envelope_HttpStartStop,
events.Envelope_LogMessage,
events.Envelope_ValueMetric,
Expand Down
71 changes: 42 additions & 29 deletions src/stackdriver-nozzle/nozzle/metric_sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/cloudfoundry/sonde-go/events"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
)

type mockUnitParser struct {
Expand Down Expand Up @@ -77,13 +78,15 @@ var _ = Describe("MetricSink", func() {
Expect(err).To(BeNil())

metrics := metricBuffer.PostedMetrics
Expect(metrics).To(ConsistOf(stackdriver.Metric{
Name: "valueMetricName",
Value: 123.456,
Labels: labels,
EventTime: eventTime,
Unit: "{foo}",
Expect(metrics).To(HaveLen(1))
Expect(metrics[0]).To(MatchAllFields(Fields{
"Name": Equal("valueMetricName"),
"Value": Equal(123.456),
"Labels": Equal(labels),
"EventTime": Ignore(),
"Unit": Equal("{foo}"),
}))
Expect(metrics[0].EventTime.UnixNano()).To(Equal(timeStamp))

Expect(unitParser.lastInput).To(Equal("barUnit"))
})
Expand Down Expand Up @@ -123,12 +126,18 @@ var _ = Describe("MetricSink", func() {
metrics := metricBuffer.PostedMetrics
Expect(metrics).To(HaveLen(6))

Expect(metrics).To(ContainElement(stackdriver.Metric{Name: "diskBytesQuota", Value: float64(1073741824), Labels: labels, EventTime: eventTime, Unit: ""}))
Expect(metrics).To(ContainElement(stackdriver.Metric{Name: "instanceIndex", Value: float64(0), Labels: labels, EventTime: eventTime, Unit: ""}))
Expect(metrics).To(ContainElement(stackdriver.Metric{Name: "cpuPercentage", Value: 0.061651273460637, Labels: labels, EventTime: eventTime, Unit: ""}))
Expect(metrics).To(ContainElement(stackdriver.Metric{Name: "diskBytes", Value: float64(164634624), Labels: labels, EventTime: eventTime, Unit: ""}))
Expect(metrics).To(ContainElement(stackdriver.Metric{Name: "memoryBytes", Value: float64(16601088), Labels: labels, EventTime: eventTime, Unit: ""}))
Expect(metrics).To(ContainElement(stackdriver.Metric{Name: "memoryBytesQuota", Value: float64(33554432), Labels: labels, EventTime: eventTime, Unit: ""}))
eventName := func(element interface{}) string {
return element.(stackdriver.Metric).Name
}

Expect(metrics).To(MatchAllElements(eventName, Elements{
"diskBytesQuota": MatchAllFields(Fields{"Name": Ignore(), "Value": Equal(float64(1073741824)), "Labels": Equal(labels), "EventTime": Ignore(), "Unit": Equal("")}),
"instanceIndex": MatchAllFields(Fields{"Name": Ignore(), "Value": Equal(float64(0)), "Labels": Equal(labels), "EventTime": Ignore(), "Unit": Equal("")}),
"cpuPercentage": MatchAllFields(Fields{"Name": Ignore(), "Value": Equal(float64(0.061651273460637)), "Labels": Equal(labels), "EventTime": Ignore(), "Unit": Equal("")}),
"diskBytes": MatchAllFields(Fields{"Name": Ignore(), "Value": Equal(float64(164634624)), "Labels": Equal(labels), "EventTime": Ignore(), "Unit": Equal("")}),
"memoryBytes": MatchAllFields(Fields{"Name": Ignore(), "Value": Equal(float64(16601088)), "Labels": Equal(labels), "EventTime": Ignore(), "Unit": Equal("")}),
"memoryBytesQuota": MatchAllFields(Fields{"Name": Ignore(), "Value": Equal(float64(33554432)), "Labels": Equal(labels), "EventTime": Ignore(), "Unit": Equal("")}),
}))
})

It("creates total and delta metrics for CounterEvent", func() {
Expand All @@ -155,26 +164,30 @@ var _ = Describe("MetricSink", func() {
Expect(err).To(BeNil())

metrics := metricBuffer.PostedMetrics
Expect(metrics).To(ConsistOf(
stackdriver.Metric{
Name: "counterName.delta",
Value: float64(654321),
Labels: labels,
EventTime: eventTime,
Unit: "",
},
stackdriver.Metric{
Name: "counterName.total",
Value: float64(123456),
Labels: labels,
EventTime: eventTime,
Unit: "",
},
))

eventName := func(element interface{}) string {
return element.(stackdriver.Metric).Name
}
Expect(metrics).To(MatchAllElements(eventName, Elements{
"counterName.delta": MatchAllFields(Fields{
"Name": Ignore(),
"Value": Equal(float64(654321)),
"Labels": Equal(labels),
"EventTime": Ignore(),
"Unit": Equal(""),
}),
"counterName.total": MatchAllFields(Fields{
"Name": Ignore(),
"Value": Equal(float64(123456)),
"Labels": Equal(labels),
"EventTime": Ignore(),
"Unit": Equal(""),
}),
}))
})

It("returns error when envelope contains unhandled event type", func() {
eventType := events.Envelope_HttpStart
eventType := events.Envelope_HttpStartStop
envelope := &events.Envelope{
EventType: &eventType,
}
Expand Down
3 changes: 2 additions & 1 deletion src/stackdriver-nozzle/stackdriver/metric_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"cloud.google.com/go/monitoring/apiv3"
"github.com/cloudfoundry-community/stackdriver-tools/src/stackdriver-nozzle/version"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
metricpb "google.golang.org/genproto/googleapis/api/metric"
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
Expand Down Expand Up @@ -65,7 +66,7 @@ func (m *metricClient) ListMetricDescriptors(request *monitoringpb.ListMetricDes
descriptors := []*metricpb.MetricDescriptor{}
for {
metricDescriptor, err := it.Next()
if err == monitoring.Done {
if err == iterator.Done {
break
}
if err != nil {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading