Files
M AlveeandGitHub 47606f6238 distributed job framework (#557)
* feat: add DistJobType enum and sync distjob status types

Adds an iota-based DistJobType enum (mirrors the HealingDriveReason/
OfflineReason pattern already used in heal-commands.go) so distributed
job identity is a typed wire value instead of a bare string, per review
feedback on the eos distributed-job framework PR.

Also syncs DistJobLeaderStatus/DistJobNodeStatus field shapes to match
the current server-side JSON response (JobID/JobType replace JobName;
drops the unused Generation/AssignedSets/top-level CurrentBucket
fields that were never populated by the server).

* fix: bump vulnerable prometheus dep

- Add msgp generation (//msgp:tag json + //go:generate msgp) for
  DistJobLeaderStatus/DistJobNodeStatus, matching the pattern used by
  every other *-commands.go file in this package.
- Add unit tests for ListDistJobStatuses (success path, job-filter
  query param, DistJobTypeUnknown no-filter case, non-200 error path).
- Bump github.com/prometheus/prometheus v0.304.1 -> v0.312.0 to clear
  3 of the 4 govulncheck findings on this branch (GO-2026-5710,
  GO-2026-5381, GO-2026-5264, all fixed by that version). The 4th,
  GO-2026-5662, has no fix published upstream yet and also currently
  fails govulncheck on main independent of this branch.

* fix: pin go:generate directives to go.mod tool versions

Consolidate distjob-commands.go's separate //msgp:tag json directive
into the //go:generate msgp -d "tag json" flag, matching net-stats.go's
style (review feedback, PR #557).

Change every //go:generate msgp / //go:generate stringer directive
(31 occurrences, 30 files) to //go:generate go tool msgp / go tool
stringer, so generation always resolves the exact version pinned in
go.mod's tool block instead of whatever binary happens to be on PATH.
This was the root cause of the earlier stringer-drift CI failure.
Drop the now-unnecessary `go install -v tool` step from lint.yml.
2026-07-01 05:10:23 -04:00

146 lines
6.2 KiB
Go

// Copyright (c) 2015-2025 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package log
import (
"fmt"
"strings"
"time"
)
//msgp:tag json
//go:generate go tool msgp -d clearomitted -d "timezone utc" $GOFILE
//msgp:replace Origin with:string
// Origin for the API event
type Origin string
const (
OriginClient Origin = "client"
OriginSiteReplication Origin = "site-replication"
OriginILM Origin = "ilm"
OriginBatch Origin = "batch"
OriginRebalance Origin = "rebalance"
OriginReplicate Origin = "replicate"
OriginDecommission Origin = "decommission"
OriginHeal Origin = "heal"
)
type APIType string
const (
APITypeObject APIType = "object"
APITypeBucket APIType = "bucket"
APITypeAdmin APIType = "admin"
APITypeAuth APIType = "auth"
APITypeTable APIType = "table"
)
// API represents the api event
type API struct {
Version string `json:"version" parquet:"version"`
Time time.Time `json:"time" parquet:"time,timestamp(microsecond)"`
Node string `json:"node,omitempty" parquet:"node,optional"`
Origin Origin `json:"origin,omitempty" parquet:"origin,optional"`
Type APIType `json:"type,omitempty" parquet:"type,optional"`
Name string `json:"name,omitempty" parquet:"name,optional"`
Bucket string `json:"bucket,omitempty" parquet:"bucket,optional"`
Object string `json:"object,omitempty" parquet:"object,optional"`
VersionID string `json:"versionId,omitempty" parquet:"versionId,optional"`
Tags map[string]string `json:"tags,omitempty" parquet:"tags,optional"`
CallInfo *CallInfo `json:"callInfo,omitempty" parquet:"callInfo,optional"`
}
// CallInfo represents the info for the external call
type CallInfo struct {
HTTPStatusCode int `json:"httpStatusCode,omitempty" parquet:"httpStatusCode,optional"`
InputBytes int64 `json:"rx,omitempty" parquet:"inputBytes,optional"`
OutputBytes int64 `json:"tx,omitempty" parquet:"outputBytes,optional"`
HeaderBytes int64 `json:"txHeaders,omitempty" parquet:"headerBytes,optional"`
TimeToFirstByte string `json:"timeToFirstByte,omitempty" parquet:"timeToFirstByte,optional"`
RequestReadTime string `json:"requestReadTime,omitempty" parquet:"requestReadTime,optional"`
ResponseWriteTime string `json:"responseWriteTime,omitempty" parquet:"responseWriteTime,optional"`
RequestTime string `json:"requestTime,omitempty" parquet:"requestTime,optional"`
TimeToResponse string `json:"timeToResponse,omitempty" parquet:"timeToResponse,optional"`
ReadBlocked string `json:"readBlocked,omitempty" parquet:"readBlocked,optional"`
WriteBlocked string `json:"writeBlocked,omitempty" parquet:"writeBlocked,optional"`
SourceHost string `json:"sourceHost,omitempty" parquet:"sourceHost,optional"`
RequestID string `json:"requestID,omitempty" parquet:"requestId,optional"`
UserAgent string `json:"userAgent,omitempty" parquet:"userAgent,optional"`
ReqPath string `json:"requestPath,omitempty" parquet:"reqPath,optional"`
ReqHost string `json:"requestHost,omitempty" parquet:"reqHost,optional"`
ReqClaims map[string]string `json:"requestClaims,omitempty" parquet:"reqClaims,optional"`
ReqQuery map[string]string `json:"requestQuery,omitempty" parquet:"reqQuery,optional"`
ReqHeader map[string]string `json:"requestHeader,omitempty" parquet:"reqHeader,optional"`
RespHeader map[string]string `json:"responseHeader,omitempty" parquet:"respHeader,optional"`
AccessKey string `json:"accessKey,omitempty" parquet:"accessKey,optional"`
ParentUser string `json:"parentUser,omitempty" parquet:"parentUser,optional"`
}
// String provides a canonical representation for API
func (a API) String() string {
values := []string{
toString("version", a.Version),
toTime("time", a.Time),
toString("node", a.Node),
toString("origin", string(a.Origin)),
toString("type", string(a.Type)),
toString("name", a.Name),
toString("bucket", a.Bucket),
toString("object", a.Object),
toString("versionId", a.VersionID),
toMap("tags", a.Tags),
}
if a.CallInfo != nil {
values = append(values, fmt.Sprintf("callInfo={%s}", a.CallInfo.String()))
}
values = filterAndSort(values)
return strings.Join(values, ",")
}
// String returns the canonical string for CallInfo
func (c CallInfo) String() string {
values := []string{
toInt("httpStatusCode", c.HTTPStatusCode),
toInt64("rx", c.InputBytes),
toInt64("tx", c.OutputBytes),
toInt64("txHeaders", c.HeaderBytes),
toString("timeToFirstByte", c.TimeToFirstByte),
toString("requestReadTime", c.RequestReadTime),
toString("responseWriteTime", c.ResponseWriteTime),
toString("requestTime", c.RequestTime),
toString("timeToResponse", c.TimeToResponse),
toString("readBlocked", c.ReadBlocked),
toString("writeBlocked", c.WriteBlocked),
toString("sourceHost", c.SourceHost),
toString("requestID", c.RequestID),
toString("userAgent", c.UserAgent),
toString("requestPath", c.ReqPath),
toString("requestHost", c.ReqHost),
toMap("requestClaims", c.ReqClaims),
toMap("requestQuery", c.ReqQuery),
toMap("requestHeader", c.ReqHeader),
toMap("responseHeader", c.RespHeader),
toString("accessKey", c.AccessKey),
toString("parentUser", c.ParentUser),
}
values = filterAndSort(values)
return strings.Join(values, ",")
}