Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #654 - Upgrade to go 1.22 #686

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/go-utils/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module jobanalyzer_go_utils

go 1.21.10
go 1.22.1

require go-utils v0.0.0-00010101000000-000000000000
replace go-utils => ../go-utils
2 changes: 1 addition & 1 deletion code/heatmap/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module heatmap

go 1.21.11
go 1.22.1
2 changes: 1 addition & 1 deletion code/jsoncheck/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module jsoncheck

go 1.21.10
go 1.22.1
2 changes: 1 addition & 1 deletion code/make-cluster-config/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module make-cluster-config

go 1.21.10
go 1.22.1

require go-utils v0.0.0-00010101000000-000000000000
replace go-utils => ../go-utils
2 changes: 1 addition & 1 deletion code/naicreport/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module naicreport

go 1.21.10
go 1.22.1

require go-utils v0.0.0-00010101000000-000000000000
replace go-utils => ../go-utils
2 changes: 1 addition & 1 deletion code/netsink/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module netsink

go 1.21.10
go 1.22.1

require go-utils v0.0.0-00010101000000-000000000000
replace go-utils => ../go-utils
2 changes: 1 addition & 1 deletion code/numdiff/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module numdiff

go 1.21.10
go 1.22.1
2 changes: 1 addition & 1 deletion code/sacctd/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module sacctd

go 1.21.11
go 1.22.1
2 changes: 1 addition & 1 deletion code/slurminfo/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module slurminfo

go 1.21.10
go 1.22.1

require go-utils v0.0.0-00010101000000-000000000000
replace go-utils => ../go-utils
3 changes: 1 addition & 2 deletions code/sonalyze/clusters/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ type SFS = SimpleFormatSpec

// MT: Constant after initialization; immutable
var clustersFormatters = DefineTableFromMap(
// TODO: Go 1.22, reflect.TypeFor[db.ClusterEntry]
reflect.TypeOf((*db.ClusterEntry)(nil)).Elem(),
reflect.TypeFor[db.ClusterEntry](),
map[string]any{
"Name": SFS{"Cluster name", "cluster"},
"Description": SFS{"Human-consumable cluster summary", "desc"},
Expand Down
46 changes: 14 additions & 32 deletions code/sonalyze/command/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,13 @@ func (val IntOrEmpty) String() string {
// Type representations of some of those, for when we need the types.

var (
// TODO: When we can adopt Go 1.22: valTy := reflect.TypeFor[TypeName]()
dummyDateTimeValue DateTimeValue
dateTimeValueTy = reflect.TypeOf(dummyDateTimeValue)

dummyDateTimeValueOrBlank DateTimeValueOrBlank
dateTimeValueOrBlankTy = reflect.TypeOf(dummyDateTimeValueOrBlank)

dummyIsoDateTimeOrUnknown IsoDateTimeOrUnknown
isoDateTimeOrUnknownTy = reflect.TypeOf(dummyIsoDateTimeOrUnknown)

dummyDurationValue DurationValue
durationValueTy = reflect.TypeOf(dummyDurationValue)

dummyUstrMax30Value UstrMax30
ustrMax30Ty = reflect.TypeOf(dummyUstrMax30Value)

dummyGpuSetValue gpuset.GpuSet
gpuSetTy = reflect.TypeOf(dummyGpuSetValue)

// See the Example for reflect.TypeOf in the Go documentation.
stringerTy = reflect.TypeOf((*fmt.Stringer)(nil)).Elem()
dateTimeValueTy = reflect.TypeFor[DateTimeValue]()
dateTimeValueOrBlankTy = reflect.TypeFor[DateTimeValueOrBlank]()
isoDateTimeOrUnknownTy = reflect.TypeFor[IsoDateTimeOrUnknown]()
durationValueTy = reflect.TypeFor[DurationValue]()
ustrMax30Ty = reflect.TypeFor[UstrMax30]()
gpuSetTy = reflect.TypeFor[gpuset.GpuSet]()
stringerTy = reflect.TypeFor[fmt.Stringer]()
)

// Given a struct type, DefineTableFromTags constructs a map from field names to a formatter for
Expand Down Expand Up @@ -278,9 +264,7 @@ func reflectStructFormatters(
panic("Struct type required")
}
for i, lim := 0, structTy.NumField(); i < lim; i++ {
// TODO: once we move to Go 1.22: no temp binding
ix := i
fld := structTy.Field(ix)
fld := structTy.Field(i)
if fld.Anonymous {
// Trace through embedded field. The formatting function will receive the outer
// structure (or pointer to it), but the formatter generator code operates on the inner
Expand All @@ -300,20 +284,18 @@ func reflectStructFormatters(
subFormatters := make(map[string]Formatter)
reflectStructFormatters(fldTy, subFormatters, admissible, synthesizable)
for name, fmt := range subFormatters {
// TODO: once we move to Go 1.22: no temp binding
theFmt := fmt.Fmt
f := Formatter{
Help: fmt.Help,
}
if mustTakeAddress {
f.Fmt = func(d any, mods PrintMods) string {
val := reflect.Indirect(reflect.ValueOf(d)).Field(ix).Addr()
return theFmt(val.Interface(), mods)
val := reflect.Indirect(reflect.ValueOf(d)).Field(i).Addr()
return fmt.Fmt(val.Interface(), mods)
}
} else {
f.Fmt = func(d any, mods PrintMods) string {
val := reflect.Indirect(reflect.ValueOf(d)).Field(ix)
return theFmt(val.Interface(), mods)
val := reflect.Indirect(reflect.ValueOf(d)).Field(i)
return fmt.Fmt(val.Interface(), mods)
}
}
formatters[name] = f
Expand All @@ -322,7 +304,7 @@ func reflectStructFormatters(
if ok, name, desc, aliases, attrs := admissible(fld); ok {
f := Formatter{
Help: desc,
Fmt: reflectTypeFormatter(ix, attrs, fld.Type),
Fmt: reflectTypeFormatter(i, attrs, fld.Type),
}
formatters[name] = f
for _, a := range aliases {
Expand All @@ -338,7 +320,7 @@ func reflectStructFormatters(
// we'll require synthesizable (or earlier code) to panic if that case occurs.
f := Formatter{
Help: desc,
Fmt: reflectTypeFormatter(ix, attrs, fld.Type),
Fmt: reflectTypeFormatter(i, attrs, fld.Type),
}
formatters[name] = f
}
Expand Down
3 changes: 1 addition & 2 deletions code/sonalyze/command/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ type SFS = SimpleFormatSpec
func TestFormatting3(t *testing.T) {
v1 := S2{x: 10, T2: T2{y: 20, U2: U2{z: 30}}}
fs := DefineTableFromMap(
// TODO: Go 1.22, reflect.TypeFor[S2]
reflect.TypeOf((*S2)(nil)).Elem(),
reflect.TypeFor[S2](),
map[string]any{
"x": SFS{"x field", "xx"},
"y": SFS{"y field", "yy"},
Expand Down
3 changes: 1 addition & 2 deletions code/sonalyze/configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ type SFS = SimpleFormatSpec

// MT: Constant after initialization; immutable
var configsFormatters = DefineTableFromMap(
// TODO: Go 1.22, reflect.TypeFor[config.NodeConfigRecord]
reflect.TypeOf((*config.NodeConfigRecord)(nil)).Elem(),
reflect.TypeFor[config.NodeConfigRecord](),
map[string]any{
"Timestamp": SFS{"Full ISO timestamp of when the reading was taken", "timestamp"},
"Hostname": SFS{"Name that host is known by on the cluster", "host"},
Expand Down
2 changes: 1 addition & 1 deletion code/sonalyze/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module sonalyze

go 1.21.10
go 1.22.1

require go-utils v0.0.0-00010101000000-000000000000
replace go-utils => ../go-utils
6 changes: 1 addition & 5 deletions code/sonalyze/load/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,4 @@ var loadAliases = map[string][]string{
}

// MT: Constant after initialization; immutable
var loadFormatters = DefineTableFromTags(
// TODO: Go 1.22, reflect.TypeFor[ReportRecord]
reflect.TypeOf((*ReportRecord)(nil)).Elem(),
nil,
)
var loadFormatters = DefineTableFromTags(reflect.TypeFor[ReportRecord](), nil)
6 changes: 1 addition & 5 deletions code/sonalyze/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,4 @@ var metadataAliases = map[string][]string{
}

// MT: Constant after initialization; immutable
var metadataFormatters = DefineTableFromTags(
// TODO: Go 1.22, reflect.TypeFor[metadataItem]
reflect.TypeOf((*metadataItem)(nil)).Elem(),
nil,
)
var metadataFormatters = DefineTableFromTags(reflect.TypeFor[metadataItem](), nil)
3 changes: 1 addition & 2 deletions code/sonalyze/nodes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ type SFS = SimpleFormatSpec

// MT: Constant after initialization; immutable
var nodesFormatters = DefineTableFromMap(
// TODO: Go 1.22, reflect.TypeFor[config.NodeConfigRecord]
reflect.TypeOf((*config.NodeConfigRecord)(nil)).Elem(),
reflect.TypeFor[config.NodeConfigRecord](),
map[string]any{
"Timestamp": SFS{"Full ISO timestamp of when the reading was taken", "timestamp"},
"Hostname": SFS{"Name that host is known by on the cluster", "host"},
Expand Down
17 changes: 15 additions & 2 deletions code/sonalyze/parse/parse.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package parse

import (
"cmp"
"errors"
"flag"
"fmt"
"io"
"reflect"
"sort"
"slices"
"strings"

"go-utils/config"
Expand Down Expand Up @@ -131,7 +132,19 @@ func (pc *ParseCommand) Perform(

if mergedSamples != nil {
// All elements that are part of the InputStreamKey must be part of the sort key here.
sort.Stable(sonarlog.HostTimeJobCmdSortableSampleStreams(mergedSamples))
slices.SortStableFunc(mergedSamples, func(a, b *sonarlog.SampleStream) int {
c := cmp.Compare((*a)[0].Host.String(), (*b)[0].Host.String())
if c == 0 {
c = cmp.Compare((*a)[0].Timestamp, (*b)[0].Timestamp)
if c == 0 {
c = cmp.Compare((*a)[0].Job, (*b)[0].Job)
if c == 0 {
c = cmp.Compare((*a)[0].Cmd.String(), (*b)[0].Cmd.String())
}
}
}
return c
})
for _, stream := range mergedSamples {
fmt.Fprintln(out, "*")
FormatData(
Expand Down
6 changes: 1 addition & 5 deletions code/sonalyze/profile/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,7 @@ var profileAliases = map[string][]string{
}

// MT: Constant after initialization; immutable
var profileFormatters = DefineTableFromTags(
// TODO: Go 1.22, reflect.TypeFor[fixedLine]
reflect.TypeOf((*fixedLine)(nil)).Elem(),
nil,
)
var profileFormatters = DefineTableFromTags(reflect.TypeFor[fixedLine](), nil)

func formatTime(t int64) string {
return FormatYyyyMmDdHhMmUtc(t)
Expand Down
6 changes: 1 addition & 5 deletions code/sonalyze/sacct/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,4 @@ var sacctAliases = map[string][]string{
}

// MT: Constant after initialization; immutable
var sacctFormatters = DefineTableFromTags(
// TODO: Go 1.22, reflect.TypeFor[SacctRegular]
reflect.TypeOf((*SacctRegular)(nil)).Elem(),
nil,
)
var sacctFormatters = DefineTableFromTags(reflect.TypeFor[SacctRegular](), nil)
7 changes: 5 additions & 2 deletions code/sonalyze/sonarlog/postprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
package sonarlog

import (
"cmp"
"errors"
"maps"
"slices"
"sort"
"strconv"
"strings"

"go-utils/config"

. "sonalyze/common"
"sonalyze/db"
)
Expand Down Expand Up @@ -136,7 +137,9 @@ func createInputStreams(
// same data file are kept in order, in corner cases (esp around roundtripping with `parse`)
// it's surprising if they are not in order.
for _, stream := range streams {
sort.Stable(TimeSortableSampleStream(*stream))
slices.SortStableFunc(*stream, func (a, b Sample) int {
return cmp.Compare(a.Timestamp, b.Timestamp)
})
}

// Remove duplicate timestamps. These may appear due to system effects, notably, sonar log
Expand Down
81 changes: 0 additions & 81 deletions code/sonalyze/sonarlog/sort.go

This file was deleted.

Loading
Loading