Skip to content

DOCSP-41982: cluster monitoring #144

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

Merged

Conversation

rustagir
Copy link
Collaborator

@rustagir rustagir commented Sep 17, 2024

Pull Request Info

PR Reviewing Guidelines

JIRA - https://jira.mongodb.org/browse/DOCSP-41982
Staging - https://deploy-preview-144--docs-php-library.netlify.app/monitoring/cluster-monitoring/

Self-Review Checklist

  • Is this free of any warnings or errors in the RST?
  • Did you run a spell-check?
  • Did you run a grammar-check?
  • Are all the links working?
  • Are the facets and meta keywords accurate?

Copy link

netlify bot commented Sep 17, 2024

Deploy Preview for docs-php-library ready!

Name Link
🔨 Latest commit 4a39d20
🔍 Latest deploy log https://app.netlify.com/sites/docs-php-library/deploys/66f1c3f20ddedb000866a811
😎 Deploy Preview https://deploy-preview-144--docs-php-library.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@mongoKart mongoKart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good! A few very small changes

- Description

* - ``ServerChangedEvent``
- Created when an instance state changes, such as from secondary to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: Could remove "Created when" from the start of every event (probably along with a new column header name)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of a good way to adjust the column header, as renaming it "Situation that Triggers Event" seems worse than keeping the "Created when"s in

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the docs for ServerChangedEvent we say the event class "encapsulates information about a changed server description".

Here, the table is presenting the event as the thing that happened instead of just an object containing some information about a thing that happened.

The "Condition" column in Events API from the driver spec might be helpful. Note that the spec includes "Description" in the name of these events, where PHP just calls it ServerChangedEvent. I think that was due to us copying the shorter name from our libmongoc dependency.

I might suggest:

When the server description changes, such as the server's type changing from secondary to primary.

@rustagir rustagir force-pushed the DOCSP-41982-cluster-monitoring branch from a36de3e to fce8972 Compare September 18, 2024 13:33
@rustagir rustagir requested a review from mongoKart September 18, 2024 15:05
Copy link
Collaborator

@mongoKart mongoKart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rustagir rustagir requested review from a team and jmikola and removed request for a team September 18, 2024 17:33
{
$this->stream = $stream;
}
public function serverOpening(MongoDB\Driver\Monitoring\ServerOpeningEvent $event): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function serverOpening(MongoDB\Driver\Monitoring\ServerOpeningEvent $event): void
public function serverOpening(MongoDB\Driver\Monitoring\ServerOpeningEvent $event): void

Also, between any methods with bodies.

public function serverHeartbeatSucceeded(MongoDB\Driver\Monitoring\ServerHeartbeatSucceededEvent $event): void {}
public function topologyChanged(MongoDB\Driver\Monitoring\TopologyChangedEvent $event): void {}
public function topologyClosed(MongoDB\Driver\Monitoring\TopologyClosedEvent $event): void {}
public function topologyOpening(MongoDB\Driver\Monitoring\TopologyOpeningEvent $event): void {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe contravariance would allow us to remove the type hints from these methods and make the code more concise. See: https://3v4l.org/H34oT#v8.3.11

That said, it'd make the example code less useful for copying if users want to implement these methods themselves. I'm fine to leave these as-is.

/cc @alcaeus

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omitting the types would make the example more concise, but I'd like to avoid suggesting to do this in documentation, as I consider it bad practice. We could leverage use statements to shorten the types, but that may be difficult if only small snippets of this code are included in the documentation.

We face a similar issue with the other documentation examples used in the server docs, and we decided to just deal with the long types in favour of having copy-pastable code.


This guide shows you how to use the {+php-library+} to monitor topology
events in a MongoDB instance, replica set, or sharded cluster. The
driver creates topology events, also known as Server Discovery and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, topology events are those related to the entire cluster, while server events are those pertaining to a single server within the topology. SDAM monitoring includes both types of events.

I would personally just refer to them as SDAM events, as you seem to do in a subsequent section. If you need a short name, "cluster events" might also work but there's no prior art for that in any driver spec.

Disregard if this name was intentionally chosen for consistency with existing driver docs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, in general it is ok if this page differs from the same page in other docs. Each docs standardization is meant to improve on previous ones!

- Description

* - ``ServerChangedEvent``
- Created when an instance state changes, such as from secondary to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the docs for ServerChangedEvent we say the event class "encapsulates information about a changed server description".

Here, the table is presenting the event as the thing that happened instead of just an object containing some information about a thing that happened.

The "Condition" column in Events API from the driver spec might be helpful. Note that the spec includes "Description" in the name of these events, where PHP just calls it ServerChangedEvent. I think that was due to us copying the shorter name from our libmongoc dependency.

I might suggest:

When the server description changes, such as the server's type changing from secondary to primary.

@rustagir rustagir requested a review from jmikola September 19, 2024 17:51
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggested rewording, but I want to wait until I hear back from other folks in drivers before signing off on the ServerOpeningEvent text.


* - ``TopologyClosedEvent``
* - :php:`TopologyClosedEvent <mongodb-driver-monitoring-topologyclosedevent>`
- Created when the topology is closed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd reword this as "the driver disconnects from the cluster". Given the event name, I don't think we need to repeat "topology is closed" in the description, although you can still include both if you like. In that case, maybe note the disconnect behavior with "i.e." or something.

Per the SDAM Monitoring spec, this would always be the last event to be dispatched. In the PHP driver, it's not actually possible to observe this event when using default behavior, as we persist the libmongoc client object (and thus the connections) beyond the lifetime of the PHP script. So by the time a client is actually closed, there'd be no subscriber in memory to receive the event.

This event can only be observed when specifying disableClientPersistence: true in the Manager or Client driver options array. There's more context to be found in PHPC-2023 and mongodb/mongo-php-driver@c2410ab.

Having said that, I think it's sufficient to just refer to disconnecting from the cluster here. And admittedly, we (the PHP team) should improve the docs for these event classes. I created PHPC-2449 to track that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for providing this background!

@rustagir rustagir requested a review from jmikola September 23, 2024 14:25
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with my suggestions applied.

- Created when the driver disconnects from the cluster.

* - :php:`ServerHeartbeatStartedEvent <mongodb-driver-monitoring-serverheartbeatstartedevent>`
- Created when the server monitor sends a ``hello`` call to the server.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Created when the server monitor sends a ``hello`` call to the server.
- Created when the server monitor sends a ``hello`` command to the server.

"Command" is less ambiguous.

- Created when a server connection is closed.

* - :php:`TopologyChangedEvent <mongodb-driver-monitoring-topologychangedevent>`
- Created when the topology description changes, such when there is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you accidentally a word in this sentence.

Suggested change
- Created when the topology description changes, such when there is
- Created when the topology description changes, such as when there is

@rustagir rustagir merged commit e2cc75b into mongodb:php-standardization Sep 23, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants