Skip to content

Commit c85a8a6

Browse files
authored
Merge pull request #7 from cicirello/fix-query-delay
Increased default, and minimum, query delays
2 parents 31ee9e7 + e4ce97f commit c85a8a6

File tree

4 files changed

+60
-36
lines changed

4 files changed

+60
-36
lines changed

ActionUserCounter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ def commitAndPush(allFilenames, name, login, failOnError) :
240240
style = None
241241

242242
queryDelay = int(sys.argv[9].strip())
243-
if queryDelay < 10 :
244-
queryDelay = 10
243+
if queryDelay < 33 :
244+
queryDelay = 33
245245

246246
exitCode = 0
247247

CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased] - 2021-08-08
7+
## [Unreleased] - 2021-08-19
88

99
### Added
1010

1111
### Changed
12-
* Added cache directive to queries ("--cache 1h").
1312

1413
### Deprecated
1514

@@ -18,6 +17,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1817
### Fixed
1918

2019

20+
## [1.0.2] - 2021-08-19
21+
22+
### Fixed
23+
* Increased default `query-delay` to 65 seconds to minimize
24+
potential of hitting secondary rate limits for the use-case of
25+
monitoring multiple actions.
26+
* Increased minimum `query-delay` to 33 seconds to minimize
27+
potential of hitting secondary rate limits for the use-case of
28+
monitoring multiple actions.
29+
* Added cache directive to queries ("--cache 1h").
30+
31+
2132
## [1.0.1] - 2021-08-05
2233

2334
### Fixed

README.md

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ in most of our repositories._
3535

3636
__Here are a Few Example Badges__
3737
* Example with moderate number of users:
38-
![Count of Action Users](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fcicirello%2Fcount-action-users%2Fsamples%2Fendpoints%2Fjacoco-badge-generator.json)
38+
![Count of Action Users](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/cicirello/count-action-users/samples/endpoints/jacoco-badge-generator.json)
3939
* Example with very large number of users (`actions/setup-python`):
40-
![Count of Action Users](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fcicirello%2Fcount-action-users%2Fsamples%2Fendpoints%2Fsetup-python.json)
40+
![Count of Action Users](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/cicirello/count-action-users/samples/endpoints/setup-python.json)
4141
* Example with huge number of users (`actions/checkout`):
42-
![Count of Action Users](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fcicirello%2Fcount-action-users%2Fsamples%2Fendpoints%2Fcheckout.json)
42+
![Count of Action Users](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/cicirello/count-action-users/samples/endpoints/checkout.json)
4343

4444
## Table of Contents
4545

@@ -93,16 +93,15 @@ jobs:
9393
9494
You can then pass the URL of the endpoint to Shields to generate and
9595
insert a badge into your README with the following Markdown. Just be sure to
96-
replace `OWNERUSERID`, `REPOSITORY`, and `BRANCH` as appropriate, and also be sure
97-
to retain the various encodings of colons (`%3A`), and backslashes (`%2F`).
96+
replace `OWNERUSERID`, `REPOSITORY`, and `BRANCH` as appropriate.
9897

9998
```markdown
100-
![Count of Action Users](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FOWNERUSERID%2FREPOSITORY%2FBRANCH%2Faction-name.json)
99+
![Count of Action Users](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/OWNERUSERID/REPOSITORY/BRANCH/action-name.json)
101100
```
102101

103102
Note that in the above, you are relying on GitHub's `raw.githubusercontent.com`
104103
server for serving the endpoint to Shields. We do not actually recommend doing this
105-
as that server isn't really intended for that purpose, and may create a noticeable delay
104+
as that server isn't really intended for that purpose, and may create a delay
106105
that will trickle down to Shields serving the badge. However, you might initially
107106
set it up this way to try out the action.
108107
See [Example 2](#example-2-serving-via-github-pages-from-the-docs-directory)
@@ -207,11 +206,10 @@ then your endpoint will be accessible from
207206
`https://YOURUSERID.github.io/REPOSITORY/action-name.json`.
208207

209208
You can then use the following Markdown to insert the badge in your README.
210-
Just be sure to replace `YOURUSERID` and `REPOSITORY` as appropriate, and also be sure
211-
to retain the various encodings of colons (`%3A`), and backslashes (`%2F`).
209+
Just be sure to replace `YOURUSERID` and `REPOSITORY` as appropriate.
212210

213211
```markdown
214-
![Count of Action Users](https://img.shields.io/endpoint?url=https%3A%2F%2FYOURUSERID.github.io%2FREPOSITORY%2Faction-name.json)
212+
![Count of Action Users](https://img.shields.io/endpoint?url=https://YOURUSERID.github.io/REPOSITORY/action-name.json)
215213
```
216214

217215
If you are also utilizing GitHub Pages for a project site, then you might want
@@ -221,7 +219,7 @@ accomplish that with the following action input: `target-directory: docs/endpoin
221219
This would change the necessary Markdown for inserting the badge to:
222220

223221
```markdown
224-
![Count of Action Users](https://img.shields.io/endpoint?url=https%3A%2F%2FYOURUSERID.github.io%2FREPOSITORY%2Fendpoints%2Faction-name.json)
222+
![Count of Action Users](https://img.shields.io/endpoint?url=https://YOURUSERID.github.io/REPOSITORY/endpoints/action-name.json)
225223
```
226224

227225
See [later in this document](#how-to-link-the-badge-to-search-results) for an
@@ -278,19 +276,18 @@ As in the previous example, the JSON endpoint will be at
278276
the root of the project site
279277
(`https://YOURUSERID.github.io/REPOSITORY/action-name.json`). Thus, you can then use the
280278
following Markdown to insert the badge in your README.
281-
Just be sure to replace `YOURUSERID` and `REPOSITORY` as appropriate, and also be sure
282-
to retain the various encodings of colons (`%3A`), and backslashes (`%2F`).
279+
Just be sure to replace `YOURUSERID` and `REPOSITORY` as appropriate.
283280

284281
```markdown
285-
![Count of Action Users](https://img.shields.io/endpoint?url=https%3A%2F%2FYOURUSERID.github.io%2FREPOSITORY%2Faction-name.json)
282+
![Count of Action Users](https://img.shields.io/endpoint?url=https://YOURUSERID.github.io/REPOSITORY/action-name.json)
286283
```
287284

288285
If you'd rather have it in a subdirectory, you can set the appropriate action input,
289286
such as with: `target-directory: endpoints`. Doing so would then require
290287
the following Markdown for inserting the badge into the README:
291288

292289
```markdown
293-
![Count of Action Users](https://img.shields.io/endpoint?url=https%3A%2F%2FYOURUSERID.github.io%2FREPOSITORY%2Fendpoints%2Faction-name.json)
290+
![Count of Action Users](https://img.shields.io/endpoint?url=https://YOURUSERID.github.io/REPOSITORY/endpoints/action-name.json)
294291
```
295292

296293
See [later in this document](#how-to-link-the-badge-to-search-results) for an
@@ -346,7 +343,7 @@ release that you wish to use, such as with the following:
346343

347344
```yml
348345
- name: Generate user count JSON endpoint
349-
uses: cicirello/count-action-users@v1.0.1
346+
uses: cicirello/count-action-users@v1.0.2
350347
with:
351348
action-list: owner/action-name
352349
env:
@@ -368,25 +365,22 @@ you might consider linking it to a GitHub search results page. You can do that
368365
with the following Markdown. Replace "YOURUSERID" with the user id of the owner
369366
of the action, and replace "ACTIONNAME" with the name of the action. Also replace
370367
"RELEVANT_SHIELDS_URL" with the link that generates the badge from the endpoint
371-
(see the examples in the workflow examples above). Also be sure
372-
to retain the various encodings of colons (`%3A`), and backslashes (`%2F`).
368+
(see the examples in the workflow examples above).
373369

374370
```markdown
375-
[![Count of Action Users](RELEVANT_SHIELDS_URL)](https://github.com/search?q=YOURUSERID+ACTIONNAME+path%3A.github%2Fworkflows+language%3AYAML&type=Code)
371+
[![Count of Action Users](RELEVANT_SHIELDS_URL)](https://github.com/search?q=YOURUSERID+ACTIONNAME+path:.github/workflows+language:YAML&type=Code)
376372
```
377373

378374
## FAQ
379375

380376
__Why not instead submit a pull request to Shields to add direct support to their
381377
awesome project for an actions users count badge?__ The GitHub Code Search API, which
382378
we utilize for this action, has a rate limit of 30 queries per minute for an
383-
authenticated user; and can also potentially interact with other secondary rate limits.
379+
authenticated user; and can also potentially interact with other secondary rate limits,
380+
including some secondary limits that are not published.
384381
By running this as an action, the necessary queries benefit
385-
from the GITHUB_TOKEN of the user of this action, and in theory the rate limit should
386-
never come into effect unless you attempt to run
387-
it to generate endpoints for many actions within a single workflow run, or are
388-
otherwise querying the code search API (or other GitHub APIs) at the same time with
389-
another tool, or run into a secondary rate limit. I imagine the rate
382+
from the GITHUB_TOKEN of the user of this action, and in theory we can more easily
383+
stay within the rate limits. I imagine the rate
390384
limit would be significantly more challenging for a solution directly integrated with
391385
Shields. We additionally have a built-in time delay in between queries for those using
392386
the action to monitor multiple GitHub actions.
@@ -404,8 +398,9 @@ GitHub's [code search](https://docs.github.com/en/github/searching-for-informati
404398
for details of what code is (and is not) indexed by GitHub.
405399

406400
__Can't we further minimize false positives with "owner/action-name" as a single search
407-
term?__ Unfortunately, GitHub's code search drops various special characters from searches,
408-
including `/`, replacing them with spaces. Due to this, combining owner and the
401+
term?__ Unfortunately, GitHub's code search drops various special characters that are often
402+
used as wildcards from searches, including `/`, replacing them with
403+
spaces. Due to this, combining owner and the
409404
action's name into a single search
410405
term in this way is equivalent to the search we are currently doing.
411406

@@ -551,9 +546,27 @@ The author of the commit is set to the github-actions bot.
551546
This input specifies a delay, in seconds, in between queries for
552547
cases where multiple actions are being monitored. The purpose of this
553548
delay is to decrease chance of hitting API rate limits. The default is
554-
15 seconds. This input doesn't accept values less than 10. For example,
555-
if you attempt to pass 0 (or anything else less than 10), the minimum of
556-
10 will be used instead.
549+
65 seconds, which ensures that no more than one code search query is
550+
executed per minute. This input doesn't accept values less than 33. For example,
551+
if you attempt to pass 0 (or anything else less than 33), the minimum of
552+
33 will be used instead. That minimum ensures that at most two code search queries
553+
will be executed per minute.
554+
555+
Why is the default, and minimum, query delays so high? Although the rate limit
556+
is 30 code search queries per minute, there are other unpublished secondary rate
557+
limits. During our initial testing, we occasionally ran into such secondary limits
558+
when using a lower query delay that allowed for four queries in a
559+
minute, specifically on the fourth query. It is unclear what other activity
560+
was interacting to hit those secondary rate limits. The default, and minimum,
561+
query delays are designed to help you avoid rate limit effects.
562+
563+
Additionally, there is no reason for the action to collect usage statistics
564+
of the actions that you maintain more than once per day, so the length of the delay
565+
between queries shouldn't really matter much to you. The one case where it might is
566+
if you have reason to run this in a private repository, and thus the delay time
567+
will count against your actions minutes. In that case you can simply setup one workflow
568+
per action that you maintain (thus no delay will be inserted), and make sure
569+
you schedule them so that they are far enough apart in time.
557570

558571
## Outputs
559572

@@ -603,7 +616,7 @@ jobs:
603616
style: flat # Which is Shields's default as well
604617
fail-on-error: true
605618
commit-and-push: true
606-
query-delay: 15
619+
query-delay: 65
607620
env:
608621
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
609622

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ inputs:
6363
query-delay:
6464
description: 'Time delay in seconds between queries if monitoring multiple actions'
6565
required: false
66-
default: 15
66+
default: 65
6767
outputs:
6868
exit-code:
6969
description: '0 if successful or non-zero if unsuccessful'

0 commit comments

Comments
 (0)