Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit ff1977c

Browse files
piyalibanerjeecwlbraaSannidhi Jalukar
committed
make app event logging sendable to fluentd
* rename VCAP::Loggregator -> VCAP::AppLogEmitter [#172415438] Co-authored-by: Connor Braa <cbraa@pivotal.io> Co-authored-by: Sannidhi Jalukar <sjalukar@pivotal.io> Co-authored-by: Piyali Banerjee <pbanerjee@pivotal.io>
1 parent c1fee1d commit ff1977c

26 files changed

Lines changed: 276 additions & 142 deletions

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ gem 'clockwork', require: false
77
gem 'cloudfront-signer'
88
gem 'em-http-request', '~> 1.1'
99
gem 'eventmachine', '~> 1.0.9'
10+
gem 'fluent-logger'
1011
gem 'googleapis-common-protos'
1112
gem 'hashdiff'
1213
gem 'httpclient'

Gemfile.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ DEPENDENCIES
499499
debase (>= 0.2.2.beta14)
500500
em-http-request (~> 1.1)
501501
eventmachine (~> 1.0.9)
502+
fluent-logger
502503
fog-aliyun
503504
fog-aws
504505
fog-azure-rm!

app/controllers/runtime/app_bits_download_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def download(guid)
1818
process = find_guid_and_validate_access(:read, guid)
1919
blob_dispatcher.send_or_redirect(guid: process.latest_package.guid)
2020
rescue CloudController::Errors::BlobNotFound
21-
VCAP::Loggregator.emit_error(guid, "Could not find package for #{guid}")
21+
VCAP::AppLogEmitter.emit_error(guid, "Could not find package for #{guid}")
2222
logger.error "could not find package for #{guid}"
2323
raise CloudController::Errors::ApiError.new_from_details('AppPackageNotFound', guid)
2424
end

app/repositories/app_event_repository.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AppEventRepository
1515
SYSTEM_ACTOR_HASH = { guid: 'system', type: 'system', name: 'system', user_name: 'system' }.freeze
1616

1717
def create_app_exit_event(app, droplet_exited_payload)
18-
VCAP::Loggregator.emit(app.guid, "App instance exited with guid #{app.guid} payload: #{droplet_exited_payload}")
18+
VCAP::AppLogEmitter.emit(app.guid, "App instance exited with guid #{app.guid} payload: #{droplet_exited_payload}")
1919

2020
actor = { name: app.name, guid: app.guid, type: 'app' }
2121
metadata = droplet_exited_payload.slice('instance', 'index', 'cell_id', 'exit_status', 'exit_description', 'reason')
@@ -26,7 +26,7 @@ def create_app_exit_event(app, droplet_exited_payload)
2626

2727
def record_app_update(app, space, user_audit_info, request_attrs, manifest_triggered: false)
2828
audit_hash = app_audit_hash(request_attrs)
29-
VCAP::Loggregator.emit(app.guid, "Updated app with guid #{app.guid} (#{audit_hash})")
29+
VCAP::AppLogEmitter.emit(app.guid, "Updated app with guid #{app.guid} (#{audit_hash})")
3030

3131
actor = { name: user_audit_info.user_email, guid: user_audit_info.user_guid, user_name: user_audit_info.user_name, type: 'user' }
3232
metadata = add_manifest_triggered(manifest_triggered, {
@@ -37,52 +37,52 @@ def record_app_update(app, space, user_audit_info, request_attrs, manifest_trigg
3737

3838
def record_app_map_droplet(app, space, user_audit_info, request_attrs)
3939
audit_hash = app_audit_hash(request_attrs)
40-
VCAP::Loggregator.emit(app.guid, "Updated app with guid #{app.guid} (#{audit_hash})")
40+
VCAP::AppLogEmitter.emit(app.guid, "Updated app with guid #{app.guid} (#{audit_hash})")
4141

4242
actor = { name: user_audit_info.user_email, guid: user_audit_info.user_guid, user_name: user_audit_info.user_name, type: 'user' }
4343
metadata = { request: audit_hash }
4444
create_app_audit_event('audit.app.droplet.mapped', app, space, actor, metadata)
4545
end
4646

4747
def record_app_apply_manifest(app, space, user_audit_info, manifest_request_yaml)
48-
VCAP::Loggregator.emit(app.guid, "Applied manifest to app with guid #{app.guid} (#{manifest_request_yaml})")
48+
VCAP::AppLogEmitter.emit(app.guid, "Applied manifest to app with guid #{app.guid} (#{manifest_request_yaml})")
4949

5050
actor = { name: user_audit_info.user_email, guid: user_audit_info.user_guid, user_name: user_audit_info.user_name, type: 'user' }
5151
metadata = { request: { manifest: manifest_request_yaml } }
5252
create_app_audit_event('audit.app.apply_manifest', app, space, actor, metadata)
5353
end
5454

5555
def record_app_create(app, space, user_audit_info, request_attrs)
56-
VCAP::Loggregator.emit(app.guid, "Created app with guid #{app.guid}")
56+
VCAP::AppLogEmitter.emit(app.guid, "Created app with guid #{app.guid}")
5757

5858
actor = { name: user_audit_info.user_email, guid: user_audit_info.user_guid, user_name: user_audit_info.user_name, type: 'user' }
5959
metadata = { request: app_audit_hash(request_attrs) }
6060
create_app_audit_event('audit.app.create', app, space, actor, metadata)
6161
end
6262

6363
def record_app_start(app, user_audit_info)
64-
VCAP::Loggregator.emit(app.guid, "Starting app with guid #{app.guid}")
64+
VCAP::AppLogEmitter.emit(app.guid, "Starting app with guid #{app.guid}")
6565

6666
actor = { name: user_audit_info.user_email, guid: user_audit_info.user_guid, user_name: user_audit_info.user_name, type: 'user' }
6767
create_app_audit_event('audit.app.start', app, app.space, actor, nil)
6868
end
6969

7070
def record_app_restart(app, user_audit_info)
71-
VCAP::Loggregator.emit(app.guid, "Restarted app with guid #{app.guid}")
71+
VCAP::AppLogEmitter.emit(app.guid, "Restarted app with guid #{app.guid}")
7272

7373
actor = { name: user_audit_info.user_email, guid: user_audit_info.user_guid, type: 'user', user_name: user_audit_info.user_name }
7474
create_app_audit_event('audit.app.restart', app, app.space, actor, nil)
7575
end
7676

7777
def record_app_stop(app, user_audit_info)
78-
VCAP::Loggregator.emit(app.guid, "Stopping app with guid #{app.guid}")
78+
VCAP::AppLogEmitter.emit(app.guid, "Stopping app with guid #{app.guid}")
7979

8080
actor = { name: user_audit_info.user_email, guid: user_audit_info.user_guid, user_name: user_audit_info.user_name, type: 'user' }
8181
create_app_audit_event('audit.app.stop', app, app.space, actor, nil)
8282
end
8383

8484
def record_app_delete_request(app, space, user_audit_info, recursive=nil)
85-
VCAP::Loggregator.emit(app.guid, "Deleted app with guid #{app.guid}")
85+
VCAP::AppLogEmitter.emit(app.guid, "Deleted app with guid #{app.guid}")
8686

8787
actor = { name: user_audit_info.user_email, guid: user_audit_info.user_guid, user_name: user_audit_info.user_name, type: 'user' }
8888
metadata = nil

app/repositories/build_event_repository.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module VCAP::CloudController
22
module Repositories
33
class BuildEventRepository
44
def self.record_build_create(build, user_audit_info, v3_app_name, space_guid, org_guid)
5-
VCAP::Loggregator.emit(build.app_guid, "Creating build for app with guid #{build.app_guid}")
5+
VCAP::AppLogEmitter.emit(build.app_guid, "Creating build for app with guid #{build.app_guid}")
66

77
metadata = {
88
build_guid: build.guid,

app/repositories/deployment_event_repository.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module VCAP::CloudController
22
module Repositories
33
class DeploymentEventRepository
44
def self.record_create(deployment, droplet, user_audit_info, v3_app_name, space_guid, org_guid, params, type)
5-
VCAP::Loggregator.emit(deployment.app_guid, "Creating deployment for app with guid #{deployment.app_guid}")
5+
VCAP::AppLogEmitter.emit(deployment.app_guid, "Creating deployment for app with guid #{deployment.app_guid}")
66

77
metadata = {
88
deployment_guid: deployment.guid,
@@ -29,7 +29,7 @@ def self.record_create(deployment, droplet, user_audit_info, v3_app_name, space_
2929
end
3030

3131
def self.record_cancel(deployment, droplet, user_audit_info, v3_app_name, space_guid, org_guid)
32-
VCAP::Loggregator.emit(deployment.app_guid, "Cancelling deployment for app with guid #{deployment.app_guid}")
32+
VCAP::AppLogEmitter.emit(deployment.app_guid, "Cancelling deployment for app with guid #{deployment.app_guid}")
3333

3434
metadata = {
3535
deployment_guid: deployment.guid,

app/repositories/droplet_event_repository.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module VCAP::CloudController
22
module Repositories
33
class DropletEventRepository
44
def self.record_create_by_staging(droplet, user_audit_info, v3_app_name, space_guid, org_guid)
5-
VCAP::Loggregator.emit(droplet.app_guid, "Creating droplet for app with guid #{droplet.app_guid}")
5+
VCAP::AppLogEmitter.emit(droplet.app_guid, "Creating droplet for app with guid #{droplet.app_guid}")
66

77
metadata = {
88
droplet_guid: droplet.guid,
@@ -26,7 +26,7 @@ def self.record_create_by_staging(droplet, user_audit_info, v3_app_name, space_g
2626
end
2727

2828
def self.record_create(droplet, user_audit_info, v3_app_name, space_guid, org_guid)
29-
VCAP::Loggregator.emit(droplet.app_guid, "Creating droplet for app with guid #{droplet.app_guid}")
29+
VCAP::AppLogEmitter.emit(droplet.app_guid, "Creating droplet for app with guid #{droplet.app_guid}")
3030

3131
metadata = {
3232
droplet_guid: droplet.guid,
@@ -49,7 +49,7 @@ def self.record_create(droplet, user_audit_info, v3_app_name, space_guid, org_gu
4949
end
5050

5151
def self.record_create_by_copying(new_droplet_guid, source_droplet_guid, user_audit_info, v3_app_guid, v3_app_name, space_guid, org_guid)
52-
VCAP::Loggregator.emit(v3_app_guid, "Creating droplet for app with guid #{v3_app_guid}")
52+
VCAP::AppLogEmitter.emit(v3_app_guid, "Creating droplet for app with guid #{v3_app_guid}")
5353

5454
metadata = {
5555
droplet_guid: new_droplet_guid,
@@ -75,7 +75,7 @@ def self.record_create_by_copying(new_droplet_guid, source_droplet_guid, user_au
7575
end
7676

7777
def self.record_delete(droplet, user_audit_info, v3_app_name, space_guid, org_guid)
78-
VCAP::Loggregator.emit(droplet.app_guid, "Deleting droplet for app with guid #{droplet.app_guid}")
78+
VCAP::AppLogEmitter.emit(droplet.app_guid, "Deleting droplet for app with guid #{droplet.app_guid}")
7979

8080
metadata = { droplet_guid: droplet.guid }
8181

@@ -97,7 +97,7 @@ def self.record_delete(droplet, user_audit_info, v3_app_name, space_guid, org_gu
9797

9898
# Emit this event once we have droplet download capability
9999
def self.record_download(droplet, user_audit_info, v3_app_name, space_guid, org_guid)
100-
VCAP::Loggregator.emit(droplet.app_guid, "Downloading droplet for app with guid #{droplet.app_guid}")
100+
VCAP::AppLogEmitter.emit(droplet.app_guid, "Downloading droplet for app with guid #{droplet.app_guid}")
101101

102102
metadata = { droplet_guid: droplet.guid }
103103

@@ -118,7 +118,7 @@ def self.record_download(droplet, user_audit_info, v3_app_name, space_guid, org_
118118
end
119119

120120
def self.record_upload(droplet, user_audit_info, v3_app_name, space_guid, org_guid)
121-
VCAP::Loggregator.emit(droplet.app_guid, "Uploading droplet for app with guid #{droplet.app_guid}")
121+
VCAP::AppLogEmitter.emit(droplet.app_guid, "Uploading droplet for app with guid #{droplet.app_guid}")
122122

123123
metadata = { droplet_guid: droplet.guid }
124124

app/repositories/package_event_repository.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Repositories
33
class PackageEventRepository
44
def self.record_app_package_create(package, user_audit_info, request_attrs)
55
app_guid = request_attrs.delete('app_guid')
6-
VCAP::Loggregator.emit(app_guid, "Adding app package for app with guid #{app_guid}")
6+
VCAP::AppLogEmitter.emit(app_guid, "Adding app package for app with guid #{app_guid}")
77

88
metadata = {
99
package_guid: package.guid,
@@ -16,7 +16,7 @@ def self.record_app_package_create(package, user_audit_info, request_attrs)
1616

1717
def self.record_app_package_copy(package, user_audit_info, source_package_guid)
1818
app = package.app
19-
VCAP::Loggregator.emit(app.guid, "Adding app package for app with guid #{app.guid} copied from package with guid #{source_package_guid}")
19+
VCAP::AppLogEmitter.emit(app.guid, "Adding app package for app with guid #{app.guid} copied from package with guid #{source_package_guid}")
2020
metadata = {
2121
package_guid: package.guid,
2222
request: {
@@ -29,31 +29,31 @@ def self.record_app_package_copy(package, user_audit_info, source_package_guid)
2929
end
3030

3131
def self.record_app_package_upload(package, user_audit_info)
32-
VCAP::Loggregator.emit(package.app.guid, "Uploading app package for app with guid #{package.app.guid}")
32+
VCAP::AppLogEmitter.emit(package.app.guid, "Uploading app package for app with guid #{package.app.guid}")
3333
metadata = { package_guid: package.guid }
3434
type = 'audit.app.package.upload'
3535

3636
create_event(package, type, user_audit_info, metadata)
3737
end
3838

3939
def self.record_app_upload_bits(package, user_audit_info)
40-
VCAP::Loggregator.emit(package.app.guid, "Uploading bits for app with guid #{package.app.guid}")
40+
VCAP::AppLogEmitter.emit(package.app.guid, "Uploading bits for app with guid #{package.app.guid}")
4141
metadata = { package_guid: package.guid }
4242
type = 'audit.app.upload-bits'
4343

4444
create_event(package, type, user_audit_info, metadata)
4545
end
4646

4747
def self.record_app_package_delete(package, user_audit_info)
48-
VCAP::Loggregator.emit(package.app.guid, "Deleting app package for app with guid #{package.app.guid}")
48+
VCAP::AppLogEmitter.emit(package.app.guid, "Deleting app package for app with guid #{package.app.guid}")
4949
metadata = { package_guid: package.guid }
5050
type = 'audit.app.package.delete'
5151

5252
create_event(package, type, user_audit_info, metadata)
5353
end
5454

5555
def self.record_app_package_download(package, user_audit_info)
56-
VCAP::Loggregator.emit(package.app.guid, "Downloading app package for app with guid #{package.app.guid}")
56+
VCAP::AppLogEmitter.emit(package.app.guid, "Downloading app package for app with guid #{package.app.guid}")
5757
metadata = { package_guid: package.guid }
5858
type = 'audit.app.package.download'
5959

app/repositories/process_event_repository.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ProcessEventRepository
66
extend AppManifestEventMixins
77

88
def self.record_create(process, user_audit_info, manifest_triggered: false)
9-
VCAP::Loggregator.emit(process.app.guid, "Added process: \"#{process.type}\"")
9+
VCAP::AppLogEmitter.emit(process.app.guid, "Added process: \"#{process.type}\"")
1010

1111
metadata = add_manifest_triggered(manifest_triggered, {
1212
process_guid: process.guid,
@@ -24,7 +24,7 @@ def self.record_create(process, user_audit_info, manifest_triggered: false)
2424
end
2525

2626
def self.record_delete(process, user_audit_info)
27-
VCAP::Loggregator.emit(process.app.guid, "Deleting process: \"#{process.type}\"")
27+
VCAP::AppLogEmitter.emit(process.app.guid, "Deleting process: \"#{process.type}\"")
2828

2929
create_event(
3030
process: process,
@@ -40,7 +40,7 @@ def self.record_delete(process, user_audit_info)
4040
end
4141

4242
def self.record_update(process, user_audit_info, request, manifest_triggered: false)
43-
VCAP::Loggregator.emit(process.app.guid, "Updating process: \"#{process.type}\"")
43+
VCAP::AppLogEmitter.emit(process.app.guid, "Updating process: \"#{process.type}\"")
4444

4545
request = request.dup.symbolize_keys
4646
request[:command] = Presenters::Censorship::PRIVATE_DATA_HIDDEN if request.key?(:command)
@@ -61,7 +61,7 @@ def self.record_update(process, user_audit_info, request, manifest_triggered: fa
6161
end
6262

6363
def self.record_scale(process, user_audit_info, request, manifest_triggered: false)
64-
VCAP::Loggregator.emit(process.app.guid, "Scaling process: \"#{process.type}\"")
64+
VCAP::AppLogEmitter.emit(process.app.guid, "Scaling process: \"#{process.type}\"")
6565

6666
metadata = add_manifest_triggered(manifest_triggered, {
6767
process_guid: process.guid,
@@ -80,7 +80,7 @@ def self.record_scale(process, user_audit_info, request, manifest_triggered: fal
8080
end
8181

8282
def self.record_terminate(process, user_audit_info, index)
83-
VCAP::Loggregator.emit(process.app.guid, "Terminating process: \"#{process.type}\", index: \"#{index}\"")
83+
VCAP::AppLogEmitter.emit(process.app.guid, "Terminating process: \"#{process.type}\", index: \"#{index}\"")
8484

8585
create_event(
8686
process: process,
@@ -97,7 +97,7 @@ def self.record_terminate(process, user_audit_info, index)
9797
end
9898

9999
def self.record_crash(process, crash_payload)
100-
VCAP::Loggregator.emit(process.app.guid, "Process has crashed with type: \"#{process.type}\"")
100+
VCAP::AppLogEmitter.emit(process.app.guid, "Process has crashed with type: \"#{process.type}\"")
101101

102102
create_event(
103103
process: process,

app/repositories/revision_event_repository.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module VCAP::CloudController
22
module Repositories
33
class RevisionEventRepository
44
def self.record_create(revision, app, user_audit_info)
5-
VCAP::Loggregator.emit(revision.app_guid, "Creating revision for app with guid #{app.guid}")
5+
VCAP::AppLogEmitter.emit(revision.app_guid, "Creating revision for app with guid #{app.guid}")
66

77
Event.create(
88
type: 'audit.app.revision.create',

0 commit comments

Comments
 (0)