Skip to content

Commit fcbda2d

Browse files
kashyap-splunkheidmotronluckyj5harshit-splunkhvaghani221
authored
1.2.3 release changes (#298)
* update docs (#276) * Update Go version and migrate to Go modules (#287) * Adding go.mod and go.sum to migrate to Go modules from Glide * Removed old Vendor folder after migrating to Go modules * Adding new Vendor folder after migrating to Go mudules * Removed Glide files, references in readme and updated CI/CD * Migrated from bolt to bbolt for cache module to resolve race issue * Added tags from the envelope to the events * Updated tile.yml with new config * Updated README * Updated migration script to prevent unnecessary migration (#288) * Updated cache.GetApp logic to retrieve app info from boltdb database as well * Bugfix/disconnect due to slow consumer event drop (#289) * dropping events when the queue is full * Corrected the newly added test case with data race condition * minor change in logging * added event drop warning threshold in config * minor update in the logging * Updated comments and log info * Trimmed white space for ApiEndPoint and SplunkHost * Updated docs with required field & optional value * Added default value in README * Updated events doc * Removed SPLUNK_VERSION config as not needed anymore * Removed SplunkVersion from eventsink.splunk_test * Updated README with app level index routing (#292) * Updated README with app level index routing * Removed unnecessary changes * added required config to enable index routing * updated index routing doc * added warning in index routing docs * upgraded module version * upgraded gogo/protobuf version * executed go mod tidy * upgraded indirect dependency * updated version in a build example in readme * Corrected index routing docs * Added more details (#299) * Updated docs around - Add Tags: Performance impact of adding tags in events - How to detect slow downstream related issues and event drops * added 'drop_warn_threshold' config in tile (#300) Co-authored-by: Matthew Heidemann <[email protected]> Co-authored-by: Shubham Jain <[email protected]> Co-authored-by: harshit-splunk <[email protected]> Co-authored-by: harshit-splunk <[email protected]>
1 parent ecf9398 commit fcbda2d

File tree

2,728 files changed

+252289
-1103131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,728 files changed

+252289
-1103131
lines changed

.circleci/ci_nozzle_manifest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ applications:
2121
JOB_INDEX: -1
2222
JOB_HOST: localhost
2323
ADD_APP_INFO: AppName,OrgName,OrgGuid,SpaceName,SpaceGuid
24+
ADD_TAGS: true
2425
IGNORE_MISSING_APP: true
2526
MISSING_APP_CACHE_INVALIDATE_TTL: 3600s
2627
APP_CACHE_INVALIDATE_TTL: 86440s

.circleci/config.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ version: 2 # use CircleCI 2.0
22
jobs:
33
build:
44
docker:
5-
- image: circleci/golang:1.12
5+
- image: circleci/golang:1.17
66
working_directory: /go/src/github.com/cloudfoundry-community/splunk-firehose-nozzle
77
steps: # steps that comprise the `build` job
88
- checkout # check out source code to working directory
99
- run:
1010
name: Install Dependencies
1111
command: |
12-
go get -u -v -t github.com/Masterminds/glide
13-
glide install --strip-vendor
12+
go mod vendor
1413
- run:
1514
name: Builder
1615
command: make build
@@ -26,7 +25,7 @@ jobs:
2625

2726
deploy-nozzle:
2827
docker:
29-
- image: circleci/golang:1.12
28+
- image: circleci/golang:1.17
3029
working_directory: /go/src/github.com/cloudfoundry-community/splunk-firehose-nozzle
3130
steps: # steps that comprise the `deploy` job
3231
- attach_workspace:
@@ -35,8 +34,7 @@ jobs:
3534
- run:
3635
name: Install dependencies
3736
command: |
38-
go get -u -v -t github.com/Masterminds/glide
39-
glide install --strip-vendor
37+
go mod vendor
4038
cp -R /tmp/splunk-firehose-nozzle .
4139
- run:
4240
name: Deploy nozzle
@@ -47,7 +45,7 @@ jobs:
4745
4846
tile-builder:
4947
docker:
50-
- image: circleci/golang:1.12
48+
- image: circleci/golang:1.17
5149
working_directory: /go/src/github.com/cloudfoundry-community/splunk-firehose-nozzle
5250
steps:
5351
- attach_workspace:
@@ -66,7 +64,7 @@ jobs:
6664
6765
execute_tests:
6866
docker:
69-
- image: circleci/golang:1.12
67+
- image: circleci/golang:1.17
7068
working_directory: /go/src/github.com/cloudfoundry-community/splunk-firehose-nozzle
7169
steps:
7270
- attach_workspace:
@@ -75,8 +73,7 @@ jobs:
7573
- run:
7674
name: Install dependencies
7775
command: |
78-
go get -u -v -t github.com/Masterminds/glide
79-
glide install --strip-vendor
76+
go mod vendor
8077
cp -R /tmp/splunk-firehose-nozzle .
8178
- run:
8279
name: Deploy data-gen

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ endif
1212
default: installdeps build
1313

1414
installdeps:
15-
glide install --strip-vendor
15+
go mod vendor
1616

1717
updatedeps:
18-
glide update
18+
go get -u
19+
go mod tidy
20+
go mod vendor
1921

2022
initdeps:
21-
glide create
23+
go mod init
24+
go mod tidy
25+
go mod vendor
2226

2327
# -gcflags '-N -l' for debug
2428
# -ldflags -w for prod

README.md

Lines changed: 72 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -57,50 +57,47 @@ or later. Earlier versions should use `cloud_controller.admin` instead.
5757
- - - -
5858
#### Environment Parameters
5959
You can declare parameters by making a copy of the scripts/nozzle.sh.template.
60-
* `DEBUG`: Enable debug mode (forward to standard out instead of Splunk).
60+
* `DEBUG`: Enable debug mode (forward to standard out instead of Splunk). (Default: false).
6161

6262
__Cloud Foundry configuration parameters:__
63-
* `API_ENDPOINT`: Cloud Foundry API endpoint address.
64-
* `CLIENT_ID`: UAA Client ID (Must have authorities and grant_types described above).
65-
* `CLIENT_SECRET`: Secret for Client ID.
63+
* `API_ENDPOINT`: Cloud Foundry API endpoint address. It is required parameter.
64+
* `CLIENT_ID`: UAA Client ID (Must have authorities and grant_types described above). It is required parameter.
65+
* `CLIENT_SECRET`: Secret for Client ID. It is required parameter.
6666

6767
__Splunk configuration parameters:__
68-
* `SPLUNK_TOKEN`: [Splunk HTTP event collector token](http://docs.splunk.com/Documentation/Splunk/latest/Data/UsetheHTTPEventCollector/).
69-
* `SPLUNK_HOST`: Splunk HTTP event collector host. example: https://example.cloud.splunk.com:8088
70-
* `SPLUNK_INDEX`: The Splunk index events will be sent to. Warning: Setting an invalid index will cause events to be lost. This index must match one of the selected indexes for the Splunk HTTP event collector token used for the SPLUNK_TOKEN parameter.
68+
* `SPLUNK_TOKEN`: [Splunk HTTP event collector token](http://docs.splunk.com/Documentation/Splunk/latest/Data/UsetheHTTPEventCollector/). It is required parameter.
69+
* `SPLUNK_HOST`: Splunk HTTP event collector host. example: https://example.cloud.splunk.com:8088. It is required parameter.
70+
* `SPLUNK_INDEX`: The Splunk index events will be sent to. Warning: Setting an invalid index will cause events to be lost. This index must match one of the selected indexes for the Splunk HTTP event collector token used for the SPLUNK_TOKEN parameter. It is required parameter.
7171

7272
__Advanced Configuration Features:__
73-
* `JOB_NAME`: Tags nozzle log events with job name.
74-
* `JOB_INDEX`: Tags nozzle log events with job index.
75-
* `JOB_HOST`: Tags nozzle log events with job host.
73+
* `JOB_NAME`: Tags nozzle log events with job name. It is optional. (Default: 'splunk-nozzle')
74+
* `JOB_INDEX`: Tags nozzle log events with job index. (Default: -1)
75+
* `JOB_HOST`: Tags nozzle log events with job host. (Default: "")
7676
* `SKIP_SSL_VALIDATION_CF`: Skips SSL certificate validation for connection to Cloud Foundry. Secure communications will not check SSL certificates against a trusted certificate authority.
77+
This is recommended for dev environments only. (Default: false)
78+
* `SKIP_SSL_VALIDATION_SPLUNK`: Skips SSL certificate validation for connection to Splunk. Secure communications will not check SSL certificates against a trusted certificate authority. (Default: false)
7779
This is recommended for dev environments only.
78-
* `SKIP_SSL_VALIDATION_SPLUNK`: Skips SSL certificate validation for connection to Splunk. Secure communications will not check SSL certificates against a trusted certificate authority.
79-
This is recommended for dev environments only.
80-
* `FIREHOSE_SUBSCRIPTION_ID`: Tags nozzle events with a Firehose subscription id. See https://docs.pivotal.io/pivotalcf/1-11/loggregator/log-ops-guide.html.
81-
* `FIREHOSE_KEEP_ALIVE`: Keep alive duration for the Firehose consumer.
82-
* `ADD_APP_INFO`: Enrich raw data with app info. A comma separated list of app metadata (AppName,OrgName,OrgGuid,SpaceName,SpaceGuid).
83-
* `IGNORE_MISSING_APP`: If the application is missing, then stop repeatedly querying application info from Cloud Foundry.
84-
* `MISSING_APP_CACHE_INVALIDATE_TTL`: How frequently the missing app info cache invalidates (in s/m/h. For example, 3600s or 60m or 1h).
85-
* `APP_CACHE_INVALIDATE_TTL`: How frequently the app info local cache invalidates (in s/m/h. For example, 3600s or 60m or 1h).
86-
* `ORG_SPACE_CACHE_INVALIDATE_TTL`: How frequently the org and space cache invalidates (in s/m/h. For example, 3600s or 60m or 1h).
87-
* `APP_LIMITS`: Restrict to APP_LIMITS the most updated apps per request when populating the app metadata cache.
88-
* `BOLTDB_PATH`: Bolt database path.
89-
* `EVENTS`: A comma separated list of events to include. Possible values: ValueMetric,CounterEvent,Error,LogMessage,HttpStartStop,ContainerMetric
90-
* `EXTRA_FIELDS`: Extra fields to annotate your events with (format is key:value,key:value).
91-
* `FLUSH_INTERVAL`: Time interval (in s/m/h. For example, 3600s or 60m or 1h) for flushing queue to Splunk regardless of CONSUMER_QUEUE_SIZE. Protects against stale events in low throughput systems.
92-
* `CONSUMER_QUEUE_SIZE`: Sets the internal consumer queue buffer size. Events will be pushed to Splunk after queue is full.
93-
* `HEC_BATCH_SIZE`: Set the batch size for the events to push to HEC (Splunk HTTP Event Collector).
94-
* `HEC_RETRIES`: Retry count for sending events to Splunk. After expiring, events will begin dropping causing data loss.
95-
* `HEC_WORKERS`: Set the amount of Splunk HEC workers to increase concurrency while ingesting in Splunk.
96-
* `ENABLE_EVENT_TRACING`: Enables event trace logging. Splunk events will now contain a UUID, Splunk Nozzle Event Counts, and a Subscription-ID for Splunk correlation searches.
97-
* `SPLUNK_VERSION`: The Splunk version that determines how HEC ingests metadata fields. Only required for Splunk version 6.3 or below.
80+
* `FIREHOSE_SUBSCRIPTION_ID`: Tags nozzle events with a Firehose subscription id. See https://docs.pivotal.io/pivotalcf/1-11/loggregator/log-ops-guide.html. (Default: splunk-firehose)
81+
* `FIREHOSE_KEEP_ALIVE`: Keep alive duration for the Firehose consumer. (Default: 25s)
82+
* `ADD_APP_INFO`: Enrich raw data with app info. A comma separated list of app metadata (AppName,OrgName,OrgGuid,SpaceName,SpaceGuid). (Default: "")
83+
* `ADD_TAGS`: Add additional tags from envelope to splunk event. (Default: false)
84+
(Please note: Adding tags / Enabling this feature may slightly impact the performance due to the increased event size)
85+
* `IGNORE_MISSING_APP`: If the application is missing, then stop repeatedly querying application info from Cloud Foundry. (Default: true)
86+
* `MISSING_APP_CACHE_INVALIDATE_TTL`: How frequently the missing app info cache invalidates (in s/m/h. For example, 3600s or 60m or 1h). (Default: 0s)
87+
* `APP_CACHE_INVALIDATE_TTL`: How frequently the app info local cache invalidates (in s/m/h. For example, 3600s or 60m or 1h). (Default: 0s)
88+
* `ORG_SPACE_CACHE_INVALIDATE_TTL`: How frequently the org and space cache invalidates (in s/m/h. For example, 3600s or 60m or 1h). (Default: 72h)
89+
* `APP_LIMITS`: Restrict to APP_LIMITS the most updated apps per request when populating the app metadata cache. keep it 0 to update all the apps. (Default: 0)
90+
* `BOLTDB_PATH`: Bolt database path. (Default: cache.db)
91+
* `EVENTS`: A comma separated list of events to include. It is a required field. Possible values: ValueMetric,CounterEvent,Error,LogMessage,HttpStartStop,ContainerMetric. If no eventtype is selected, nozzle will automatically select LogMessage to keep the nozzle running. (Default: "ValueMetric,CounterEvent,ContainerMetric")
92+
* `EXTRA_FIELDS`: Extra fields to annotate your events with (format is key:value,key:value). (Default: "")
93+
* `FLUSH_INTERVAL`: Time interval (in s/m/h. For example, 3600s or 60m or 1h) for flushing queue to Splunk regardless of CONSUMER_QUEUE_SIZE. Protects against stale events in low throughput systems. (Default: 5s)
94+
* `CONSUMER_QUEUE_SIZE`: Sets the internal consumer queue buffer size. Events will be pushed to Splunk after queue is full. (Default: 10000)
95+
* `HEC_BATCH_SIZE`: Set the batch size for the events to push to HEC (Splunk HTTP Event Collector). (Default: 100)
96+
* `HEC_RETRIES`: Retry count for sending events to Splunk. After expiring, events will begin dropping causing data loss. (Default: 5)
97+
* `HEC_WORKERS`: Set the amount of Splunk HEC workers to increase concurrency while ingesting in Splunk. (Default: 8)
98+
* `ENABLE_EVENT_TRACING`: Enables event trace logging. Splunk events will now contain a UUID, Splunk Nozzle Event Counts, and a Subscription-ID for Splunk correlation searches. (Default: false)
9899
* `STATUS_MONITOR_INTERVAL`: Time interval (in s/m/h. For example, 3600s or 60m or 1h) for monitoring memory queue pressure. Use to help with back-pressure insights. (Increases CPU load. Use for insights purposes only) Default is 0s (Disabled).
99-
### Please note
100-
> SPLUNK_VERSION configuration parameter is only required for Splunk version 6.3 and below.
101-
For Splunk version 6.3 or below, please deploy nozzle via CLI. Update nozzle_manifest.yml with splunk_version (For example: SPLUNK_VERSION: 6.3) as an env variable and [deploy nozzle as an app via CLI](#push-as-an-app-to-cloud-foundry).
102-
103-
**[Tile](https://network.pivotal.io/products/splunk-nozzle/)** only supports deployment for Splunk version 6.4 or above
100+
* `DROP_WARN_THRESHOLD`: Threshold for the count of dropped events in case the downstream is slow. Based on the threshold, the errors will be logged.
104101

105102
- - - -
106103

@@ -157,26 +154,42 @@ specifying correct "--boltdb-path" flag or "BOLTDB_PATH" environment variable.
157154
Set F2S_DISABLE_LOGGING = true as a environment variable in applications's manifest to disable logging.
158155

159156

160-
### Index routing
157+
## Index routing
161158
Index routing is a feature that can be used to send different Cloud Foundry logs to different indexes for better ACL and data retention control in Splunk.
162159

163-
#### Per application index routing via application manifest
164-
In your app manifest provide an environment variable called `SPLUNK_INDEX` and assign it the index you would like to send the app data to
160+
### Per application index routing via application manifest
161+
To enable per app index routing,
162+
* Please set environment variable `SPLUNK_INDEX` in your application's manifest ([example below](#example-manifest-file))
163+
* Make sure Splunk nozzle is configured with `ADD_APP_INFO` (Select at least one of AppName,OrgName,OrgGuid,SpaceName,SpaceGuid) to enable app info caching
164+
* Make sure `SPLUNK_INDEX` specified in app's manifest exist in Splunk and can receive data for the configured Splunk HEC token.
165+
166+
> **WARNING**: If `SPLUNK_INDEX` is invalid, events from other apps may also get lost as splunk will drop entire event batch if any of the event from batch is invalid (i.e. invalid index)
167+
168+
There are two ways to set the variable:
165169

170+
In your app manifest provide an environment variable called `SPLUNK_INDEX` and assign it the index you would like to send the app data to.
171+
172+
#### Example Manifest file
166173
```
167174
applications:
168-
- name: console
175+
- name: <App-Name>
169176
memory: 256M
170177
disk_quota: 256M
171-
host: console
172-
timeout: 180
173-
buildpack: https://github.com/SUSE/stratos-buildpack
174-
health-check-type: port
178+
...
175179
env:
176-
SPLUNK_INDEX: testing_index
180+
SPLUNK_INDEX: <SPLUNK_INDEX>
181+
...
182+
```
183+
184+
You can also update the env on the fly using cf-cli command:
185+
```
186+
cf set-env <APP_NAME> SPLUNK_INDEX <ENV_VAR_VALUE>
177187
```
188+
#### Please note
189+
> If you are updating env on the fly, make sure that `APP_CACHE_INVALIDATE_TTL` is greater tha 0s. Otherwise cached app-info will not be updated and events will not be sent to required index.
178190
179-
#### Index routing via Splunk configuration
191+
192+
### Index routing via Splunk configuration
180193
Logs can be routed using fields such as app ID/name, space ID/name or org ID/name.
181194
Users can configure the Splunk configuration files props.conf and transforms.conf on Splunk indexers or Splunk Heavy Forwarders if deployed.
182195
@@ -337,7 +350,6 @@ A correct setup logs a start message with configuration parameters of the Nozzle
337350
skip-ssl: true
338351
splunk-host: http://localhost:8088
339352
splunk-index: atomic
340-
splunk-version: 8.1
341353
subscription-id: splunk-firehose
342354
trace-logging: true
343355
status-monitor-interval: 0s
@@ -366,7 +378,17 @@ As the Splunk Firehose Nozzle sends data to Splunk via HTTPS using the HTTP Even
366378
sourcetype="cf:splunknozzle" "dropping events"
367379
</pre>
368380
369-
### 4. Check for data loss inside the Splunk Firehose Nozzle:
381+
### 4. Check for dropped events due to slow downstream(Network/Splunk):
382+
383+
If the nozzle emits the ‘dropped events’ warning saying that downstream is slow, then the network or Splunk environment might needs to be scaled. (eg. Splunk HEC receiver node, Splunk Indexer, LB etc)
384+
385+
Run the following search to determine if Splunk has indexed any events indicating such issues.
386+
387+
<pre class="terminal">
388+
sourcetype="cf:splunknozzle" "dropped Total of"
389+
</pre>
390+
391+
### 5. Check for data loss inside the Splunk Firehose Nozzle:
370392
371393
If "Event Tracing" is enabled, extra metadata will be attached to events. This allows searches to calculate the percentage of data loss inside the Splunk Firehose Nozzle, if applicable.
372394
@@ -398,10 +420,9 @@ Make sure you have the following installed on your workstation:
398420
399421
| Software | Version
400422
| --- | --- |
401-
| go | go1.12.x
402-
| glide | 0.12.x
423+
| go | go1.17.x
403424
404-
Then install all dependent packages via [Glide](https://glide.sh/):
425+
Then make sure that all dependent packages are there:
405426
406427
```
407428
$ cd <REPO_ROOT_DIRECTORY>
@@ -421,7 +442,7 @@ $ chmod +x tools/nozzle.sh
421442
Build project:
422443
423444
```
424-
$ make VERSION=1.2.2
445+
$ make VERSION=1.2.3
425446
```
426447
427448
Run tests with [Ginkgo](http://onsi.github.io/ginkgo/)

cache/boltdb.go

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import (
99

1010
"code.cloudfoundry.org/lager"
1111

12-
"github.com/boltdb/bolt"
1312
cfclient "github.com/cloudfoundry-community/go-cfclient"
1413
json "github.com/mailru/easyjson"
14+
bolt "go.etcd.io/bbolt"
1515
)
1616

1717
const (
1818
APP_BUCKET = "AppBucket"
1919
)
2020

2121
var (
22-
MissingAndIgnoredErr = errors.New("App was missed and ignored")
22+
ErrMissingAndIgnored = errors.New("App was missing from the in-memory cache and ignored")
2323
)
2424

2525
type BoltdbConfig struct {
@@ -127,13 +127,12 @@ func (c *Boltdb) Close() error {
127127
return c.appdb.Close()
128128
}
129129

130-
// GetApp tries first get app info from cache. If caches doesn't have this
131-
// app info (cache miss), it issues API to retrieve the app info from remote
132-
// if the app is not already missing and clients don't ignore the missing app
133-
// info, and then add the app info to the cache
134-
// On the other hand, if the app is already missing and clients want to
135-
// save remote API and ignore missing app, then a nil app info and an error
136-
// will be returned.
130+
// GetApp tries to retrieve the app info from in-memory cache. If it finds the app then it returns.
131+
// If the app is added to missing app cache then it will return ErrMissingAndIgnored.
132+
// If the app is not found in in-memory cache and missing app cache, it'll make an API request
133+
// to retrieve the app info from remote. If found, the app will be added to the cache and returns.
134+
// If not found on remote, it'll try to retrieve from boltdb databse. If found, returns.
135+
// If not found and IgnoreMissingApps congig is enabled, the app will be added to missingApps cache.
137136
func (c *Boltdb) GetApp(appGuid string) (*App, error) {
138137
app, err := c.getAppFromCache(appGuid)
139138
if err != nil {
@@ -146,9 +145,26 @@ func (c *Boltdb) GetApp(appGuid string) (*App, error) {
146145
return app, nil
147146
}
148147

149-
// First time seeing app
148+
// App was not found in in-memory cache. Try to retrieve from remote and boltdb databse.
150149
app, err = c.getAppFromRemote(appGuid)
150+
151+
if app == nil {
152+
// Not able to find the app from remote. App may be deleted.
153+
// Check if the app is available in boltdb cache
154+
dbApp, _ := c.getAppFromDatabase(appGuid)
155+
if dbApp != nil {
156+
c.config.Logger.Debug(fmt.Sprint("Using old app info for cf_app_id ", appGuid))
157+
c.lock.Lock()
158+
c.cache[appGuid] = dbApp
159+
c.lock.Unlock()
160+
c.fillOrgAndSpace(dbApp)
161+
return dbApp, nil
162+
}
163+
}
164+
151165
if err != nil {
166+
// App is not available from in-memory cache, boltdb databse or remote
167+
// Adding to missing app cache
152168
if c.config.IgnoreMissingApps {
153169
// Record this missing app
154170
c.lock.Lock()
@@ -207,7 +223,7 @@ func (c *Boltdb) getAppFromCache(appGuid string) (*App, error) {
207223
if c.config.IgnoreMissingApps && alreadyMissed {
208224
// already missed
209225
c.lock.RUnlock()
210-
return nil, MissingAndIgnoredErr
226+
return nil, ErrMissingAndIgnored
211227
}
212228
c.lock.RUnlock()
213229

@@ -239,6 +255,25 @@ func (c *Boltdb) getAllAppsFromBoltDB() (map[string]*App, error) {
239255
return apps, nil
240256
}
241257

258+
// getAppFromDatabase will try to get the app from the database and return it.
259+
func (c *Boltdb) getAppFromDatabase(appGuid string) (*App, error) {
260+
var appData []byte
261+
c.appdb.View(func(tx *bolt.Tx) error {
262+
b := tx.Bucket([]byte(APP_BUCKET))
263+
264+
appData = b.Get([]byte(appGuid))
265+
return nil
266+
})
267+
if appData == nil {
268+
return nil, nil
269+
}
270+
var app App
271+
if err := json.Unmarshal(appData, &app); err != nil {
272+
return nil, err
273+
}
274+
return &app, nil
275+
}
276+
242277
func (c *Boltdb) getAllAppsFromRemote() (map[string]*App, error) {
243278
c.config.Logger.Info("Retrieving apps from remote")
244279

@@ -341,12 +376,12 @@ func (c *Boltdb) fillDatabase(apps map[string]*App) {
341376
c.appdb.Update(func(tx *bolt.Tx) error {
342377
serialize, err := json.Marshal(app)
343378
if err != nil {
344-
return fmt.Errorf("Error Marshaling data: %s", err)
379+
return fmt.Errorf("error Marshaling data: %s", err)
345380
}
346381

347382
b := tx.Bucket([]byte(APP_BUCKET))
348383
if err := b.Put([]byte(app.Guid), serialize); err != nil {
349-
return fmt.Errorf("Error inserting data: %s", err)
384+
return fmt.Errorf("error inserting data: %s", err)
350385
}
351386
return nil
352387
})

0 commit comments

Comments
 (0)