gerrit/Documentation/cmd-stream-events.txt
David Ostrovsky 9503a2e582 Use subscribe pattern to avoid eager stream-events materialization
Now that memoized supplier pattern is used to reduce the resource
consumption in firing event machinery and the data is only retrieved
when the events are really consumed, it's worth to provide an option to
optimize stream events consumption to avoid materialization of events
that are not needed. Stream events are used by IRC publish libraries
and CI integration solutions, e.g. Zuul, where only a subset of event
types is used. Add --subscribe option and allow to specify event types
to consume while ignore all other events.

Test Plan:

Non retrieval of data with default gerrit install + reviewers plugin +
Jenkins Gerrit Trigger plugin.

1. install gerrit with all core plugins
2. install reviewers plugin
3. set up stream event for Jenkins Gerrit Trigger plugin, but use new
   option to subscribe to only "draft-published", "patchset-created"
   and "ref-replicated" (exposed by replication plugin) events
4. create a group_100 that contains 100 users
5. add a reviewer to a change and select the group_100

Without this change hundreds of SQL select statements are executed in
vain. That's because 100 ChangeEvent instances are created and multiple
SQL select statements are executed per instance. With this change exact
0 select SQL statements are executed. Memoized suppliers are created
but because this stream event type "reviewer-added" wasn't subscribed
to all these events are ignored and thus not materialized.

Change-Id: I525499c26812bb09ba0cddf9f0e8eb0fb822c15b
2016-01-07 08:12:21 +01:00

276 lines
6.6 KiB
Plaintext

= gerrit stream-events
== NAME
gerrit stream-events - Monitor events occurring in real time
== SYNOPSIS
--
'ssh' -p <port> <host> 'gerrit stream-events'
--
== DESCRIPTION
Provides a portal into the major events occurring on the server,
outputting activity data in real-time to the client. Events are
filtered by the caller's access permissions, ensuring the caller
only receives events for changes they can view on the web, or in
the project repository.
Event output is in JSON, one event per line.
== ACCESS
Caller must be a member of the privileged 'Administrators' group,
or have been granted
link:access-control.html#capability_streamEvents[the 'Stream Events' global capability].
== SCRIPTING
This command is intended to be used in scripts.
== OPTIONS
--subscribe|-s::
Type of the event to subscribe to. Multiple --subscribe options
may be specified to subscribe to multiple events. When this option
is provided, only subscribed events are emitted and all other
events are ignored. When this option is omitted, all events are
emitted.
== EXAMPLES
====
$ ssh -p 29418 review.example.com gerrit stream-events
{"type":"comment-added",change:{"project":"tools/gerrit", ...}, ...}
{"type":"comment-added",change:{"project":"tools/gerrit", ...}, ...}
====
Only subscribe to specific event types:
====
$ ssh -p 29418 review.example.com gerrit stream-events \
-s draft-published -s patchset-created -s ref-replicated
====
== SCHEMA
The JSON messages consist of nested objects referencing the *change*,
*patchSet*, *account* involved, and other attributes as appropriate.
Note that any field may be missing in the JSON messages, so consumers of
this JSON stream should deal with that appropriately.
[[events]]
== EVENTS
=== Change Abandoned
Sent when a change has been abandoned.
type:: "change-abandoned"
change:: link:json.html#change[change attribute]
patchSet:: link:json.html#patchSet[patchSet attribute]
abandoner:: link:json.html#account[account attribute]
reason:: Reason for abandoning the change.
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
created.
=== Change Merged
Sent when a change has been merged into the git repository.
type:: "change-merged"
change:: link:json.html#change[change attribute]
patchSet:: link:json.html#patchSet[patchSet attribute]
submitter:: link:json.html#account[account attribute]
newRev:: The resulting revision of the merge.
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
created.
=== Change Restored
Sent when an abandoned change has been restored.
type:: "change-restored"
change:: link:json.html#change[change attribute]
patchSet:: link:json.html#patchSet[patchSet attribute]
restorer:: link:json.html#account[account attribute]
reason:: Reason for restoring the change.
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
created.
=== Comment Added
Sent when a review comment has been posted on a change.
type:: "comment-added"
change:: link:json.html#change[change attribute]
patchSet:: link:json.html#patchSet[patchSet attribute]
author:: link:json.html#account[account attribute]
approvals:: All link:json.html#approval[approval attributes] granted.
comment:: Review comment cover message.
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
created.
=== Draft Published
Sent when a draft change has been published.
type:: "draft-published"
change:: link:json.html#change[change attribute]
patchSet:: link:json.html#patchSet[patchSet attribute]
uploader:: link:json.html#account[account attribute]
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
created.
=== Dropped Output
Sent to notify a client that events have been dropped.
type:: "dropped-output"
=== Hashtags Changed
Sent when the hashtags have been added to or removed from a change.
type:: "hashtags-changed"
change:: link:json.html#change[change attribute]
editor:: link:json.html#account[account attribute]
added:: List of hashtags added to the change
removed:: List of hashtags removed from the change
hashtags:: List of hashtags on the change after tags were added or removed
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
created.
=== Project Created
Sent when a new project has been created.
type:: "project-created"
projectName:: The created project name
projectHead:: The created project head name
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
created.
=== Merge Failed
Sent when a change has failed to be merged into the git repository.
type:: "merge-failed"
change:: link:json.html#change[change attribute]
patchSet:: link:json.html#patchSet[patchSet attribute]
submitter:: link:json.html#account[account attribute]
reason:: Reason that the merge failed.
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
created.
=== Patchset Created
Sent when a new change has been uploaded, or a new patch set has been uploaded
to an existing change.
Note that this event is also sent for changes or patch sets uploaded as draft,
but is only visible to the change owner, any existing reviewers, and users who
belong to a group that is granted the
link:access-control.html#category_view_drafts[View Drafts] capability.
type:: "patchset-created"
change:: link:json.html#change[change attribute]
patchSet:: link:json.html#patchSet[patchSet attribute]
uploader:: link:json.html#account[account attribute]
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
created.
=== Ref Updated
Sent when a reference is updated in a git repository.
type:: "ref-updated"
submitter:: link:json.html#account[account attribute]
refUpdate:: link:json.html#refUpdate[refUpdate attribute]
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
created.
=== Reviewer Added
Sent when a reviewer is added to a change.
type:: "reviewer-added"
change:: link:json.html#change[change attribute]
patchSet:: link:json.html#patchSet[patchSet attribute]
reviewer:: link:json.html#account[account attribute]
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
created.
=== Topic Changed
Sent when the topic of a change has been changed.
type:: "topic-changed"
change:: link:json.html#change[change attribute]
changer:: link:json.html#account[account attribute]
oldTopic:: Topic name before it was changed.
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
created.
== SEE ALSO
* link:json.html[JSON Data Formats]
* link:access-control.html[Access Controls]
GERRIT
------
Part of link:index.html[Gerrit Code Review]
SEARCHBOX
---------