Граф коммитов

111 Коммитов

Автор SHA1 Сообщение Дата
Andrew Bonventre 7796a18097 discovery: add UI for “Back to godoc.org” button
With the option to redirect automatically from godoc.org, there needs
to be a mechanism to return to godoc.org and turn it off if necessary.
Reliably knowing that a request is coming from a godoc.org redirect
is complicated as you can’t set cross-origin cookies and 3XX redirects
don’t alter the Referer header.

In order to reliably know that a request is coming to pkg.go.dev from
godoc.org, we look for a utm_source GET parameter set to 'godoc'.
If we see this, we set a temporary cookie and redirect to the
pkg.go.dev URL with the utm_source param stripped (so that it doesn’t
remain in all our URLs coming from godoc.org). If this temporary cookie
is seen, it is marked to be deleted and the correct value for the
“Back to godoc.org” link is set. The existence of this value will be
used to determine whether to show the button in the UI.

Updates b/147492306

Change-Id: I9c2e6b891ba4f23b7490c087d32583cd7f0f6ad8
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/696565
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-04-06 17:09:52 -04:00
Andrew Bonventre 1832788466 discovery: move content/static/third_party to top-level directory
This is required per Google’s open source policies.

Change-Id: Iff06d489a30f051c024618e53f65e46d4f89df94
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/697023
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-04-06 17:09:52 -04:00
Jonathan Amsterdam 6e0f7e38ab cmd/worker: rename etl-log to worker-log
Change-Id: I8c4e5d356df26ad043d166737d8e774fc9a7e955
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/694065
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-04-06 17:09:52 -04:00
Jonathan Amsterdam 7f69d0c374 cmd/worker: get excluded filename from an env var
Change-Id: Ie5789e4b45924e758fa1654dafaf24842ab677d8
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/690402
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-04-06 17:09:52 -04:00
Jonathan Amsterdam 9cce535f22 cmd/worker: fix excluded.txt path
Change-Id: I90c4e3f5e54d752c1ff8293abbc94d5e63c93440
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/688360
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-04-06 17:09:51 -04:00
Jonathan Amsterdam 312ebec2bc many: rename etl to worker
Miscellaneous renames.

Updates b/150864416.

Change-Id: I3816a8f652c9ced989d9c929d2c2d42734c2f5b3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/686711
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-04-06 15:50:53 -04:00
Jonathan Amsterdam 2ec475d6de internal/worker: rename etl package to worker
This CL renames the package at internal/worker to "worker".

Updates b/150864416.

Change-Id: I9f3ab58faf57bfd78d14d880b4192e292b37f1b6
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/686703
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-04-06 15:50:52 -04:00
Jonathan Amsterdam 368146c56a all: rename directories from etl to worker
This CL only renames directories, and makes the minimal
changes needed for tests to pass.

Updates b/150864416.

Change-Id: Iebe977a1a80341e170c306e58851fa1b48ef79e6
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/686700
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-04-06 15:50:52 -04:00
Jonathan Amsterdam 54eb20f2f3 cmd/etl: fix path to excluded.txt
Change-Id: I236f0708ef9c44d47ae62a123c350cb1b013e8d3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/685279
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 15:50:52 -04:00
Jonathan Amsterdam 529ddcb91e cmd/etl: move excluded prefixes to a file
This keeps them under version control, but makes it easier to
remove them from the repo.

Updates b/150142069.

Change-Id: I7811f31cc35a2dd8125e43a3876115d2c6f18ad2
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/682844
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 15:50:52 -04:00
Jonathan Amsterdam 45ec602b7b cmd/etl: use time.Until
Replace t.Sub(time.Now()) with time.Until(t).

Change-Id: Ibaf0cfef92f8b60d2680339b4987a94cf2fa361c
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/680831
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 15:50:52 -04:00
Jonathan Amsterdam 0f8c7c9210 discovery: fix issues highlighted by mvdan.cc/unparam
I ran unparam (`go get mvdan.cc/unparam`) on our codebase, and
it found a few issues that I fixed.

- etl/main.go:getRedis: Use the context to set the DialTimout option when dialing redis.

- config.go:readOverrideFile: Use the bucketName argument, not a global constant.

- various: Remove unused parameters and return values.

Change-Id: I98a1e5d728d41033b5f632ccc6c22442d91c2b6d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/678587
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-04-06 15:50:52 -04:00
Jonathan Amsterdam a6ac6c2d74 config,cmd/frontend: try a secondary DB host if the main one is down
- Provide a way to configure a secondary DB host.

- Modify the frontend to try connecting to the secondary if the primary fails.

This is a partial solution to the problem discussed in the bug below. It deals
with DBs that are bad on startup, but not ones that go bad later. For that case,
we have to wait for the process to die, or kill it manually, so on restart it
can pick the secondary DB.

Updates b/149906513.

Change-Id: I177590111dc4544476a4b2aef39f06456ba28ab5
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/673861
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-04-06 15:50:52 -04:00
Jonathan Amsterdam cfcdc5826a internal/config: make more stateless
As per the bug listed below, we are trying to remove the global cfg
variable from the config package. This CL brings us close to that
goal. There are still two uses of the global that are harder to remove.

Updates b/145301722.

Change-Id: Ia6c350ef5d817ff7fb3125cd207343d10911d64f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/672580
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 15:50:52 -04:00
Julie Qiu c0dfa6a74d internal/queue: create package
The code for creating a new package is moved to internal/queue. This
allows for adding items to a task queue from the frontend, without
importing the entire internal/etl package.

No logic is changed, except the signature of
queue.InMemoryQueue.process, so that etl.FetchAndUpdateState can be
passed in, and the entire internal/etl package does not need to be
imported by internal/queue, which would lead to a circular import.

Updates b/135954292

Change-Id: I33a6418c73d85e15c4aa5593d633e19eb7e4eb1b
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/671014
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-04-06 15:50:52 -04:00
Julie Qiu f5696633a1 cmd/etl: unexcluded github.com/clevergo/clevergo
The author changed their mind and wants unexcluded
github.com/clevergo/clevergo back on the site.



Change-Id: I07a6c25dda1fb2861ca9553195cd4707f309e3a9
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/664075
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-04-06 15:50:51 -04:00
Jonathan Amsterdam b7b19005e3 cmd/etl: insert a hard-coded list of exclusions
Permanent exclusions (user requests, malicious license violations, etc.) are
at risk of vanishing if the DB is corrupted or truncated. Keep the
list in code (it's pretty small), and insert it on etl startup.

We clumsily check if it's present, then insert if it isn't. The alternatives
are: (1) check the error to see if it is a primary key violation, but that
requires looking into the pq package's errors, and we don't want to do that
(what if we switch DB clients?); or (2) change InsertedExcludedPrefix to
do some other conflict resolution, but that wouldn't be right for its
primary use with dbadmin.

Change-Id: If346d97326b3ef566eb0c9ce9387c05645e47955
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/663154
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-04-06 15:50:51 -04:00
Rob Findley d484cb5bc3 internal/config: export the Config type
In preparation for eliminating the cfg singleton, export the Config type
and add a load function that resolves a Config from the environment.

The Init method is kept around temporarily, but modified to return the
Config that was loaded. This allows for incrementally deprecating
dependence on the config singleton. In the future, the Init function
will be deprecated and Load will be exported, making the package
stateless.

Configuration values that were only used in main.go are now read
directly from the newly available Config instance. This allowed deleting
some functions in the config package.

Updates b/145301722

Change-Id: I98e00971fad95cc4d69b371d815de5f5498b04db
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/609591
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-03-27 16:46:50 -04:00
Julie Qiu 181627c7e5 internal/middleware: integrate experiments to frontend
An experiments middleware is added, which is used in the frontend
binary.

The experiments middleware periodically polls the provided experiments
source for information, and decides whether a given request should be
enrolled for every experiment in the set.

Updates b/146052411

Change-Id: I1ee75cb20fe1d6f5cca1a7ad0995e2147e9820f3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/620409
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-03-27 16:46:50 -04:00
Julie Qiu 6183b51f73 internal/{etl,fetch}: move FetchAndInsertVersion to internal/etl
FetchAndInsertVersion is moved back to the internal/etl, after it was
initally moved to internal/fetch in commit
4252193cf5471489b9cb2c4351427448ac422e26, because it is only used by
the internal/etl package.

Fixes b/146890756

Change-Id: I4945f07636dc8986ad80f36f916c2676f85e2ab7
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/627781
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:50 -04:00
Julie Qiu dbcd26b7e0 internal/fetch: move FetchVersion and FetchAndInsertVersion from etl
We currently import internal/etl into internal/proxydatasource,
because etl.FetchVersion is used by the proxydatasource.

These functions are moved into their own package fetch.

FetchAndInsertVersion may be moved back to internal/etl in a later CL,
since it is only used by the ETL. At the moment, all functionality for
FetchVersion is being tested by FetchAndInsertVersion.

Updates b/146890756

Change-Id: Icaaf1feeac3821c82a85f21e07085d65556328d5
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/626675
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:50 -04:00
Jonathan Amsterdam 193997f5c7 internal/{log,middleware}: add trace ID to context, use in logging
- The requestlog middleware gets the trace ID from the request and
  adds it to the request's context.

- The internal/log package retrieves the traceID and adds it to log
  messages. It also creates two logs instead of one, a "parent" log
  used in requestlog, and a "child" log used for all other logging.
  Together, these two changes will cause the Stackdriver log viewer to
  group all log messages for a request with the request start and end
  log messages.

- These changes require that all log functions take a context, so I
  plumbed one through everywhere. In a handful of cases it didn't seem
  worth doing the plumbing. I used context.TODO() for those so we can
  easily find and re-evalaute them.

Change-Id: I663588463520187d0549a8f802ba9cb44a893592
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/622940
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:50 -04:00
Julie Qiu 1ab926d464 internal: move Datasource from frontend to internal package
frontend.Datasource is moved into internal.Datasource, so that it
can be used in future CLs in the internal/middleware package.

Change-Id: Id4823b46f36f114fd02ee3b8ac78c1e6d24c0cc5
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/611020
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-03-27 16:46:49 -04:00
Jonathan Amsterdam d363a41af4 cmd/frontend: shorten timeout
Make the middleware timeout shorter, to distinguish it from
a possible nginx timeout.

Might help in understanding a repeat of 

Change-Id: Iee2628ef19c827586e42bd0accd247ac6c2246ec
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/608334
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
2020-03-27 16:46:49 -04:00
Julie Qiu 42beb7ca44 cmd,internal: add stackdriver profiler
Updates b/143470697

Change-Id: I5dbbe51c49416c4848005ef681fdc4d981035b8f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/608522
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-03-27 16:46:49 -04:00
Jonathan Amsterdam 723f3612d1 internal/postgres: replace Open with New(db)
The constructor for a postgres.DB takes a *database.DB
instead of a driver and connection string.

Change-Id: Ief58ce676946fd34cbcafc2b634a772663b6f932
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/604403
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:48 -04:00
Rob Findley 4e25618631 internal/frontend: add an autocompletion endpoint
Now that completion data is being populated by the ETL, we can use it to
provide a JSON API for search autocompletions at /autocomplete?q=query.

This API reads lexical completions from Redis, sorts according to a
scoring heuristic, and returns the results as a JSON array.

For testing purposes, the pathCompletions function is moved from the etl
package to the complete package, and exported.

Updates b/143370178

Change-Id: I61d75296399222fa9ebfe8aadc909bf048389a23
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/602064
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-03-27 16:46:48 -04:00
Rob Findley 9d2ae5274b internal/etl: add an action to populate completion indexes
We're going to compute auto-completions using redis sorted sets in the
'HA' redis instance (because we don't want them to be evicted by
caching). This data need not be very fresh, and so can be computed by
the ETL every so often, perhaps once a day.

This CL wires the HA redis instance into the ETL, and adds an action to
update these Redis sorted sets. Doing this takes 1-2 minutes and
consumes quite a lot of memory, so there are some optimizations used:
 + the underlying *sql.DB is used for streaming search documents, rather
   than a method on postgres.DB. There is explanation for this in the
   code, and additionally I don't think this is so bad as long as it is
   only done in the ETL.
 + Completions data is loaded into temporary Redis keys and then renamed
   to overwrite the keys that will be used by the frontend, in order to
   minimize disruption while the completion data is being updated.

Updates b/143370178

Change-Id: I48caf77eb26d8ea7b60c2e117481bfa98ef089ca
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/602062
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-03-27 16:46:48 -04:00
Jonathan Amsterdam 58456c72bf internal/frontend: handle latest-badge work on the server
Use server-side string replacement to determine what to show for the
latest-version badge, rather than client-side code that calls back to
the server.

Using the same technique as for script nonces, we embed placeholders
in the HTML, and a middleware layer replaces them with the correct
values. The HTML with placeholders is indefinitely cacheable,
yet we still serve a page whose body can change dynamically.

The replaced information is kept to a minimum: the latest version for
use in the "go to latest" link, and a CSS class. Both alternatives for
the badge are in the HTML, and the CSS class determines which one is
displayed.

An additional challenge we did not face with nonces: how to extract
information embedded on the page that we must use to determine the
placeholder values. In this case, that is the version being served,
the module path, and in the case of a package, the package path.  We
could find that information by parsing the HTML, but that is overkill,
and slow.

I first tried embedding the information in an HTML comment and
used a regexp to extract it, but surprisingly, HTML comments are
stripped out by html/template, and there is no easy workaround.  So I
added the information to the HTML as data-XXX attributes, but I still
extract them by regexp for speed. Since this data appears before any
user-provided text (like documentation or a README), and we find the
first match, there is no way for users to spoof it. But it is fragile,
as the comment in details.tmpl points out.

Now that the latest-version badge is done on the server, we can
add checks for it to TestServer, which I've done.

Fixes b/144098197.

Change-Id: I3a126f1cac48cd35c0317d47035bf227483cdbf1
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/599082
Reviewed-by: Alexander Rakoczy <rakoczy@google.com>
2020-03-27 16:46:48 -04:00
Jonathan Amsterdam 07ca1c6347 cmd/frontend: export go-discovery/quota/result_count metric
Change-Id: I017181c2391f748ffe35062c2b6624157881c8b7
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/598343
Reviewed-by: Julie Qiu <julieqiu@google.com>
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
2020-03-27 16:46:48 -04:00
Julie Qiu 8f7732c9ce cmd/prober: update check from "Go Discovery" to "go.dev"
Fixes b/144301072

Change-Id: I1929bf25877e543c111fc1276ff60b83d280a524
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/596762
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:47 -04:00
Rob Findley 200cf3c0e2 internal/middleware,etl: add error reporting middleware
A new middleware is added that sends an error report whenever the ETL
returns a 500 from a scheduled endpoint.

Along the way, refactor main() in cmd/etl to be more consistent about
resolving dependencies in helper functions.

Fixes b/142731446

Change-Id: Ib44cd40bf48a3c229220c8c571e52ee033047aa5
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/592534
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:47 -04:00
Rob Findley e639c37ff6 cmd/prober: add a view for probe count
Simply exporting the distribution is not enough: in order to alert on a
number or ratio of failed probes, we need to have a separate view that
aggregates by count.

Updates b/143915414

Change-Id: I73f7239d41a65a608d3afebb408c3f54b30a8af6
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/592544
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:47 -04:00
Rob Findley 3d3b12d222 metrics: remove redundant custom.googleapis.com
The stackdriver exporter prepends custom.googleapis.com/Opencensus to
metrics, which means the custom.googleapis.com I added was redundant.
..

All alert policies and dashboards will also have to be updated, which
I'll do in a later CL.

Updates b/142737661

Change-Id: I25a5035ad01add59d4b34bcd0a1851bd87a6c35e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/592541
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-03-27 16:46:47 -04:00
Julie Qiu 6befaf64c4 cmd/prober: fix /pkg endpoints
Change-Id: I9eea20c4006751a658e97c2fb12cffe24fe0a19e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/591809
Reviewed-by: Rebecca Stambler <rstambler@google.com>
2020-03-27 16:46:47 -04:00
Rob Findley 322865bcd1 middleware,frontend: add a panic middleware
Right now, if any of our frontend handlers panic the user will be served
a blank page. This CL adds a new middleware to recover from panics and
serve a provided panic handler.

This is then hooked into the frontend, using our default error page.

Fixes b/141254586

Change-Id: Ie45b0f5c83ff88fc5bec2ab7e174fa0ea2bd0253
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/589272
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:46 -04:00
Jonathan Amsterdam c40217ff76 internal/config: support overrides
Make it possible to reconfigure App Engine instances dynamically, without
redeploying them.

With this feature, some config settings can be changed just by copying
a file to GCS. Instances will get the new config when they restart.

- middleware/quota.go: move QuotaSettings to config to avoid circular import

- config.Init: read and decode the config overrides from a file in GCS

- Add the env var for the config override object to config/{dev,staging,prod}.yaml.

- Add sample files config/{dev,staging,prod}-override.yaml.

Change-Id: I9b13d02a5b50748b45172202c5261330b2f9f81d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/589173
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:46 -04:00
Rob Findley 0bb75a949a cmd/prober: add probes that bypass the cache
Now that we're caching, our probes are no longer exercising the
database. This CL configures several probes that bypass the cache.

Change-Id: Ia87239ab4ca34ace5f384880b45bd01a108bcf31
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/584257
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:46 -04:00
Jonathan Amsterdam 32ff85effe cmd/frontend: add quota middleware in record-only mode
Add the Quota middleware to the chain, but configure it only
to collect metrics about how many requests it would have blocked;
do not actually block anything.

Change-Id: I6ed6fbc1688fd35211e090507004cc5efb2fc90d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/583655
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:46 -04:00
Jonathan Amsterdam 7963793b75 internal/middleware: replace nonce placeholders in body
To make pages cacheable, we cannot embed the actual nonce value in the
cached body, because it must be different on each request. So we instead
generate the body with a placeholder, and substitute in the actual
nonce value when we serve it.

Change-Id: I3f8397fbc594ee9081b3426dc5b4048d3694053a
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/582017
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:46 -04:00
Jonathan Amsterdam db02ff8a15 etl: support a list of module versions removed by the proxy
Optionally read a file of module@version that were removed
by the proxy, but still in the index. Exclude these from
being fetched.

Change-Id: I26269e0aba29a09fa86fcac462b4ade0ee7947d0
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/580836
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:45 -04:00
Julie Qiu db7a23c216 internal/middleware: add a page-caching middleware
A page caching middleware is added that caches any 200 OK responses for
a configurable duration. It is instrumented with custom metrics.

For now, this isn't wired into the frontend, though the code to do so is
commented out. Tests will be added in a follow-up CL.

Updates 143163521

Change-Id: Id919d3e63e1b43f5905e7f20df475a3c69379e87
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/580776
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-03-27 16:46:45 -04:00
Rob Findley d901d01b12 internal/postgres: add a fast(er) search
A new method is added to postgres.DB, optimistically named 'FastSearch',
that implements search hedging. Each FastSearch concurrently queries
both all packages as well as popular subsets of packages, so that
results can be returned quicker when they consist entirely of popular
packages.

Additionallly SearchResult.Rank is renamed to 'Score', to differentiate
it from ts_rank.

The old 'Search' method is kept for now, although 'log' is corrected to
'ln' (this should have little effect on the ordering of results). In a
subsequent CL we will switch the default search method to FastSearch,
and implement the 'of many' qualifier in the search result summary.

Updates b/141182438

Change-Id: I73c6700e09288f3a8bfdb5fa57d0899606e452d2
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/558516
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-03-27 16:46:44 -04:00
Jonathan Amsterdam b33bb8a31a cmd/prober: check for duplicate probe names
Change-Id: I8fd171da814e313c57bfa5d0076cc1b79745cc34
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/556729
Reviewed-by: Julie Qiu <julieqiu@google.com>
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
2020-03-27 16:46:44 -04:00
Julie Qiu 2c280144b5 cmd/prober: add search, directory, readme, imports and static page endpoints
The following URLs are added to the prober:
* /pkg/cloud.google.com/go/firestore?tab=<tab> for readme and imports
* /search?q=github
* /pkg/golang.org/x/tools/go (directory page)
* /search-help
* /license-policy

Change-Id: I3f0836adbb46d68e8a82cfc5be95245ec5b46f87
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/558321
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-03-27 16:46:43 -04:00
Jonathan Amsterdam 78fe06e6e1 various: use internal/log package
Take advantage of log levels when logging DB queries: use
Debug, except for errors.

Change-Id: Icd99d1474799b89d2d8149e5f5bb6f417c6448b5
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/556725
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:43 -04:00
Jonathan Amsterdam 0bdd479bc1 internal/frontend: use new logger
Change-Id: I32c79a4280ad7a0bc1e12d02b6305f438b3d8810
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/556724
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:43 -04:00
Jonathan Amsterdam d787f45c48 internal/etl: convert to new logger
Use the new logger everywhere.

Also remove the Printf alias; it is easy enough to change all call sites.

Change-Id: I4f46c306e22f132cd505518a8d46b1a989f6bd1d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/556722
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27 16:46:43 -04:00
Jonathan Amsterdam 8017c52c28 internal/log: a logging package
It is intended as a drop-in replacement for the standard log
package, but also supports levels (just three for now)
and structured logging.

Also, converted etl/main.go as an example, to show usage.

If this is approved I'll convert everything else.

Change-Id: I8ee8855be05aafdd31cbf9b550aae76cb2240abe
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/556096
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-27 16:46:43 -04:00
Rob Findley ef1f08bb21 internal/dcensus: customize our http views
Our usage of opencensus views is updated so that we only export 'custom
metrics' to StackDriver that start with the custom.googleapis.com
prefix. Additionally views are updated to always contain the server
route tag or client host tag.

Fixes b/141183559

Change-Id: Ie17db025bd61a3cc1ea969d214947d09cdacf96a
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/553907
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-03-27 16:46:43 -04:00