Skip to content

feat: upgrade cf client to v3 #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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 .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

env:
GO_VERSION: '1.18.1'
GO_VERSION: '1.23'
RUBY_VERSION: '3.3'

jobs:
Expand Down
39 changes: 14 additions & 25 deletions cache/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package cache
import (
"errors"
"fmt"
"net/url"
"github.com/cloudfoundry/go-cfclient/v3/resource"
"sync"
"time"

"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/v3"

cfclient "github.com/cloudfoundry-community/go-cfclient"
"github.com/cloudfoundry-community/splunk-firehose-nozzle/monitoring"
"github.com/cloudfoundry-community/splunk-firehose-nozzle/utils"
json "github.com/mailru/easyjson"
Expand Down Expand Up @@ -302,24 +301,14 @@ func (c *Boltdb) getAppFromDatabase(appGuid string) (*App, error) {
func (c *Boltdb) getAllAppsFromRemote() (map[string]*App, error) {
c.config.Logger.Info("Retrieving apps from remote")

totalPages := 0
q := url.Values{}
q.Set("inline-relations-depth", "0")
if c.config.AppLimits > 0 {
// Latest N apps
q.Set("order-direction", "desc")
q.Set("results-per-page", "100")
totalPages = c.config.AppLimits/100 + 1
}

cfApps, err := c.appClient.ListAppsByQueryWithLimits(q, totalPages)
cfApps, err := c.appClient.ListApps()
if err != nil {
return nil, err
}

apps := make(map[string]*App, len(cfApps))
for i := range cfApps {
app := c.fromPCFApp(&cfApps[i])
app := c.fromPCFApp(cfApps[i])
apps[app.Guid] = app
}

Expand Down Expand Up @@ -413,13 +402,13 @@ func (c *Boltdb) fillDatabase(apps map[string]*App) {
}
}

func (c *Boltdb) fromPCFApp(app *cfclient.App) *App {
func (c *Boltdb) fromPCFApp(app *resource.App) *App {
cachedApp := &App{
Name: app.Name,
Guid: app.Guid,
SpaceGuid: app.SpaceGuid,
IgnoredApp: c.isOptOut(app.Environment),
CfAppEnv: app.Environment,
Name: app.Name,
Guid: app.GUID,
SpaceGuid: app.Relationships.Space.Data.GUID,
IgnoredApp: c.isOptOut(app.Metadata.Labels),
CfAppLabels: app.Metadata.Labels,
}

c.fillOrgAndSpace(cachedApp)
Expand All @@ -442,7 +431,7 @@ func (c *Boltdb) fillOrgAndSpace(app *App) error {

space = Space{
Name: cfspace.Name,
OrgGUID: cfspace.OrganizationGuid,
OrgGUID: cfspace.Relationships.Organization.Data.GUID,
LastUpdated: now,
}

Expand Down Expand Up @@ -484,14 +473,14 @@ func (c *Boltdb) getAppFromRemote(appGuid string) (*App, error) {
if err != nil {
return nil, err
}
app := c.fromPCFApp(&cfApp)
app := c.fromPCFApp(cfApp)
c.fillDatabase(map[string]*App{app.Guid: app})

return app, nil
}

func (c *Boltdb) isOptOut(envVar map[string]interface{}) bool {
if val, ok := envVar["F2S_DISABLE_LOGGING"]; ok && val == "true" {
func (c *Boltdb) isOptOut(appLabels map[string]*string) bool {
if val, ok := appLabels["F2S_DISABLE_LOGGING"]; ok && *val == "true" {
return true
}
return false
Expand Down
29 changes: 13 additions & 16 deletions cache/cache.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package cache

import (
"net/url"

cfclient "github.com/cloudfoundry-community/go-cfclient"
"github.com/cloudfoundry/go-cfclient/v3/resource"
)

type App struct {
Name string
Guid string
SpaceName string
SpaceGuid string
OrgName string
OrgGuid string
CfAppEnv map[string]interface{}
IgnoredApp bool
Name string
Guid string
SpaceName string
SpaceGuid string
OrgName string
OrgGuid string
CfAppLabels map[string]*string
IgnoredApp bool
}

type Cache interface {
Expand All @@ -25,9 +23,8 @@ type Cache interface {
}

type AppClient interface {
AppByGuid(appGuid string) (cfclient.App, error)
ListApps() ([]cfclient.App, error)
ListAppsByQueryWithLimits(query url.Values, totalPages int) ([]cfclient.App, error)
GetSpaceByGuid(spaceGUID string) (cfclient.Space, error)
GetOrgByGuid(orgGUID string) (cfclient.Org, error)
AppByGuid(appGuid string) (*resource.App, error)
ListApps() ([]*resource.App, error)
GetSpaceByGuid(spaceGUID string) (*resource.Space, error)
GetOrgByGuid(orgGUID string) (*resource.Organization, error)
}
12 changes: 6 additions & 6 deletions cache/cache_easyjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ func parseCfAppEnv(in *jlexer.Lexer, out *App) {
} else {
in.Delim('{')
if !in.IsDelim('}') {
out.CfAppEnv = make(map[string]interface{})
out.CfAppLabels = make(map[string]*string)
} else {
out.CfAppEnv = nil
out.CfAppLabels = nil
}
for !in.IsDelim('}') {
key := string(in.String())
in.WantColon()
v1 := in.Interface()
(out.CfAppEnv)[key] = v1
v1 := in.String()
(out.CfAppLabels)[key] = &v1
in.WantComma()
}
in.Delim('}')
Expand Down Expand Up @@ -121,12 +121,12 @@ func easyjsonA591d1bcEncodeGithubComCloudfoundryCommunitySplunkFirehoseNozzleCac
}
first = false
out.RawString("\"CfAppEnv\":")
if in.CfAppEnv == nil {
if in.CfAppLabels == nil {
out.RawString(`null`)
} else {
out.RawByte('{')
v2First := true
for v2Name, v2Value := range in.CfAppEnv {
for v2Name, v2Value := range in.CfAppLabels {
if !v2First {
out.RawByte(',')
}
Expand Down
2 changes: 1 addition & 1 deletion cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"time"

"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/v3"

. "github.com/cloudfoundry-community/splunk-firehose-nozzle/cache"
"github.com/cloudfoundry-community/splunk-firehose-nozzle/testing"
Expand Down
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Cloud Foundry Firehose-to-Splunk Nozzle

!!!warning
Starting from version `1.4.0`, the `go-cfclient` used by the nozzle was upgraded from v2 to v3. As a result of this breaking change, the `environment_variables` for each App object have been replaced with `Cf Labels`.

## Compatibility

### VMware Tanzu Application Service versions
Expand Down
8 changes: 4 additions & 4 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (e *Event) AnnotateWithAppData(appCache cache.Cache, config *Config) {
appInfo, err := appCache.GetApp(appGuid)
if err != nil {
if err == cache.ErrMissingAndIgnored {
logrus.Info(err.Error(), cfAppId)
logrus.Info(err.Error(), " (", cfAppId, ")")
} else {
logrus.Error("Failed to fetch application metadata from remote: ", err)
}
Expand All @@ -224,7 +224,7 @@ func (e *Event) parseAndAnnotateWithAppInfo(appInfo *cache.App, config *Config)
cfOrgId := appInfo.OrgGuid
cfOrgName := appInfo.OrgName
cfIgnoredApp := appInfo.IgnoredApp
appEnv := appInfo.CfAppEnv
appLabels := appInfo.CfAppLabels

if cfAppName != "" && config.AddAppName {
e.Fields["cf_app_name"] = cfAppName
Expand All @@ -246,8 +246,8 @@ func (e *Event) parseAndAnnotateWithAppInfo(appInfo *cache.App, config *Config)
e.Fields["cf_org_name"] = cfOrgName
}

if appEnv["SPLUNK_INDEX"] != nil {
e.Fields["info_splunk_index"] = appEnv["SPLUNK_INDEX"]
if appLabels["SPLUNK_INDEX"] != nil {
e.Fields["info_splunk_index"] = appLabels["SPLUNK_INDEX"]
}

if cfIgnoredApp {
Expand Down
2 changes: 1 addition & 1 deletion eventsink/splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"sync/atomic"

"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/v3"
"github.com/cloudfoundry-community/splunk-firehose-nozzle/cache"
fevents "github.com/cloudfoundry-community/splunk-firehose-nozzle/events"
"github.com/cloudfoundry-community/splunk-firehose-nozzle/eventwriter"
Expand Down
2 changes: 1 addition & 1 deletion eventsink/splunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/v3"
"github.com/cloudfoundry-community/splunk-firehose-nozzle/cache"
"github.com/cloudfoundry-community/splunk-firehose-nozzle/eventrouter"
"github.com/cloudfoundry-community/splunk-firehose-nozzle/utils"
Expand Down
2 changes: 1 addition & 1 deletion eventwriter/splunk_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"code.cloudfoundry.org/cfhttp"
"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/v3"
"github.com/cloudfoundry-community/splunk-firehose-nozzle/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion eventwriter/splunk_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"net/http"

"code.cloudfoundry.org/cfhttp"
"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/v3"
)

type splunkMetric struct {
Expand Down
2 changes: 1 addition & 1 deletion eventwriter/splunk_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// "time"

"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/v3"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

Expand Down
2 changes: 1 addition & 1 deletion eventwriter/splunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http/httptest"
"strings"

"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/v3"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down
65 changes: 37 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,57 +1,66 @@
module github.com/cloudfoundry-community/splunk-firehose-nozzle

go 1.20
go 1.23.0

toolchain go1.23.5

require (
code.cloudfoundry.org/cfhttp v2.0.0+incompatible
code.cloudfoundry.org/lager v2.0.0+incompatible
github.com/cloudfoundry-community/go-cfclient v0.0.0-20220930021109-9c4e6c59ccf1
code.cloudfoundry.org/lager/v3 v3.29.0
github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.10
github.com/cloudfoundry/noaa v2.1.1-0.20190110210640-5ce49363dfa6+incompatible
github.com/cloudfoundry/sonde-go v0.0.0-20160804000546-81c3f6be579c
github.com/gogo/protobuf v1.3.2
github.com/google/uuid v1.3.1
github.com/gorilla/websocket v1.5.0
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.3
github.com/mailru/easyjson v0.7.7
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.33.1
github.com/onsi/gomega v1.36.2
github.com/sirupsen/logrus v1.9.3
go.etcd.io/bbolt v1.3.6
go.etcd.io/bbolt v1.3.11
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)

require (
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/google/pprof v0.0.0-20250302191652-9094ed2288e7 // indirect
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 // indirect
github.com/onsi/ginkgo/v2 v2.23.0 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.9.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/tools v0.31.0 // indirect
)

require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect
github.com/apoydence/eachers v0.0.0-20181020210610-23942921fe77 // indirect
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a // indirect
github.com/elazarl/goproxy/ext v0.0.0-20230808193330-2592e75ae04a // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/elazarl/goproxy v0.0.0-20240909085733-6741dbfc16a1 // indirect
github.com/elazarl/goproxy/ext v0.0.0-20240909085733-6741dbfc16a1 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/shirou/gopsutil/v3 v3.23.9
golang.org/x/net v0.34.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/shirou/gopsutil/v3 v3.24.5
golang.org/x/net v0.37.0 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/text v0.23.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading