Commit Graph

413 Commits

Author SHA1 Message Date
Matt
0092d3a118 Upgrade to Go 1.22 toolchain (#1987)
Upgrades to the Go 1.22 toolchain. Upgrades golangci-lint to 1.61.0 and disables some new linters.

---------

Co-authored-by: Nicholas Wiersma <nick@wiersma.co.za>
2024-09-28 05:51:14 +00:00
Taylor Chen
3856c6feee add timeout to vcsLister.List() (#1986) 2024-09-20 08:19:47 +02:00
Balazs Sandor
70ee634a80 Add http body to list handler on error (#1974)
Mimic responses to that of proxy.golang.org when a list fails to produce a result.
2024-09-09 03:23:40 +00:00
yueluhuan
34002b8408 Switch from ADAL to AzIdentity, Add Azure Storage Token Refresh, and Update Golang Version (#1977)
Uses the new Azure Identity package for current support. Support automated Azure storage token refresh. Sets the default value of Athens storage account key and Azure managed identity resource id should be empty.
2024-09-09 03:03:26 +00:00
yueluhuan
1e39c23d72 Add aad auth option when using azure storage account (#1973)
Support managed identity authentication in Azure Blob Storage.
2024-07-14 18:21:31 -07:00
Matt
bde4952614 Set correct content type and send once (#1965)
Set correct Content-Type headers on each endpoint rather than on the router. The router would, at times, send two Content-Type headers and other times just send the wrong one.
2024-06-02 19:49:36 +00:00
Derek Buitenhuis
0ef761cc8b gcp/saver: Only return errors.KindAlreadyExists if all three exist (#1957)
* gcp/saver: Only return errors.KindAlreadyExists if all three exist

In #1124, a GCP lock type was added as a singleflight backend. As part of this work, the GCP backend's Save() was made serial, likely because moduploader.Upload requires a call to Exists() before it, rendering the GCP lock less useful, by doubling the calls to GCS.

However, by doing this, the existence check was now only checking the existence of the mod file, and not the info or zip. This meant that if during a Save, the zip or info uploads failed, on subsequent rquests, that when using the GCP singleflight backend, Athens would assume everything had been stashed and saved properly, and then fail to serve up the info or zip that had failed upload, meaning the cache was in an unhealable broklen state, requiring a manual intervention.

To fix this, without breaking the singleflight behavior, introduce a metadata key that is set on the mod file during its initial upload, indicating that a Stash is still in progress on subsequent files, which gets removed once all three files are uploaded successfully, which can be checked if it it is determined that the mod file already exists. That way we can return a errors.KindAlreadyExists if a Stash is in progress, but also properly return it when a Stash is *not* currently in progress if and only if all three files exist on GCS, which prevents the cache from becoming permanently poisoned.

One note is that it is possible the GCS call to remove the metadata key fails, which would mean it is left on the mod object forever. To avoid this, consider it stale after 2 minutes.

---------

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Co-authored-by: Matt <matt.ouille@protonmail.com>
2024-06-02 19:32:54 +00:00
Yong Zhang
0e1af85c0b Fix AWS default credentials (#1963)
Fix a bug where default credentials were erroneously cleared out, which broke several implementations.
2024-05-22 19:15:48 -07:00
Vanes Angelo
900cb4f7c1 Upgrade to AWS SDK v2 (#1938) (#1950)
Upgrades the AWS SDK to v2. AWS S3 bucket urls will now error if they are not prefixed with a schema (example: https://).
2024-04-28 21:38:42 -07:00
Matt
359c119441 Add an introduction page as the home page (#1945)
A default homepage is baked into the server that uses the request host address, or in HTTP 2 the authority. This includes ports. It also checks for schema. The values are used to indicate to users how to configure their go env

Of course, this won't work on all installations - especially enterprise ones. For that, we've introduced ATHENS_HOME_TEMPLATE_PATH as an environment variable along with HomeTemplatePath in the config. This value defaults to /var/lib/athens/home.html but can be configured to any location that Athens can reliably read from. This is a Go HTML template so it should use Go HTML template formatting and logic.
2024-04-20 00:19:34 -07:00
kkHAIKE
81415839ba Fix an issue where contexts are not copied correctly (#1941)
Fix an issue in the Stasher where contexts between the request and log entry are not copied correctly.

Co-authored-by: ouyangxu <ouyangxu@bilibili.com>
2024-04-13 13:35:25 -07:00
kkHAIKE
a5277a3e7a Use errors.AsErr to extract and detect errors.Error (#1936)
Switches from using errors.Is() to errors.As() so the error context is passed correctly.
2024-04-09 14:25:00 -07:00
Matt
b9c8fb7f8a Rework logging defaults (#1927)
Changes default logger back to plain.
2024-03-27 17:48:10 -07:00
tanx
c072f6089a Update mongodb driver (#1928)
Updates the MongoDB driver
2024-03-25 15:39:14 -07:00
Matt
08520bf894 Add log formatting settings (#1926)
Adds a log format setting as ATHENS_LOG_FORMAT that can be either plain or JSON when CloudRuntime is none (the default). Does not break or change any existing behavior.
2024-03-21 09:07:39 -07:00
wozz
3af0d009a8 singleflight go commands (#1877)
* singleflight go commands

* Apply suggestions from code review

Co-authored-by: Brendan Le Glaunec <brendan@glaulabs.com>

---------

Co-authored-by: michael-wozniak <michael.wozniak@snapchat.com>
Co-authored-by: Brendan Le Glaunec <brendan@glaulabs.com>
2023-12-21 15:37:36 +02:00
yatesliang
aca3cc0090 test: unit test for testing KindUnexpected case in Mongo query function (#1883) 2023-09-25 00:24:02 -07:00
Thomas
9a14565152 fix(pkg/stash): close etcd sessions (#1887) 2023-09-18 12:15:41 -07:00
Thomas
1d16cc3070 fix(pkg/stash): don't check status of all etcd endpoints on start (#1889) 2023-09-18 11:54:33 -07:00
Thomas
e248d22892 fix(proxy): don't check TLS file permission (#1880) 2023-09-01 07:44:47 -07:00
Nicholas Wiersma
6be4bebc0c chore: switch from interface{} to any (#1837) 2023-06-23 15:41:27 +02:00
LINKIWI
e5aa5974e1 Support Unix domain sockets for proxy server listener (#1865) 2023-05-06 11:35:06 +02:00
Nicholas Wiersma
7c3e3a0999 fix: relax file permissions (#1866) 2023-04-14 08:25:53 +02:00
Zhongpeng Lin
b72a768a05 use errors.AsErr (#1849)
Co-authored-by: Manu Gupta <manugupt1@gmail.com>
2023-03-12 22:04:12 -07:00
Zhongpeng Lin
5099b30ac6 Removing Exists() check from S3 getters (#1842)
* Atomic access to S3

* fixing linting errors

* make delete return KindNotFound

* restore checker and deleter
2023-03-03 19:46:09 -08:00
Zhongpeng Lin
1f0a460687 Calling HeadObjectWithContext() concurrently to check the existence of a module (#1844)
* Using HeadObject to check the existence of a module

* fixing build

* calling cancel before closing channel

* fixing test

* using waitgroup

* calling cancel

* calling wg.Done

* only return the first error

* Revert "only return the first error"

This reverts commit c0aa18b522.

* clean err if not exist
2023-03-03 14:56:12 -05:00
Nicholas Wiersma
748aa4d165 chore: remove last drone remains (#1839)
* chore: remove drone

* fix: cr suggestions

* fix: cr suggestions
2023-02-28 18:51:12 +08:00
Nicholas Wiersma
d932d50232 chore: lint code with golangci-lint (#1828)
* feat: add golangci-lint linting

* chore: fix linter issues

* feat: add linting into the workflow

* docs: update lint docs

* fix: cr suggestions

* fix: remove old formatting and vetting scripts

* fix: add docker make target

* fix: action go caching

* fix: depreciated actions checkout version

* fix: cr suggestion

* fix: cr suggestions

---------

Co-authored-by: Manu Gupta <manugupt1@gmail.com>
2023-02-24 20:39:17 -08:00
Ashish Ranjan
3f26845cff move to github actions from drone (#1823)
* add github actions workflow for tag releases

* migrate drone build &test step to github actions

* fix minio service

* fix indentation

* fix dependency syntax

* remove needs keyword

* fix service hostnames, add protectedredis

* update protected redis docker image

* fix too many args error

* exclude vendor dir from gofmt

* fix fmt errors

* fix fmt errors

* rm .drone.yml

* rename workflow name

* break test step

* remove vendor step

* use makefile rule

* use buildx
2023-02-22 22:47:37 -08:00
Zhongpeng Lin
6aaf9e5b17 Handle duplicate keys returned by S3 ListObject (#1793)
S3 API sometimes returns duplicate keys, causing the number of file for a specific module greater than 3. This PR makes Athens handle that situation gracefully and log a warning message instead of treating the module as not found.

logging string content

Co-authored-by: Manu Gupta <manugupt1@gmail.com>
Co-authored-by: Ashish Ranjan <ashishranjan2912@gmail.com>
2023-01-30 13:01:09 +08:00
Eng Zer Jun
b3bc773e29 test(pkg/config): use t.Setenv to set env vars (#1821)
This commit replaces `os.Setenv` with `t.Setenv` in tests. The
environment variable is automatically restored to its original value
when the test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.Setenv

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: Ashish Ranjan <ashishranjan2912@gmail.com>
2023-01-30 13:00:37 +08:00
Mike Seplowitz
f35a5406a3 Pass Athens's logger to the Redis package (#1817)
Co-authored-by: Ashish Ranjan <ashishranjan2912@gmail.com>
2023-01-30 12:22:49 +08:00
Nicholas Wiersma
ab64133949 feat: replace ioutil with io and os (#1816) 2023-01-27 20:42:47 +05:30
Rob Prentiss
a1553999bb Make shutdown timeout configurable (#1806)
Currently, when shutting down the server (via SIGINT or SIGTERM), the
shutdown closes any open connections after only 10 seconds (via a
context.WithTimeout). This does not provie a lot of time for longer
operations, such as listing versions, or downloading a larger module zip
file.

When running in Kubernetes, and scaling instances or changing config,
this causes a lot of dropped connections and gateway errors. 10 seconds
is arguably much too short, and should be configurable.

This commit increases that default to 60 seconds, and adds a config
variable to allow users to specify their desired timeout.
2023-01-23 22:02:45 -08:00
Zhongpeng Lin
4c3443328e Adding new fields to RevInfo (#1812)
* Allow unknown fields in RevInfo

* Revert "Allow unknown fields in RevInfo"

This reverts commit 902d791554.

* Adding new fields to rev_info.go

* fixed tests
2023-01-16 12:11:10 -08:00
Jerry Ng
92150d0500 Update s3 checker to iterate through all objects pages (#1802) 2023-01-08 13:46:20 -08:00
Ashish Ranjan
cc496afbf1 read redis lock options from config to support custom TTL & timeout (#1791)
* read redis lock options from config to support custom TTL & timeout

* fix test

* fix typo

* downgrade to bsm/redislock@v0.7.2 to prevent usage of beta go-redis version

* revert test changes

* return error for invalid lock config

* update config parsing test

* udpate docs to include redis lock config

* fix test

* set default max retries to 10

* reduce default redis lock timeout to 15s

* update default TTL to 15mins

Co-authored-by: Manu Gupta <manugupt1@gmail.com>
2022-09-28 22:53:06 -07:00
Zhongpeng Lin
b8d7c4aa79 Register HTTP client views for stats (#1787) 2022-09-22 21:04:51 -07:00
Ashish Ranjan
7d67ee76ce fix default s3 credentials set as anonymous (#1789) 2022-09-15 18:30:54 -07:00
Ashish Ranjan
33777c5cc4 copy context before starting stash operations to prevent ctx cancellations (#1790)
* copy context before starting stash operations to prevent ctx cancellations

* add comment about context cancellation
2022-09-15 11:03:59 -04:00
Rob Prentiss
3fab46905e Resolve memory leaks when using Minio storage (#1777)
When using Minio storage, memory usage constantly increases. After
profiling, it appears that memory usage is building in the minio client,
and not being released.

Finding a similar issue listed in the minio/warp project, I found that
they fixed the issue by closing the *minio.Object instances. In the
athens usage, the minio.Object instances are never closed after reading
the data from them.

This adds deferred 'Close' calls in the 'storageImpl.Info' and
'storageImpl.GoMod' functions so that the objects may be released and
garbage collected. The 'storageImpl.Zip' function does not use defer,
since it has the object embedded into the return value, so the 'Close'
is only called on error.
2022-06-06 19:04:33 -04:00
Manu Gupta
be203340be Remove deprecated GOPROXY in favor of GoBinaryEnvVars (#1759) 2022-02-18 10:24:44 -08:00
Manu Gupta
3a40029ec8 Revert retries in redis-flake as builds are failing again. (#1758) 2022-02-16 12:31:47 -08:00
Manu Gupta
67bb68c45d Update etcd (#1756) 2022-02-15 09:10:51 -08:00
Manu Gupta
533035c40c fix flake on redis-sentinel by depending on redis container / step. (#1748)
* fix: flake on redis-sentinel by depending on redis container / step.

Signed-off-by: Manu Gupta <manugupt1@gmail.com>

* Add retries in an attempt to reduce the number of flakes

Also; update go-redis.

Co-authored-by: Aaron Schlesinger <70865+arschles@users.noreply.github.com>
2022-02-14 14:01:29 -08:00
Rob Lee
918ddfb59a Replace golint with go vet#1743 (#1744)
* Set GO111MODULE to auto in golint script– #1743

As mentioned in #1743 the Go modules environment flag is set to `off`
in the script which appears to cause a warning message for each module
of the codebase that it is "not in GOROOT".

Set to `auto` as this allows the same build to be run the original way
should someone choose to delete the `go.mod` file from the project root.

* Remove redundant code – golint script

Go 1.17 ignores `GO111MODULE` and there are no directories in the
project root called `mock`.

* Replace `golint` with `go vet`

`golint` is deprecated (and frozen) replace with the current `go vet`.
This reported one issue on `main` branch:
```pkg/stash/with_etcd.go:33:28:
loop variable ep captured by func literal```

Fixed loop variable capture with extraction to parameterised anonymous
function passed loop variable and passed in to `errgroup.Go` call.
2021-12-09 22:03:48 -08:00
Abhay Krishna
38a3039a21 Fix typos and comments in config.toml (#1739)
Co-authored-by: Marwan Sulaiman <marwan.sameer@gmail.com>
2021-12-03 01:38:09 -05:00
Aaron Schlesinger
2a8b8eed75 Fixing panic with S3 storage (#1730)
Signed-off-by: Aaron Schlesinger <70865+arschles@users.noreply.github.com>
2021-10-01 13:11:33 -07:00
Marwan Sulaiman
a724fcdddc Update mongo client to address CVE (#1728) 2021-08-18 22:49:44 -04:00
Zhongpeng Lin
4abe908a58 Using directory as prefix for S3 (#1720)
* Using directory as prefix for S3

* address comments

Co-authored-by: Marwan Sulaiman <marwan.sameer@gmail.com>
2021-08-18 21:06:51 -04:00