Skip to content

Commit 6db25d8

Browse files
committed
Merge branch 'version/0-36-0-RC1'
# Conflicts: # internal/runbits/requirements/requirements.go
2 parents 3c95cd0 + d18942f commit 6db25d8

File tree

631 files changed

+14529
-165292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

631 files changed

+14529
-165292
lines changed

activestate.generators.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ scripts:
8888
language: bash
8989
description: Generates graph server and client files
9090
value: |
91-
type gqlgen &>/dev/null || go install github.com/99designs/gqlgen@v0.13.0
92-
cd ./cmd/state-svc && gqlgen
91+
go install github.com/99designs/gqlgen@v0.17.24
92+
cd ./cmd/state-svc && gqlgen --verbose
9393
- name: generate-test-update
9494
language: bash
9595
standalone: true

changelog.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,65 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres
77
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
### 0.36.0
10+
11+
### Added
12+
13+
- All commands have been updated to proactively mention project and runtime
14+
information, making it easier to understand what is going on and how to configure
15+
your tooling.
16+
- State Tool will now give you a heads-up if the organization you're accessing
17+
has gone over its runtime limit.
18+
- State Tool will now configure itself for all supported shells on your system,
19+
rather than just the currently active shell.
20+
- Better support for Bash on Windows.
21+
22+
### Changed
23+
24+
- Significantly improved the performance of runtime executors.
25+
- `state revert` now reverts "a" commit, rather than reverting "to" a commit. This
26+
is meant to bring the user-experience in line with that of git.
27+
- Bash on macOS is no longer supported as a shell. This is due to the fact that
28+
macOS has deprecated the use of bash in favor of zsh. Using bash should still
29+
work, but you will receive warnings, and it may stop working in the future.
30+
- The state-svc is now installed as an App on macOS. Solving the issue of macOS
31+
referring to it as an sh script which isn't very useful for end-users.
32+
- Progress indication for runtime installations will now show build progress for
33+
all artifacts, even if they are cached.
34+
- Reorganized the `--help` output.
35+
36+
### Fixed
37+
38+
- Fixed error message received when running State Tool without the `HOME` env var
39+
not being indicative of that root cause.
40+
- Fixed progress count being off when installing runtimes.
41+
- Fixed progress sometimes hangs or panics while installing runtimes.
42+
- Fixed `state languages install` and `state platforms add` should not modify the
43+
remote project (that's what `state push` is for).
44+
- Fixed `state import` panics when ran outside of a project folder.
45+
- Fixed malformed error message when `state clean uninstall` fails.
46+
- Fixed `state push` creating the remote project even if the user told it not to.
47+
- Fixed unstable subcommands not showing a warning explaining that they are unstable.
48+
- Fixed `state shell` giving a misleading error when no default project is configured.
49+
- Fixed `state update` showing redundant output.
50+
- Fixed `state import --non-interactive` cancelling out of import rather than
51+
continuing without prompting.
52+
- Fixed `state revert <commit ID>` should not work on a commit that doesn't exist in
53+
the history.
54+
- Fixed `state clean cache` not giving a success or abort messaging.
55+
- Fixed `state export private-key` giving an uninformative error message when
56+
improperly authenticated.
57+
- Fixed `state show` not working with commits that haven't been pushed to the platform.
58+
59+
### Removed
60+
61+
- Removed the `--set-version` flag from `state update`. Instead, you can run the
62+
installation script with the `-v` flag.
63+
- The experimental tray tool (ActiveState Desktop) has been removed. It will be
64+
making a reappearance in the future.
65+
- The `--namespace` flag has been removed from `state history`. To inspect projects
66+
without checking them out you can use the website.
67+
968
### 0.35.0
1069

1170
We are introducing a set of new environment management commands that will

cmd/state-svc/internal/resolver/resolver.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package resolver
22

33
import (
44
"encoding/json"
5+
"github.com/ActiveState/cli/cmd/state-svc/internal/rtusage"
56
"sort"
67
"time"
78

@@ -30,6 +31,8 @@ type Resolver struct {
3031
cfg *config.Instance
3132
depPoller *poller.Poller
3233
updatePoller *poller.Poller
34+
authPoller *poller.Poller
35+
usageChecker *rtusage.Checker
3336
projectIDCache *projectcache.ID
3437
an *sync.Client
3538
anForClient *sync.Client // Use separate client for events sent through service so we don't contaminate one with the other
@@ -49,11 +52,22 @@ func New(cfg *config.Instance, an *sync.Client, auth *authentication.Auth) (*Res
4952
return upchecker.Check()
5053
})
5154

55+
pollAuth := poller.New(1*time.Minute, func() (interface{}, error) {
56+
if auth.SyncRequired() {
57+
return nil, auth.Sync()
58+
}
59+
return nil, nil
60+
})
61+
62+
usageChecker := rtusage.NewChecker(cfg, auth)
63+
5264
anForClient := sync.New(cfg, auth)
5365
return &Resolver{
5466
cfg,
5567
pollDep,
5668
pollUpdate,
69+
pollAuth,
70+
usageChecker,
5771
projectcache.NewID(),
5872
an,
5973
anForClient,
@@ -64,6 +78,7 @@ func New(cfg *config.Instance, an *sync.Client, auth *authentication.Auth) (*Res
6478
func (r *Resolver) Close() error {
6579
r.depPoller.Close()
6680
r.updatePoller.Close()
81+
r.authPoller.Close()
6782
r.anForClient.Close()
6883
return r.rtwatch.Close()
6984
}
@@ -158,16 +173,34 @@ func (r *Resolver) AnalyticsEvent(_ context.Context, category, action string, _l
158173
return &graph.AnalyticsEventResponse{Sent: true}, nil
159174
}
160175

161-
func (r *Resolver) RuntimeUsage(ctx context.Context, pid int, exec string, dimensionsJSON string) (*graph.RuntimeUsageResponse, error) {
176+
func (r *Resolver) ReportRuntimeUsage(_ context.Context, pid int, exec string, dimensionsJSON string) (*graph.ReportRuntimeUsageResponse, error) {
162177
logging.Debug("Runtime usage resolver: %d - %s", pid, exec)
163178
var dims *dimensions.Values
164179
if err := json.Unmarshal([]byte(dimensionsJSON), &dims); err != nil {
165-
return &graph.RuntimeUsageResponse{Received: false}, errs.Wrap(err, "Could not unmarshal")
180+
return &graph.ReportRuntimeUsageResponse{Received: false}, errs.Wrap(err, "Could not unmarshal")
166181
}
167182

168183
r.rtwatch.Watch(pid, exec, dims)
169184

170-
return &graph.RuntimeUsageResponse{Received: true}, nil
185+
return &graph.ReportRuntimeUsageResponse{Received: true}, nil
186+
}
187+
188+
func (r *Resolver) CheckRuntimeUsage(_ context.Context, organizationName string) (*graph.CheckRuntimeUsageResponse, error) {
189+
logging.Debug("CheckRuntimeUsage resolver")
190+
191+
usage, err := r.usageChecker.Check(organizationName)
192+
if err != nil {
193+
return nil, errs.Wrap(err, "Could not check runtime usage: %s", errs.JoinMessage(err))
194+
}
195+
196+
result := &graph.CheckRuntimeUsageResponse{
197+
Limit: int(usage.LimitDynamicRuntimes),
198+
Usage: int(usage.ActiveDynamicRuntimes),
199+
}
200+
201+
logging.Debug("Returning %v, based on %v", result, usage)
202+
203+
return result, nil
171204
}
172205

173206
func (r *Resolver) CheckDeprecation(ctx context.Context) (*graph.DeprecationInfo, error) {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package rtusage
2+
3+
import (
4+
"time"
5+
6+
"github.com/patrickmn/go-cache"
7+
8+
"github.com/ActiveState/cli/internal/errs"
9+
"github.com/ActiveState/cli/internal/logging"
10+
"github.com/ActiveState/cli/pkg/platform/api/graphql"
11+
"github.com/ActiveState/cli/pkg/platform/api/graphql/model"
12+
"github.com/ActiveState/cli/pkg/platform/api/graphql/request"
13+
"github.com/ActiveState/cli/pkg/platform/authentication"
14+
)
15+
16+
const cacheKey = "runtime-usage-"
17+
18+
// Checker is the struct that we use to do checks with
19+
type Checker struct {
20+
config configurable
21+
cache *cache.Cache
22+
auth *authentication.Auth
23+
}
24+
25+
// configurable defines the configuration function used by the functions in this package
26+
type configurable interface {
27+
ConfigPath() string
28+
GetTime(key string) time.Time
29+
Set(key string, value interface{}) error
30+
Close() error
31+
}
32+
33+
// NewChecker returns a new instance of the Checker struct
34+
func NewChecker(configuration configurable, auth *authentication.Auth) *Checker {
35+
checker := &Checker{
36+
configuration,
37+
cache.New(1*time.Hour, 1*time.Hour),
38+
auth,
39+
}
40+
41+
return checker
42+
}
43+
44+
// Check will check the runtime usage for the given organization, it may return a cached result
45+
func (c *Checker) Check(organizationName string) (*model.RuntimeUsage, error) {
46+
if !c.auth.Authenticated() {
47+
// Usage information can only be given to authenticated users, and the API doesn't support authentication errors
48+
// so we just don't even attempt it if not authenticated.
49+
return nil, nil
50+
}
51+
52+
if cached, ok := c.cache.Get(cacheKey + organizationName); ok {
53+
return cached.(*model.RuntimeUsage), nil
54+
}
55+
56+
client := graphql.New()
57+
58+
orgsResponse := model.Organizations{}
59+
if err := client.Run(request.OrganizationsByName(organizationName), &orgsResponse); err != nil {
60+
return nil, errs.Wrap(err, "Could not fetch organization: %s", organizationName)
61+
}
62+
if len(orgsResponse.Organizations) == 0 {
63+
return nil, errs.New("Could not find organization: %s", organizationName)
64+
}
65+
org := orgsResponse.Organizations[0]
66+
67+
usageResponse := model.RuntimeUsageResponse{}
68+
if err := client.Run(request.RuntimeUsage(org.ID), &usageResponse); err != nil {
69+
return nil, errs.Wrap(err, "Could not fetch runtime usage information")
70+
}
71+
72+
if len(usageResponse.Usage) == 0 {
73+
logging.Debug("No runtime usage information found for organization: %s", organizationName)
74+
return nil, nil
75+
}
76+
77+
c.cache.Set(cacheKey+organizationName, &usageResponse.Usage[0], 0)
78+
79+
return &usageResponse.Usage[0], nil
80+
}

0 commit comments

Comments
 (0)