mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-28 08:39:56 +00:00
TUN-9016: update go to 1.24
## Summary Update several moving parts of cloudflared build system: * use goboring 1.24.2 in cfsetup * update linter and fix lint issues * update packages namely **quic-go and net** * install script for macos * update docker files to use go 1.24.1 * remove usage of cloudflare-go * pin golang linter Closes TUN-9016
This commit is contained in:
1
vendor/go.uber.org/automaxprocs/internal/cgroups/cgroup.go
generated
vendored
1
vendor/go.uber.org/automaxprocs/internal/cgroups/cgroup.go
generated
vendored
@@ -18,6 +18,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package cgroups
|
||||
|
5
vendor/go.uber.org/automaxprocs/internal/cgroups/cgroups.go
generated
vendored
5
vendor/go.uber.org/automaxprocs/internal/cgroups/cgroups.go
generated
vendored
@@ -18,6 +18,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package cgroups
|
||||
@@ -109,8 +110,8 @@ func (cg CGroups) CPUQuota() (float64, bool, error) {
|
||||
}
|
||||
|
||||
cfsPeriodUs, err := cpuCGroup.readInt(_cgroupCPUCFSPeriodUsParam)
|
||||
if err != nil {
|
||||
return -1, false, err
|
||||
if defined := cfsPeriodUs > 0; err != nil || !defined {
|
||||
return -1, defined, err
|
||||
}
|
||||
|
||||
return float64(cfsQuotaUs) / float64(cfsPeriodUs), true, nil
|
||||
|
176
vendor/go.uber.org/automaxprocs/internal/cgroups/cgroups2.go
generated
vendored
Normal file
176
vendor/go.uber.org/automaxprocs/internal/cgroups/cgroups2.go
generated
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
// Copyright (c) 2022 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package cgroups
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
// _cgroupv2CPUMax is the file name for the CGroup-V2 CPU max and period
|
||||
// parameter.
|
||||
_cgroupv2CPUMax = "cpu.max"
|
||||
// _cgroupFSType is the Linux CGroup-V2 file system type used in
|
||||
// `/proc/$PID/mountinfo`.
|
||||
_cgroupv2FSType = "cgroup2"
|
||||
|
||||
_cgroupv2MountPoint = "/sys/fs/cgroup"
|
||||
|
||||
_cgroupV2CPUMaxDefaultPeriod = 100000
|
||||
_cgroupV2CPUMaxQuotaMax = "max"
|
||||
)
|
||||
|
||||
const (
|
||||
_cgroupv2CPUMaxQuotaIndex = iota
|
||||
_cgroupv2CPUMaxPeriodIndex
|
||||
)
|
||||
|
||||
// ErrNotV2 indicates that the system is not using cgroups2.
|
||||
var ErrNotV2 = errors.New("not using cgroups2")
|
||||
|
||||
// CGroups2 provides access to cgroups data for systems using cgroups2.
|
||||
type CGroups2 struct {
|
||||
mountPoint string
|
||||
groupPath string
|
||||
cpuMaxFile string
|
||||
}
|
||||
|
||||
// NewCGroups2ForCurrentProcess builds a CGroups2 for the current process.
|
||||
//
|
||||
// This returns ErrNotV2 if the system is not using cgroups2.
|
||||
func NewCGroups2ForCurrentProcess() (*CGroups2, error) {
|
||||
return newCGroups2From(_procPathMountInfo, _procPathCGroup)
|
||||
}
|
||||
|
||||
func newCGroups2From(mountInfoPath, procPathCGroup string) (*CGroups2, error) {
|
||||
isV2, err := isCGroupV2(mountInfoPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !isV2 {
|
||||
return nil, ErrNotV2
|
||||
}
|
||||
|
||||
subsystems, err := parseCGroupSubsystems(procPathCGroup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Find v2 subsystem by looking for the `0` id
|
||||
var v2subsys *CGroupSubsys
|
||||
for _, subsys := range subsystems {
|
||||
if subsys.ID == 0 {
|
||||
v2subsys = subsys
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if v2subsys == nil {
|
||||
return nil, ErrNotV2
|
||||
}
|
||||
|
||||
return &CGroups2{
|
||||
mountPoint: _cgroupv2MountPoint,
|
||||
groupPath: v2subsys.Name,
|
||||
cpuMaxFile: _cgroupv2CPUMax,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func isCGroupV2(procPathMountInfo string) (bool, error) {
|
||||
var (
|
||||
isV2 bool
|
||||
newMountPoint = func(mp *MountPoint) error {
|
||||
isV2 = isV2 || (mp.FSType == _cgroupv2FSType && mp.MountPoint == _cgroupv2MountPoint)
|
||||
return nil
|
||||
}
|
||||
)
|
||||
|
||||
if err := parseMountInfo(procPathMountInfo, newMountPoint); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return isV2, nil
|
||||
}
|
||||
|
||||
// CPUQuota returns the CPU quota applied with the CPU cgroup2 controller.
|
||||
// It is a result of reading cpu quota and period from cpu.max file.
|
||||
// It will return `cpu.max / cpu.period`. If cpu.max is set to max, it returns
|
||||
// (-1, false, nil)
|
||||
func (cg *CGroups2) CPUQuota() (float64, bool, error) {
|
||||
cpuMaxParams, err := os.Open(path.Join(cg.mountPoint, cg.groupPath, cg.cpuMaxFile))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return -1, false, nil
|
||||
}
|
||||
return -1, false, err
|
||||
}
|
||||
defer cpuMaxParams.Close()
|
||||
|
||||
scanner := bufio.NewScanner(cpuMaxParams)
|
||||
if scanner.Scan() {
|
||||
fields := strings.Fields(scanner.Text())
|
||||
if len(fields) == 0 || len(fields) > 2 {
|
||||
return -1, false, fmt.Errorf("invalid format")
|
||||
}
|
||||
|
||||
if fields[_cgroupv2CPUMaxQuotaIndex] == _cgroupV2CPUMaxQuotaMax {
|
||||
return -1, false, nil
|
||||
}
|
||||
|
||||
max, err := strconv.Atoi(fields[_cgroupv2CPUMaxQuotaIndex])
|
||||
if err != nil {
|
||||
return -1, false, err
|
||||
}
|
||||
|
||||
var period int
|
||||
if len(fields) == 1 {
|
||||
period = _cgroupV2CPUMaxDefaultPeriod
|
||||
} else {
|
||||
period, err = strconv.Atoi(fields[_cgroupv2CPUMaxPeriodIndex])
|
||||
if err != nil {
|
||||
return -1, false, err
|
||||
}
|
||||
|
||||
if period == 0 {
|
||||
return -1, false, errors.New("zero value for period is not allowed")
|
||||
}
|
||||
}
|
||||
|
||||
return float64(max) / float64(period), true, nil
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return -1, false, err
|
||||
}
|
||||
|
||||
return 0, false, io.ErrUnexpectedEOF
|
||||
}
|
1
vendor/go.uber.org/automaxprocs/internal/cgroups/errors.go
generated
vendored
1
vendor/go.uber.org/automaxprocs/internal/cgroups/errors.go
generated
vendored
@@ -18,6 +18,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package cgroups
|
||||
|
5
vendor/go.uber.org/automaxprocs/internal/cgroups/mountpoint.go
generated
vendored
5
vendor/go.uber.org/automaxprocs/internal/cgroups/mountpoint.go
generated
vendored
@@ -18,6 +18,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package cgroups
|
||||
@@ -94,8 +95,12 @@ func NewMountPointFromLine(line string) (*MountPoint, error) {
|
||||
|
||||
for i, field := range fields[_miFieldIDOptionalFields:] {
|
||||
if field == _mountInfoOptionalFieldsSep {
|
||||
// End of optional fields.
|
||||
fsTypeStart := _miFieldIDOptionalFields + i + 1
|
||||
|
||||
// Now we know where the optional fields end, split the line again with a
|
||||
// limit to avoid issues with spaces in super options as present on WSL.
|
||||
fields = strings.SplitN(line, _mountInfoSep, fsTypeStart+_miFieldCountSecondHalf)
|
||||
if len(fields) != fsTypeStart+_miFieldCountSecondHalf {
|
||||
return nil, mountPointFormatInvalidError{line}
|
||||
}
|
||||
|
1
vendor/go.uber.org/automaxprocs/internal/cgroups/subsys.go
generated
vendored
1
vendor/go.uber.org/automaxprocs/internal/cgroups/subsys.go
generated
vendored
@@ -18,6 +18,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package cgroups
|
||||
|
36
vendor/go.uber.org/automaxprocs/internal/runtime/cpu_quota_linux.go
generated
vendored
36
vendor/go.uber.org/automaxprocs/internal/runtime/cpu_quota_linux.go
generated
vendored
@@ -18,20 +18,25 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"math"
|
||||
"errors"
|
||||
|
||||
cg "go.uber.org/automaxprocs/internal/cgroups"
|
||||
)
|
||||
|
||||
// CPUQuotaToGOMAXPROCS converts the CPU quota applied to the calling process
|
||||
// to a valid GOMAXPROCS value.
|
||||
func CPUQuotaToGOMAXPROCS(minValue int) (int, CPUQuotaStatus, error) {
|
||||
cgroups, err := cg.NewCGroupsForCurrentProcess()
|
||||
// to a valid GOMAXPROCS value. The quota is converted from float to int using round.
|
||||
// If round == nil, DefaultRoundFunc is used.
|
||||
func CPUQuotaToGOMAXPROCS(minValue int, round func(v float64) int) (int, CPUQuotaStatus, error) {
|
||||
if round == nil {
|
||||
round = DefaultRoundFunc
|
||||
}
|
||||
cgroups, err := _newQueryer()
|
||||
if err != nil {
|
||||
return -1, CPUQuotaUndefined, err
|
||||
}
|
||||
@@ -41,9 +46,30 @@ func CPUQuotaToGOMAXPROCS(minValue int) (int, CPUQuotaStatus, error) {
|
||||
return -1, CPUQuotaUndefined, err
|
||||
}
|
||||
|
||||
maxProcs := int(math.Floor(quota))
|
||||
maxProcs := round(quota)
|
||||
if minValue > 0 && maxProcs < minValue {
|
||||
return minValue, CPUQuotaMinUsed, nil
|
||||
}
|
||||
return maxProcs, CPUQuotaUsed, nil
|
||||
}
|
||||
|
||||
type queryer interface {
|
||||
CPUQuota() (float64, bool, error)
|
||||
}
|
||||
|
||||
var (
|
||||
_newCgroups2 = cg.NewCGroups2ForCurrentProcess
|
||||
_newCgroups = cg.NewCGroupsForCurrentProcess
|
||||
_newQueryer = newQueryer
|
||||
)
|
||||
|
||||
func newQueryer() (queryer, error) {
|
||||
cgroups, err := _newCgroups2()
|
||||
if err == nil {
|
||||
return cgroups, nil
|
||||
}
|
||||
if errors.Is(err, cg.ErrNotV2) {
|
||||
return _newCgroups()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
3
vendor/go.uber.org/automaxprocs/internal/runtime/cpu_quota_unsupported.go
generated
vendored
3
vendor/go.uber.org/automaxprocs/internal/runtime/cpu_quota_unsupported.go
generated
vendored
@@ -18,6 +18,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
//go:build !linux
|
||||
// +build !linux
|
||||
|
||||
package runtime
|
||||
@@ -25,6 +26,6 @@ package runtime
|
||||
// CPUQuotaToGOMAXPROCS converts the CPU quota applied to the calling process
|
||||
// to a valid GOMAXPROCS value. This is Linux-specific and not supported in the
|
||||
// current OS.
|
||||
func CPUQuotaToGOMAXPROCS(_ int) (int, CPUQuotaStatus, error) {
|
||||
func CPUQuotaToGOMAXPROCS(_ int, _ func(v float64) int) (int, CPUQuotaStatus, error) {
|
||||
return -1, CPUQuotaUndefined, nil
|
||||
}
|
||||
|
9
vendor/go.uber.org/automaxprocs/internal/runtime/runtime.go
generated
vendored
9
vendor/go.uber.org/automaxprocs/internal/runtime/runtime.go
generated
vendored
@@ -20,6 +20,8 @@
|
||||
|
||||
package runtime
|
||||
|
||||
import "math"
|
||||
|
||||
// CPUQuotaStatus presents the status of how CPU quota is used
|
||||
type CPUQuotaStatus int
|
||||
|
||||
@@ -28,6 +30,11 @@ const (
|
||||
CPUQuotaUndefined CPUQuotaStatus = iota
|
||||
// CPUQuotaUsed is returned when a valid CPU quota can be used
|
||||
CPUQuotaUsed
|
||||
// CPUQuotaMinUsed is return when CPU quota is smaller than the min value
|
||||
// CPUQuotaMinUsed is returned when CPU quota is smaller than the min value
|
||||
CPUQuotaMinUsed
|
||||
)
|
||||
|
||||
// DefaultRoundFunc is the default function to convert CPU quota from float to int. It rounds the value down (floor).
|
||||
func DefaultRoundFunc(v float64) int {
|
||||
return int(math.Floor(v))
|
||||
}
|
||||
|
Reference in New Issue
Block a user