NXLog Docs

Google Cloud Pub/Sub (im_googlepubsub)

Google Cloud Pub/Sub is a service that allows event producers to deliver events to subscribers asynchronously. It is commonly used for data streaming, real-time event distribution, or as a message queue for parallel workflows.

This module uses the Google Pub/Sub REST API to create a subscription and collect logs from a Google Pub/Sub topic.

To examine the supported platforms, see the list of installer packages in the Available Modules chapter.

Configuring a Google Cloud service account

im_googlepubsub requires a Google Cloud service account and a corresponding private key file in JSON format to connect to the Google Cloud Pub/Sub API. Follow these instructions to create a new service account and download its private key file for an existing project.

  1. Log in to your Google Cloud account and switch to the project you want to configure.

  2. From the navigation menu, click on IAM & Admin > Service Accounts.

    IAM & Admin menu
  3. Click CREATE SERVICE ACCOUNT.

  4. Enter a service account name and description and click CREATE AND CONTINUE.

    Create service account
  5. Select the Owner role from the Role drop-down and click DONE.

    Service account role
  6. Click on the newly created account on the Service accounts page to open its configuration page.

  7. Click the KEYS tab, expand the ADD KEY drop-down and select Create new key.

    Create new service key
  8. Select JSON for the key type and click CREATE to download the private key. Save the private key file to a location accessible by NXLog. This file is required for the NXLog configuration.

    New service key type

Configuration

The im_googlepubsub module accepts the following directives in addition to the common module directives. The CredentialsFile and Subscription directives are required.

Required directives

The following directives are required for the module to start.

CredentialsFile

This mandatory directive specifies the path to the private key file of the service account required for authenticating with the Google Pub/Sub. See Configuring a Google Cloud service account for more information.

Subscription

This mandatory directive specifies the name of the subscription from which messages should be pulled. The format is projects/{project}/subscriptions/{sub}.

Optional directives

Acknowledge

This optional boolean directive specifies whether an acknowledge confirmation should be sent for received messages. The default is TRUE.

CADir

This directive specifies a path to a directory containing certificate authority (CA) certificates. These certificates will be used to verify the certificate presented by the remote server. The certificate files must be named using the OpenSSL hashed format, i.e. the hash of the certificate followed by .0, .1 etc. To find the hash of a certificate using OpenSSL:

$ openssl x509 -hash -noout -in ca.crt

For example, if the certificate hash is e2f14e4a, then the certificate filename should be e2f14e4a.0. If there is another certificate with the same hash then it should be named e2f14e4a.1 and so on.

A remote server’s self-signed certificate (which is not signed by a CA) can also be trusted by including a copy of the certificate in this directory.

The default operating system root certificate store will be used if this directive is not specified. Unix-like operating systems commonly store root certificates in /etc/ssl/certs. Windows operating systems use the Windows Certificate Store, while macOS uses the Keychain Access Application as the default certificate store. See NXLog TLS/SSL configuration in the User Guide for more information on using this directive.

Connections

Number of allowed parallel HTTP connections. The default is 1.

PollInterval

This directive specifies how frequently the module will check for new events in seconds. If this directive is not specified, it defaults to 20 seconds.

Reconnect

This optional directive sets the reconnect interval in seconds. If it is set, the module attempts to reconnect in every defined second. If it is not set, the reconnect interval will start at 1 second and doubles on every attempt. If the duration of the successful connection is greater than the current reconnect interval, then the reconnect interval will be reset to 1 sec.

ReadFromLast

This optional boolean directive instructs the module to only read logs that arrive after NXLog is started. This directive is not normally required if the Acknowledge directive is set to TRUE (default) as the Google Cloud Pub/Sub server will manage the starting point when a connection is (re-)established. This directive comes into effect if a saved position is not found, for example on first start, or when the SavePos directive is FALSE. When the SavePos directive is TRUE and a previously saved position is found, the module will always resume reading from the saved position. If ReadFromLast is FALSE, the module will read all the available logs. This can result in a lot of messages and is usually not the expected behavior. For this to has effect the subscription needs to have "Retain acknowledged messages" option activated. If this directive is not specified, it defaults to TRUE.

The following matrix shows the outcome of this directive in conjunction with the SavePos directive:

ReadFromLast SavePos SavedPosition Outcome

TRUE

TRUE

No

Reads events that are logged after NXLog is started.

TRUE

TRUE

Yes

Reads events from saved position.

TRUE

FALSE

No

Reads events that are logged after NXLog is started.

TRUE

FALSE

Yes

Reads events that are logged after NXLog is started.

FALSE

TRUE

No

Reads all events.

FALSE

TRUE

Yes

Reads events from saved position.

FALSE

FALSE

No

Reads all events.

FALSE

FALSE

Yes

Reads all events.

SavePos

If this boolean directive is set to TRUE, the timestamp of the last read event will be saved when NXLog exits. This directive is not normally required if the Acknowledge directive is set to 'TRUE' (default) as the Google Cloud Pub/Sub server will manage the starting point when a connection is (re-)established. The timestamp will be read from the cache file upon startup. For this to has effect the subscription needs to have "Retain acknowledged messages" option activated. The default is TRUE, the last timestamp will be saved if this directive is not specified. This directive affects the outcome of the ReadFromLast directive. The SavePos directive can be overridden by the global NoCache directive.

URL

Optional directive for specifying a region-specific URL. The default is https://pubsub.googleapis.com.

Fields

The following fields are used by im_googlepubsub.

$raw_event (type: string)

A list of event fields in key-value pairs.

$Attributes.* (type: string)

Attributes for this message. It contains user-defined keys.

$Data (type: string)

The message data field.

$MessageId (type: string)

ID of this message, assigned by the server when the message is published.

$OrderingKey (type: string)

If non-empty, identifies related messages for which publish order should be respected. If a Subscription has enableMessageOrdering set to true, messages published with the same non-empty orderingKey value will be delivered to subscribers in the order in which they are received by the Pub/Sub system.

$PublishTime (type: datetime)

The time at which the message was published, populated by the server when it receives the topics.publish call.

Examples

Example 1. Collecting logs from Google Pub/Sub

This configuration uses the im_googlepubsub input module to create the subscription test and collect logs from the Google Cloud project myproject.

<Input google_pubsub>
    Module             im_googlepubsub
    CredentialsFile    /path/to/credentials.json (1)
    Subscription       projects/myproject-343509/subscriptions/test
</Input>
1 Credentials file for authenticating with the Google Pub/Sub. See Configuring a Google Cloud service account for more information.