Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/cmd
AgeCommit message (Collapse)Author
2021-12-16Merge branch 'pks-limithandler-remove-globals' into 'master'John Cai
limithandler: Refactor package to not use global state See merge request gitlab-org/gitaly!4197
2021-12-16testdb: Rename functions to avoid stutteringPatrick Steinhardt
The functions `testdb.NewDB()` and `testdb.GetDBConfig()` both stutter. Rename them to `testdb.New()` and `testdb.GetConfig()`, respectively.
2021-12-16glsql: Move test database implementation into testdb packagePatrick Steinhardt
The glsql package hosts both the implementation used to connect to a "normal" production database as well as the logic to connect to a test database. Mixing production and test code like this is bad practice though. Move test-related functions into the "testdb" package to fix this. This change requires the glsql tests to use a separate package to break a cyclic dependency between the "glsql" and "testdb" package. And furthermore, the linter kicks in after this move and (legitly) complains about missing error checks and closes for rows.
2021-12-15limithandler: Refactor package to not use global statePatrick Steinhardt
The limithandler package uses global variables to both track Prometheus metrics and to handle its configuration. Especially the latter is really fragile, where we need to set up state of the limithandler in various places by calling global functions. Fix this by making the `LimiterMiddleware` self-contained, where it hosts all configuration as well as the Prometheus metrics.
2021-12-15gitaly: Inject the limit handlerPatrick Steinhardt
The limit handler is currently created ad-hoc by Gitaly's server code. We're about to change the way it hosts Prometheus metrics though such that we can get rid of a set of global variables, and this will require us to make sure that there's only a single instance of the limiter. Inject the limit handler as a dependency when creating the server to prepare for this.
2021-12-14Merge branch 'jc-repositories-missing-primary' into 'master'John Cai
praefect: add missing primaries check See merge request gitlab-org/gitaly!4176
2021-12-14cmd/praefect: Add missing primaries checkJohn Cai
Add a praefect startup check to get the number of repositories that have a missing primary. This check fails if there are any repositories are deemed unavailable. Changelog: added
2021-12-14tests: Convert to use testhelper contextsPatrick Steinhardt
We're about to disallow use of "normal" contexts created via the `context` package given that they do not perform sanity checks for feature flags. Instead, contexts should be created via the testhelper package. Convert tests to use the testhelper context.
2021-12-13Merge branch 'pks-bootstrap-rewrite-tests' into 'master'John Cai
bootstrap: Rewrite tests to not use timeouts See merge request gitlab-org/gitaly!4188
2021-12-13Merge branch 'jc-replicate-immediately' into 'master'John Cai
praefect: replicate immediately after track-repository Closes #3892 and #3909 See merge request gitlab-org/gitaly!4183
2021-12-13cmd/praefect: add helper text to explain replicationJohn Cai
Adds some text that explains what is happening with replication. The command either creates replication jobs in the queue, or it replicates immediately. In both of these cases, print out helpful messages. This also adds a writer in the command so we don't rely on the logger so the output is more reader friendly. Changelog: added
2021-12-13cmd/praefect: replicate immediately after track-repositoryJohn Cai
track-repository is a subcommand that tracks a repository in the praefect database. This is generally used by an admin when a repository is on disk but not tracked in the praefect db. Once tracked, replication to the other nodes takes about 5 minutes and requires the Praefect process to be running. This MR adds a flag that, if set, will immediately process a relication job and wait for it to finish. Changelog: added
2021-12-13bootstrap: Use ticker to get rid of test timeoutsPatrick Steinhardt
The bootstrapping tests still need to use timeouts because of the grace period, which is the duration we give the server to exit before we force the upgrade. Convert the interface to instead accept tickers such that we can get rid of using timeouts in our tests.
2021-12-11cmd/praefect: create replication eventsJohn Cai
track-repository inserts database records for praefect to track the repository, but doesn't insert any replication jobs. When a mutator RPC comes through, it will trigger replication but we want to make sure that no matter what the reositories are replicated to its secondaries. Also refactors the tests to no longer test sql replication, as that is no longer supported. Changelog: fixed
2021-12-10backup: Fix missing feature flag testsPatrick Steinhardt
The backup restoration tests aren't testing feature flags for atomic creation and removal of repositories. This went undetected because the tests used `context.Background()` to create the context instead of using `testhelper.Context()`, which would've set up additional sanity checks for feature flags. Exercise the feature flags. This uncovers a bug in the test setup if running with Praefect: because the repository entry does not exist in the database, Praefect intercepted the repository removal and never forwarded it to Gitaly. As a result, at the time we try to create the repository the old repository still exists. This used to work alright, but now fails with atomic repository creation enabled because the target repository must not exist yet. Fix this setup by creating the repository with `CreateRepository()` first.
2021-12-10backup: Replace use of standard contexts with testhelper onesPatrick Steinhardt
Tests should always use the testhelper package to create contexts such that we can benefit from the feature flag sanity checks. Convert backup tests to do so.
2021-12-10backup: Parallelize testsPatrick Steinhardt
Use better parallelization for tests by adding `t.Parallel()` calls as required. Like this, tests drop from 28 seconds of execution time to only 8 seconds.
2021-12-10Merge branch 'pks-linting-disallow-context-timeouts' into 'master'Patrick Steinhardt
lint: Forbid use of context timeouts in tests See merge request gitlab-org/gitaly!4162
2021-12-10gitaly-lfs-smudge: Fix missing close for HTTP bodyPatrick Steinhardt
The gitaly-lfs-smudge command is a smudge filter for Git which will replace contents of LFS pointers with the actual LFS object's contents. To do so, we need to request the object's contents from Rails via an HTTP request. The tests exercising this code all of a sudden started failing due to leaking Goroutines, where the leak happens in the HTTP handling code. And sure enough: we never close the `http.Response` body, which may likely be the root cause here. Fix this by always closing the body. While I have no idea why leaks started to happen just now, chances are high that this fixes the new flake.
2021-12-10replicator: Use ticker to process stale jobsPatrick Steinhardt
The function which processes stale jobs takes a configurable duration for how often the monitoring loop should run. This makes it hard to control the ticker from the outside, most importantly in tests. Refactor the code to instead accept a ticker and amend tests to use a manual ticker to get rid of timeouts.
2021-12-07git2go: Use gob for submodule sub-command invocationPavlo Strokov
So far we used JSON serialization to invoke submodule sub-command of the git2go executable. We are moving towards usage of the gob serialization to do the same and use stdin and stdout of the process to get an input and return the result of the execution. gob doesn't require us to do mapping of the fields and allows passing typed errors between the processes. In order to support smooth migration we should support both serialization formats. We can drop support of the JSON in the next release. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/3232 Changelog: changed
2021-12-06Make remove-repository dry-run by defaultJohn Cai
remove-repository is a destructive command. In order to make it safer to use, make it print what it intends to destroy by default. This is a "dry run". Only when --destroy is passed in will the command actuall remove database records and delete the repository on disk. Changelog: changed
2021-12-06testhelper: Rename `GrpcEqualErr()` to `RequireGrpcError()`Patrick Steinhardt
The naming of the `GrpcEqualErr()` helper function is quite irregular compared to other helper functions we have. Most importantly, it's significantly different from `RequireGrpcCode()` and may thus be easy to miss. Rename it to `RequireGrpcError()` to clarify this.
2021-12-06testhelper: Absorb helpers from the testassert packagePatrick Steinhardt
Personally, whenever I want to compare gRPC errors and/or messages, I stand there asking myself where the helper I want is located again. This is caused by a split we have in test helpers related to gRPC: while we do have `testhelper.RequireGrpcError()`, checking for actual errors is done via `testassert.GrpcEqualErr()`. I always have to look up which of both does what and where it's located. Fix this by absorbing the helpers from the testassert package into the testhelper package.
2021-12-03featureflag: Consolidate feature flags context APIPatrick Steinhardt
Consolidate the feature flags context APIs such that we have the same set of functions for creating feature flags in incoming and outgoing contexts.
2021-12-03tests: Add missing tests for atomic repo creation feature flagPatrick Steinhardt
Some tests use CreateRepository et al, but don't verify that they still work with the corresponding feature flag which enables atomic repository creation. Some don't care but will start to fail when tests are required to explicitly inject all feature flags which are used, and others do care but weren't addressed. Add missing feature flags as required to prepare for explicitly required feature flags.
2021-12-01testhelper: Improve creation of loggersPatrick Steinhardt
The testhelper has functions to create test loggers for us. These are awkardly named though, and furthermore we have a global variable which contains a reference to one of the functions which creates the logger for us, which is bad design. Furthermore, this global variable isn't modified by anything anymore, making it essentially the same as the function it's aliasing. Rename functions to match Go best practices and remove the global variable.
2021-11-30Merge branch 'ps-dsn' into 'master'John Cai
glsql: Compile DSN from configuration See merge request gitlab-org/gitaly!4138
2021-11-30Merge branch 'smh-generalize-dataloss' into 'master'Patrick Steinhardt
Add 'praefect metadata' subcommand Closes #3481 See merge request gitlab-org/gitaly!4122
2021-11-30Add 'praefect metadata' subcommandSami Hiltunen
Praefect doesn't yet have any way of fetching a repository's metadata. With the addition of replica path, this is becoming increasingly important as users may need to figure out where on the disk a given repository is stored. They may also want to figure out which repository on the disk a replica actually belongs to. Likewise, it's currently not possible to really see which Gitaly node is acting as a primary of a repository. The dataloss subcommand does provide some of this information but it only returns information when a repository is not fully replicated. To address this gap, this commit adds 'praefect metadata' subcommand that can be used to fetch a repository's metadata. Users can fetch the metadata either by the repository's ID or by its virtual storage and relative path to accommodate all possible queries. Changelog: added
2021-11-26Merge branch 'jc-postgres-readwrite-check' into 'master'Toon Claes
praefect: Add database read/write check Closes gitlab#328493 See merge request gitlab-org/gitaly!4121
2021-11-24Merge branch 'jc-use-timeout-in-dialnodes' into 'master'John Cai
dial-nodes: add timeout flag Closes #3936 See merge request gitlab-org/gitaly!4123
2021-11-24dial-nodes: add timeout flagJohn Cai
A recent refactor got rid of a default timeout for the dial nodes subcommand. This change adds a flag -timeout that can be passed into the command so that it doesn't have to wait the full 30 seconds to get a timeout error back. Changelog: changed
2021-11-24glsql: Replace DB.ToPQString with glqlsql.DSNPavlo Strokov
The change removes ToPQString method and replaces its usages with glsql.DSN function.
2021-11-23praefect: Add database read/write checkJohn Cai
In order to check if praefect can read/write to a database, we can use the hello_world table. We can try inserting a row, and reading from it. Changelog: added
2021-11-23praefect: Fix repository being created twicePatrick Steinhardt
One of our testcases creates a Gitaly repository twice, and this will lead to an error when we convert `CreateRepository()` to disallow recreation of repositories. Fix the test to only create it once.
2021-11-22Merge branch 'jc-add-result-text-list-repositories' into 'master'John Cai
praefect: Add text clarifying what list-untracked-repositories output signfiies Closes #3890 See merge request gitlab-org/gitaly!4055
2021-11-22Merge branch 'error_summary' into 'master'Toon Claes
Collect summary of backup errors See merge request gitlab-org/gitaly!4049
2021-11-18Merge branch 'jc-pass-logger-into-checks' into 'master'John Cai
Use verbose flag in Checks See merge request gitlab-org/gitaly!4060
2021-11-18praefect: print verbose output in check subcommandJohn Cai
When an admin runs the praefect startup checks, it would be useful to print more information about each check. This change refactors some of the code to allow that to happen, and also a -q flag that the user can pass to silence this detailed outpt. Changelog: changed
2021-11-18praefect: Add text clarifying what list-untracked-repositories output signfiiesJohn Cai
list-untracked-repositories currently outputs json rows for repositories that exist on disk but are untracked by the database. It's unclear what these rows are. Add helper text to signal to the user what these rows mean. Changelog: changed
2021-11-17praefect: add test to ensure database metrics collector registrationJohn Cai
Add a test to ensure that the PrometheusExcludeDatabaseFromDefaultMetrics controls whether or not it gets registered in the main metrics registry.
2021-11-17praefect: Add ability to have separate database metrics endpointJohn Cai
By default, when metrics are enabled, then each Praefect will expose information about how many read-only repositories there are, which requires Praefect to query the database. First, this will result in the same metrics being exposed by every Praefect given that the database is shared between all of them. And second, this will cause one query per Praefect per scraping run. This cost does add up and generate quite some load on the database, especially so if there is a lot of repositories in that database, up to a point where it may overload the database completely. Fix this issue by splitting metrics which hit the database into a separate endpoint "/db_metrics". This allows admins to set up a separate scraper with a different scraping interval for this metric, and furthermore it gives the ability to only scrape this metric for one of the Praefect instances so the work isn't unnecessarily duplicated. Given that this is a breaking change which will get backported, we must make this behaviour opt-in for now. We thus include a new configuration key "prometheus_use_database_endpoint" which enables the new behaviour such that existing installations' metrics won't break on a simple point release. The intent is to eventually remove this configuration though and enable it for all setups on a major release. Changelog: added
2021-11-16Merge branch 'pks-commit-tree-entries' into 'master'Patrick Steinhardt
commit: Refactor recursive `GetTreeEntries()` for efficiency Closes #3888 See merge request gitlab-org/gitaly!4052
2021-11-16backup: Collect summary of backup errorsJames Fargher
Start collecting errors so that these can be summarised at the end of the backup run. Previously errors were only reported in logging which is often ignored. Changelog: changed
2021-11-12Merge branch 'ps-db-connect-hangs' into 'master'Toon Claes
praefect: Praefect should not hang if db is not reachable Closes #3678 See merge request gitlab-org/gitaly!4034
2021-11-12lint: Inline exceptions about missing documentationPatrick Steinhardt
Most of the linting exception we have are about missing documentation of public variables or comments. Let's inline all of these -- it's hard to keep track of exceptions and keep the list up-to-date. By having a `//nolint` directive at the site where the document is missing it becomes a breeze to directly clean it up. Furthermore, it also acts as a reminder that one might want to add a comment when one stumbles over any of these comments.
2021-11-12lint: Clean up various exception for the errcheck linterPatrick Steinhardt
Clean up various exceptions for the errcheck linter, either by removing exceptions which don't apply anymore, by handling the errors or by ignoring errors.
2021-11-12praefect: Log listening message in proper placePavlo Strokov
The Praefect printed log message about listening addresses too far from the actual point when it starts to listen on them. This change moves the log message to the proper place.
2021-11-12praefect: Praefect should not hang if db is not reachablePavlo Strokov
If the database is not accessible the at the time of Praefect start it hangs forever and doesn't report much information about the reason. The attempt to fix it by using PingContext with timeout set on the context failed because of the issue in the lib/pq that is not yet fixed. The problem is solved by a separate goroutine that issues the PingContext and main goroutine watching the timeout. If timeout occurs it returns an error up to the caller. Another goroutine won't be over and hangs, but we don't care much as it is a critical error and the service will be terminated. Closes: https://gitlab.com/gitlab-org/gitaly/-/issues/3678