Skip to content

Commit

Permalink
Merge branch 'master' into edit-config
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jul 23, 2021
2 parents bb7c177 + 600edd2 commit f9c46ba
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 24 deletions.
39 changes: 39 additions & 0 deletions components/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/tiup/components/playground/instance"
"github.com/pingcap/tiup/pkg/cluster/api"
"github.com/pingcap/tiup/pkg/cluster/spec"
"github.com/pingcap/tiup/pkg/environment"
"github.com/pingcap/tiup/pkg/localdata"
"github.com/pingcap/tiup/pkg/logger/log"
Expand All @@ -47,6 +48,7 @@ import (
"github.com/spf13/pflag"
clientv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/zap"
"golang.org/x/mod/semver"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -233,6 +235,43 @@ Examples:
}
}()

// expand version string
if !semver.IsValid(options.Version) {
var version utils.Version
var err error
// If any of the binpath arguments is set (which indicates the user is
// using a self build binary) and version number is not set, we assume
// it is a developer and use the latest release version by default.
// The platform string used to resolve the full version number is set
// to "linux-amd64" as this is the platform that every released version
// is available.
// For platforms lacks of support for some versions, e.g., darwin-amd64,
// specifically set a valid version for it, or use custom binpath for
// all components used.
// If none of the binpath arguments is set, use the platform of the
// playground binary itself.
if options.TiDB.BinPath != "" || options.TiKV.BinPath != "" ||
options.PD.BinPath != "" || options.TiFlash.BinPath != "" ||
options.TiCDC.BinPath != "" || options.Pump.BinPath != "" ||
options.Drainer.BinPath != "" && options.Version == "" {
version, err = env.V1Repository().ResolveComponentVersionWithPlatform(spec.ComponentTiDB, options.Version, "linux-amd64")
} else {
version, err = env.V1Repository().ResolveComponentVersion(spec.ComponentTiDB, options.Version)
}
if err != nil {
return errors.Annotate(err, fmt.Sprintf("can not expand version %s to a valid semver string", options.Version))
}
fmt.Println(color.YellowString(`Using the version %s for version constraint "%s".
If you'd like to use a TiDB version other than %s, cancel and retry with the following arguments:
Specify version manually: tiup playground <version>
Specify version range: tiup playground ^5
The nightly version: tiup playground nightly
`, version, options.Version, version))

options.Version = version.String()
}

bootErr := p.bootCluster(ctx, env, options)
if bootErr != nil {
// always kill all process started and wait before quit.
Expand Down
16 changes: 0 additions & 16 deletions components/playground/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,22 +678,6 @@ func (p *Playground) bootCluster(ctx context.Context, env *environment.Environme
return fmt.Errorf("all components count must be great than 0 (tikv=%v, pd=%v)", options.TiKV.Num, options.PD.Num)
}

{
version, err := env.V1Repository().ResolveComponentVersion(spec.ComponentTiDB, options.Version)
if err != nil {
return err
}
fmt.Println(color.YellowString(`Using the version %s for version constraint "%s".
If you'd like to use a TiDB version other than %s, cancel and retry with the following arguments:
Specify version manually: tiup playground <version>
Specify version range: tiup playground ^5
The nightly version: tiup playground nightly
`, version, options.Version, version))

options.Version = version.String()
}

if !utils.Version(options.Version).IsNightly() {
if semver.Compare(options.Version, "v3.1.0") < 0 && options.TiFlash.Num != 0 {
fmt.Println(color.YellowString("Warning: current version %s doesn't support TiFlash", options.Version))
Expand Down
4 changes: 4 additions & 0 deletions embed/templates/config/grafana.ini.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ admin_password = {{.Password}}
# Default UI theme ("dark" or "light")
;default_theme = dark

############### Set Cookie Name for Multiple Instances #######################
[auth]
login_cookie_name = grafana_session_{{ if .Domain }}{{.Domain}}_{{ end }}{{.Port}}

#################################### Anonymous Auth ##########################
[auth.anonymous]
{{- if .AnonymousEnable}}
Expand Down
21 changes: 13 additions & 8 deletions pkg/repository/v1_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,8 @@ func (r *V1Repository) ComponentVersion(id, ver string, includeYanked bool) (*v1
return vi, nil
}

// ResolveComponentVersion resolves the latest version of a component that satisfies the constraint
func (r *V1Repository) ResolveComponentVersion(id, constraint string) (utils.Version, error) {
// ResolveComponentVersionWithPlatform resolves the latest version of a component that satisfies the constraint
func (r *V1Repository) ResolveComponentVersionWithPlatform(id, constraint, platform string) (utils.Version, error) {
manifest, err := r.FetchComponentManifest(id, false)
if err != nil {
return "", err
Expand All @@ -765,16 +765,16 @@ func (r *V1Repository) ResolveComponentVersion(id, constraint string) (utils.Ver
}
ver = v.String()
case utils.NightlyVersionAlias:
if !manifest.HasNightly(r.PlatformString()) {
return "", errors.Annotatef(ErrUnknownVersion, "component %s does not have nightly on %s", id, r.PlatformString())
if !manifest.HasNightly(platform) {
return "", errors.Annotatef(ErrUnknownVersion, "component %s does not have nightly on %s", id, platform)
}
ver = manifest.Nightly
default:
cons, err := utils.NewConstraint(constraint)
if err != nil {
return "", err
}
versions := manifest.VersionList(r.PlatformString())
versions := manifest.VersionList(platform)
verList := make([]string, 0, len(versions))
for v := range versions {
if v == manifest.Nightly {
Expand All @@ -793,15 +793,20 @@ func (r *V1Repository) ResolveComponentVersion(id, constraint string) (utils.Ver
}
}
if ver == "" {
return "", fmt.Errorf(`no version on %s for component %s satisfies constraint "%s"`, r.PlatformString(), id, constraint)
return "", fmt.Errorf(`no version on %s for component %s satisfies constraint "%s"`, platform, id, constraint)
}
vi := manifest.VersionItem(r.PlatformString(), ver, false)
vi := manifest.VersionItem(platform, ver, false)
if vi == nil {
return "", errors.Annotatef(ErrUnknownVersion, "version %s on %s for component %s not found", ver, r.PlatformString(), id)
return "", errors.Annotatef(ErrUnknownVersion, "version %s on %s for component %s not found", ver, platform, id)
}
return utils.Version(ver), nil
}

// ResolveComponentVersion resolves the latest version of a component that satisfies the constraint
func (r *V1Repository) ResolveComponentVersion(id, constraint string) (utils.Version, error) {
return r.ResolveComponentVersionWithPlatform(id, constraint, r.PlatformString())
}

// LatestNightlyVersion returns the latest nightly version of specific component
func (r *V1Repository) LatestNightlyVersion(id string) (utils.Version, *v1manifest.VersionItem, error) {
com, err := r.FetchComponentManifest(id, false)
Expand Down

0 comments on commit f9c46ba

Please sign in to comment.