Skip to content
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

feat: Implement Enhanced Syslog for Dagger-Registry Redirect and Add Local Testing Guide #5

Merged
merged 16 commits into from
Aug 15, 2023

Conversation

grouville
Copy link
Member

@grouville grouville commented Jul 25, 2023

Fixes https://linear.app/dagger/issue/INFRA-36/mitigate-registrydaggerio-nats-spof

Problem

@gerhard and @jlongtine found out that when Fly.io NATS is affected, our ability to report metrics becomes affected too. See the original incident for more details.

Solution

This PR extends the app's logger to write to syslog as well as the current stdout.
As these are important changes, a markdown file Local Testing Guide for Dagger-Registry Redirect.md explains how to test the app.

Pre-requisites

Follow-up

  • update Magefile to deploy this app in parallel in fly.io (taking into consideration the new API v2 changes)
  • update corresponding Vector files: https://github.com/dagger/dagger.io/pull/2735, verify filter's app name (review listening interface)
  • one last manual check that everything behaves correctly
  • point registry.dagger.io to the new app instance
  • delete previous registry-redirect instance in ~24h when we have the confidence that everything behaves as expected

@grouville grouville requested a review from gerhard July 25, 2023 17:11
@grouville grouville marked this pull request as draft July 25, 2023 17:21
main.go Outdated Show resolved Hide resolved
pkg/logger/logger.go Outdated Show resolved Hide resolved
pkg/syslogger/syslogger.go Outdated Show resolved Hide resolved
grouville added 3 commits July 28, 2023 18:31
…Local Testing Guide

This commit introduces several enhancements and new features:

- Implemented a new Syslog in pkg/logger/logger.go with accompanying unit tests in logger_test.go.
- Introduced the Syslog writer in pkg/syslogger/syslogger.go, along with a mock_syslogger for testing purposes. Unit tests for the syslogger are available in syslogger_test.go.
- Updated main.go to integrate the new Syslog functionalities.
- Made relevant updates to dependencies in go.mod and go.sum.
- Added a comprehensive local testing guide (Local Testing Guide for Dagger-Registry Redirect.md) to facilitate local testing and verification of the Dagger-Registry Redirect.

These improvements enhance the logging capabilities of the Dagger-Registry Redirect and streamline the process of local testing.

Signed-off-by: grouville <[email protected]>
- Remove interface, as no mockups are required
- Rename and simplify code
- Modify syslogger unit tests (race conditions)
- Add logger integration test (currently not testing http server graceful shutdown)

Signed-off-by: grouville <[email protected]>
Still a race on the logger, I wonder what the best synchronization strategy is the best option:
- a wg group at the handler level
- a buffer at the logger level

Signed-off-by: grouville <[email protected]>
Test deploying the app on fly, redirect to ngrok -> local vector instance

Signed-off-by: grouville <[email protected]>
@grouville grouville force-pushed the add-syslogger branch 2 times, most recently from 529141d to edf701a Compare August 4, 2023 23:34
E2E integration test in which we test our shutdown logic to see if we lose data when having a concurrent shutdown signal and incoming streams. In this test, we setup a local HTTP and TCP server (fake syslogger), send X messages to the HTTP server and right after that send the HTTP shutdown signal (faked with a channel).

The HTTP server mimicks our main.go implementation: it wraps the handler with a waitGroup and waits for all processed logs to be written in the HTTP shutdown goroutine.

Signed-off-by: grouville <[email protected]>
- Update docs to follow new testing methodology
- Implement app name retrieval from env

Signed-off-by: grouville <[email protected]>
Copy link
Member

@gerhard gerhard left a comment

Choose a reason for hiding this comment

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

Looking good, almost there!

magefiles/dagger.go Outdated Show resolved Hide resolved
Local Testing Guide for Dagger-Registry Redirect.md Outdated Show resolved Hide resolved
magefiles/dagger.go Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
pkg/logger/logger_test.go Outdated Show resolved Hide resolved
pkg/logger/logger_test.go Outdated Show resolved Hide resolved
pkg/logger/logger_test.go Outdated Show resolved Hide resolved
pkg/logger/logger_test.go Outdated Show resolved Hide resolved
grouville and others added 4 commits August 8, 2023 15:52
Update handler's logic, cleanup test, make app more generic with env variables

Signed-off-by: grouville <[email protected]>
Co-authored-by: Gerhard Lazu <[email protected]>
When closing the syslog server, I was not signaling the main goroutine that all messages had been processed.
Also, easier implementation of httpserver

Signed-off-by: grouville <[email protected]>
Rely on JSON formatting for easier processing on Vector's side

Signed-off-by: grouville <[email protected]>
Implements the reconnection mechanism in logger's logic, when losing the TCP connection

Signed-off-by: grouville <[email protected]>
Signed-off-by: grouville <[email protected]>
grouville and others added 2 commits August 10, 2023 14:20
Guard against a segfault when the writer hasn't connected

Signed-off-by: grouville <[email protected]>
Also sensible default values when running locally, nothing
platform-specific.

Signed-off-by: Gerhard Lazu <[email protected]>
@grouville grouville marked this pull request as ready for review August 14, 2023 14:28
So that this is set at deploy time & we have a single source of truth.

Signed-off-by: Gerhard Lazu <[email protected]>
@gerhard gerhard force-pushed the add-syslogger branch 2 times, most recently from 27fdff0 to da6d7de Compare August 15, 2023 11:55
Only deploy when the app source has changed (including the pipeline code).

Remove logs target since it did not prove useful to have - we run this
command locally when we need it.

Share the same client when running multiple targets via All

Signed-off-by: Gerhard Lazu <[email protected]>
We do not use the top-level go deps for GHA, everything runs in Dagger.

Signed-off-by: Gerhard Lazu <[email protected]>
Copy link
Member

@gerhard gerhard left a comment

Choose a reason for hiding this comment

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

👍 🚀

@gerhard gerhard merged commit 52afd45 into dagger:main Aug 15, 2023
1 check 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.

2 participants