Skip to content

Conversation

@hermanschaaf
Copy link
Member

Before, when pressing ctrl+c, these messages would show in the CLI:

failed to terminate destination client:  destination plugin process exited with status signal: killed
failed to terminate source client:  source plugin process exited with status signal: killed

This PR fixes it so that these messages no longer appear. This is the main user-facing change.

Other changes include:

  • sending an analytics message when the sync ends for any reason, rather than only on successful syncs
  • include an "exit reason" in the analytics message, so that we can better understand when and why syncs fail
  • introduction of an CQ_ANALYTICS_HOST environment variable that can override the default host. This is mainly useful for testing, so no code changes are necessary to send analytics to a test server. For normal operation, users should still use --telemetry-level or CQ_TELEMETRY_LEVEL to control the telemetry
  • send analytics not only for the GitHub registry, but also for path and grpc registries. This can help us better understand how plugins are being deployed. We strip off any potentially identifying information and send only the final part of the path (i.e. the name of the binary)

This change will be improved by cloudquery/plugin-sdk#664 but doesn't depend on it to work.

Copy link
Contributor

@yevgenypats yevgenypats left a comment

Choose a reason for hiding this comment

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

Few questions on the context. still need to give it another review as it's tricky code section.

opts = append(opts, source.WithNoSentry())
}
sourceClient, err := source.NewClient(ctx, sourceSpec.Registry, sourceSpec.Path, sourceSpec.Version, opts...)
sourceCtx, sourceCancel := context.WithCancel(context.Background())
Copy link
Contributor

Choose a reason for hiding this comment

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

why background here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea here is that the CLI should manage the context for the plugins. If the CLI receives a signal and its context gets cancelled, we don't want that to bubble down to the plugins, because then we don't have time to fetch metrics first and send a shutdown signal of our own. Instead, the CLI should listen for when its context gets cancelled, do some clean-up, and then cancel the contexts of the plugins

Copy link
Member Author

Choose a reason for hiding this comment

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

To add to this: now that cloudquery/plugin-sdk#664 has been merged, the plugins should run in a separate process group, so they won't receive an interrupt signal from the OS when ctrl+c is pressed. However, we still use a command with context which sends a kill signal as soon as the context is cancelled. To avoid this, we will either need to stop using CommandContext, or send a different context like the change in this PR is doing.

defer log.Info().Str("source", sourceSpec.VersionString()).Strs("destinations", destinationStrings).Time("sync_time", syncTime).Msg("End sync")

destClients, err := newDestinationClientsV0(ctx, sourceSpec, destinationsSpecs, cqDir)
destCtx, destCancel := context.WithCancel(context.Background())
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here? why context.Background ?

@erezrokah
Copy link
Member

Is there anything blocking us from merging and releasing this?

@hermanschaaf
Copy link
Member Author

@erezrokah It's been a few weeks, so I'd like to just do a quick round of manual testing again to ensure that it all still works as expected. Some of these scenarios, like ctrl+c behavior, are not currently being tested in an automated way (though maybe that would be a good test to add)

@hermanschaaf hermanschaaf added the automerge Automatically merge once required checks pass label Feb 27, 2023
@hermanschaaf
Copy link
Member Author

I did some more testing and it still looks good, let's merge it

@kodiakhq kodiakhq bot merged commit 4fbaefe into main Feb 27, 2023
@kodiakhq kodiakhq bot deleted the send-stats-when-sync-ends branch February 27, 2023 13:30
kodiakhq bot pushed a commit that referenced this pull request Feb 28, 2023
🤖 I have created a release *beep* *boop*
---


## [2.4.0](cli-v2.3.10...cli-v2.4.0) (2023-02-28)


### Features

* Better handling of Ctrl+C, log failure reason when sync ends abruptly ([#7756](#7756)) ([4fbaefe](4fbaefe))


### Bug Fixes

* **deps:** Update module github.com/cloudquery/plugin-sdk to v1.39.0 ([#8344](#8344)) ([9c57544](9c57544))
* **deps:** Update module github.com/cloudquery/plugin-sdk to v1.39.1 ([#8371](#8371)) ([e3274c1](e3274c1))
* Update CLI SDK to sync sources in order they appear in config ([#8403](#8403)) ([e36e891](e36e891))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Automatically merge once required checks pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants