Skip to content

Commit

Permalink
[backward compatibility] v3.22 and prior; bump CLI version
Browse files Browse the repository at this point in the history
* keep v3.22 control structures
  - denote all of them - attach "v322" or "V322" suffix
* REST APIs: node and cluster stats; node and cluster status
* refactor `api` pkg - extract stats.go
* remove redundant code; simplify

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Mar 24, 2024
1 parent bcd7dca commit 85e15b9
Show file tree
Hide file tree
Showing 29 changed files with 324 additions and 212 deletions.
50 changes: 50 additions & 0 deletions ais/htrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/archive"
"github.com/NVIDIA/aistore/cmn/atomic"
Expand Down Expand Up @@ -1045,15 +1046,64 @@ func (h *htrun) httpdaeget(w http.ResponseWriter, r *http.Request, query url.Val
statsNode := h.statsT.GetStats()
statsNode.Snode = h.si
body = statsNode
case apc.WhatNodeStatsV322:
statsNode := h.statsT.GetStatsV322()
statsNode.Snode = h.si
body = statsNode
case apc.WhatMetricNames:
body = h.statsT.GetMetricNames()
case apc.WhatNodeStatsAndStatus:
ds := h.statsAndStatus()
daeStats := h.statsT.GetStats()
ds.Tracker = daeStats.Tracker
body = ds
case apc.WhatNodeStatsAndStatusV322:
ds := h.statsAndStatusV322()
daeStats := h.statsT.GetStatsV322()
ds.Tracker = daeStats.Tracker
body = ds
default:
h.writeErrf(w, r, "invalid GET /daemon request: unrecognized what=%s", what)
return
}
h.writeJSON(w, r, body, "httpdaeget-"+what)
}

func (h *htrun) statsAndStatus() (ds *stats.NodeStatus) {
smap := h.owner.smap.get()
ds = &stats.NodeStatus{
Node: stats.Node{
Snode: h.si,
},
SmapVersion: smap.Version,
MemCPUInfo: apc.GetMemCPU(),
DeploymentType: deploymentType(),
Version: daemon.version,
BuildTime: daemon.buildTime,
K8sPodName: os.Getenv(env.AIS.K8sPod),
Status: h._status(smap),
}
return ds
}

// [backward compatibility] v3.22 and prior
func (h *htrun) statsAndStatusV322() (ds *stats.NodeStatusV322) {
smap := h.owner.smap.get()
ds = &stats.NodeStatusV322{
NodeV322: stats.NodeV322{
Snode: h.si,
},
SmapVersion: smap.Version,
MemCPUInfo: apc.GetMemCPU(),
DeploymentType: deploymentType(),
Version: daemon.version,
BuildTime: daemon.buildTime,
K8sPodName: os.Getenv(env.AIS.K8sPod),
Status: h._status(smap),
}
return ds
}

func (h *htrun) sendAllLogs(w http.ResponseWriter, r *http.Request, query url.Values) string {
sev := query.Get(apc.QparamLogSev)
tempdir, archname, err := h.targzLogs(sev)
Expand Down
22 changes: 2 additions & 20 deletions ais/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"time"

"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/archive"
"github.com/NVIDIA/aistore/cmn/atomic"
Expand Down Expand Up @@ -2450,7 +2449,8 @@ func (p *proxy) httpdaeget(w http.ResponseWriter, r *http.Request) {
}
fallthrough // fallthrough
case apc.WhatNodeConfig, apc.WhatSmapVote, apc.WhatSnode, apc.WhatLog,
apc.WhatNodeStats, apc.WhatMetricNames:
apc.WhatNodeStats, apc.WhatNodeStatsV322, apc.WhatMetricNames,
apc.WhatNodeStatsAndStatus, apc.WhatNodeStatsAndStatusV322:
p.htrun.httpdaeget(w, r, query, nil /*htext*/)
case apc.WhatSysInfo:
p.writeJSON(w, r, apc.GetMemCPU(), what)
Expand Down Expand Up @@ -2478,24 +2478,6 @@ func (p *proxy) httpdaeget(w http.ResponseWriter, r *http.Request) {
return
}
p.writeJSON(w, r, smap, what)
case apc.WhatNodeStatsAndStatus:
smap := p.owner.smap.get()
msg := &stats.NodeStatus{
Node: stats.Node{
Snode: p.htrun.si,
},
SmapVersion: smap.Version,
MemCPUInfo: apc.GetMemCPU(),
DeploymentType: deploymentType(),
Version: daemon.version,
BuildTime: daemon.buildTime,
K8sPodName: os.Getenv(env.AIS.K8sPod),
Status: p._status(smap),
}
daeStats := p.statsT.GetStats()
msg.Tracker = daeStats.Tracker

p.writeJSON(w, r, msg, what)
default:
p.htrun.httpdaeget(w, r, query, nil /*htext*/)
}
Expand Down
2 changes: 1 addition & 1 deletion ais/prxclu.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (p *proxy) httpcluget(w http.ResponseWriter, r *http.Request) {
p.xquery(w, r, what, query)
case apc.WhatAllRunningXacts:
p.xgetRunning(w, r, what, query)
case apc.WhatNodeStats:
case apc.WhatNodeStats, apc.WhatNodeStatsV322:
p.qcluStats(w, r, what, query)
case apc.WhatSysInfo:
p.qcluSysinfo(w, r, what, query)
Expand Down
62 changes: 34 additions & 28 deletions ais/tgtcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"path/filepath"
"strconv"
"sync"
"time"

"github.com/NVIDIA/aistore/ais/backend"
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/cmn/debug"
Expand All @@ -32,7 +30,6 @@ import (
"github.com/NVIDIA/aistore/nl"
"github.com/NVIDIA/aistore/reb"
"github.com/NVIDIA/aistore/res"
"github.com/NVIDIA/aistore/stats"
"github.com/NVIDIA/aistore/xact"
"github.com/NVIDIA/aistore/xact/xreg"
jsoniter "github.com/json-iterator/go"
Expand Down Expand Up @@ -287,40 +284,40 @@ func (t *target) httpdaeget(w http.ResponseWriter, r *http.Request) {
)
switch getWhat {
case apc.WhatNodeConfig, apc.WhatSmap, apc.WhatBMD, apc.WhatSmapVote,
apc.WhatSnode, apc.WhatLog, apc.WhatNodeStats, apc.WhatMetricNames:
apc.WhatSnode, apc.WhatLog, apc.WhatMetricNames:
t.htrun.httpdaeget(w, r, query, t /*htext*/)
case apc.WhatSysInfo:
tsysinfo := apc.TSysInfo{MemCPUInfo: apc.GetMemCPU(), CapacityInfo: fs.CapStatusGetWhat()}
t.writeJSON(w, r, tsysinfo, httpdaeWhat)
case apc.WhatMountpaths:
t.writeJSON(w, r, fs.MountpathsToLists(), httpdaeWhat)

case apc.WhatNodeStats:
ds := t.statsAndStatus()
daeStats := t.statsT.GetStats()
ds.Tracker = daeStats.Tracker
t.writeJSON(w, r, ds, httpdaeWhat)
case apc.WhatNodeStatsV322: // [backward compatibility] v3.22 and prior
ds := t.statsAndStatusV322()
daeStats := t.statsT.GetStatsV322()
ds.Tracker = daeStats.Tracker
t.writeJSON(w, r, ds, httpdaeWhat)
case apc.WhatNodeStatsAndStatus:
var rebSnap *core.Snap
if entry := xreg.GetLatest(xreg.Flt{Kind: apc.ActRebalance}); entry != nil {
if xctn := entry.Get(); xctn != nil {
rebSnap = xctn.Snap()
}
}
smap := t.owner.smap.get()
msg := &stats.NodeStatus{
Node: stats.Node{
Snode: t.htrun.si,
},
SmapVersion: smap.Version,
MemCPUInfo: apc.GetMemCPU(),
RebSnap: rebSnap,
DeploymentType: deploymentType(),
Version: daemon.version,
BuildTime: daemon.buildTime,
K8sPodName: os.Getenv(env.AIS.K8sPod),
Status: t._status(smap),
}
// stats and capacity
ds := t.statsAndStatus()
ds.RebSnap = _rebSnap()
daeStats := t.statsT.GetStats()
msg.Tracker = daeStats.Tracker
msg.TargetCDF = daeStats.TargetCDF
ds.Tracker = daeStats.Tracker
ds.TargetCDF = daeStats.TargetCDF
nlog.Errorln(ds.TargetCDF.TotalUsed, ds.TargetCDF.TotalAvail) // DEBUG
t.writeJSON(w, r, ds, httpdaeWhat)
case apc.WhatNodeStatsAndStatusV322: // [ditto]
ds := t.statsAndStatusV322()
ds.RebSnap = _rebSnap()
daeStats := t.statsT.GetStatsV322()
ds.Tracker = daeStats.Tracker
ds.TargetCDF = daeStats.TargetCDF
t.writeJSON(w, r, ds, httpdaeWhat)

t.writeJSON(w, r, msg, httpdaeWhat)
case apc.WhatDiskStats:
diskStats := make(ios.AllDiskStats)
fs.FillDiskStats(diskStats)
Expand Down Expand Up @@ -349,6 +346,15 @@ func (t *target) httpdaeget(w http.ResponseWriter, r *http.Request) {
}
}

func _rebSnap() (rebSnap *core.Snap) {
if entry := xreg.GetLatest(xreg.Flt{Kind: apc.ActRebalance}); entry != nil {
if xctn := entry.Get(); xctn != nil {
rebSnap = xctn.Snap()
}
}
return rebSnap
}

// admin-join target | enable/disable mountpath
func (t *target) httpdaepost(w http.ResponseWriter, r *http.Request) {
apiItems, err := t.parseURL(w, r, apc.URLPathDae.L, 0, true)
Expand Down
14 changes: 9 additions & 5 deletions api/apc/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,15 @@ const (
// config
WhatNodeConfig = "config" // query specific node for (cluster config + overrides, local config)
WhatClusterConfig = "cluster_config"
// stats
WhatNodeStats = "stats"
WhatNodeStatsAndStatus = "status"
WhatMetricNames = "metrics"
WhatDiskStats = "disk"

// stats and status
WhatNodeStatsV322 = "stats" // [ backward compatibility ]
WhatNodeStatsAndStatusV322 = "status" // [ ditto ]
WhatNodeStats = "node_stats"
WhatNodeStatsAndStatus = "node_status"

WhatMetricNames = "metrics"
WhatDiskStats = "disk"
// assorted
WhatMountpaths = "mountpaths"
WhatRemoteAIS = "remote"
Expand Down
2 changes: 1 addition & 1 deletion api/blob.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package api provides Go based AIStore API/SDK over HTTP(S)
// Package api provides native Go-based API/SDK over HTTP(S).
/*
* Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
*/
Expand Down
4 changes: 2 additions & 2 deletions api/bsumm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package api provides Go based AIStore API/SDK over HTTP(S)
// Package api provides native Go-based API/SDK over HTTP(S).
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
*/
package api

Expand Down
4 changes: 2 additions & 2 deletions api/bucket.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package api provides Go based AIStore API/SDK over HTTP(S)
// Package api provides native Go-based API/SDK over HTTP(S).
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
*/
package api

Expand Down
4 changes: 2 additions & 2 deletions api/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package api provides Go based AIStore API/SDK over HTTP(S)
// Package api provides native Go-based API/SDK over HTTP(S).
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
*/
package api

Expand Down
51 changes: 2 additions & 49 deletions api/cluster.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package api provides Go based AIStore API/SDK over HTTP(S)
// Package api provides native Go-based API/SDK over HTTP(S).
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
*/
package api

Expand All @@ -13,8 +13,6 @@ import (
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/core/meta"
"github.com/NVIDIA/aistore/stats"
jsoniter "github.com/json-iterator/go"
)

// to be used by external watchdogs (Kubernetes, etc.)
Expand Down Expand Up @@ -158,46 +156,6 @@ func GetClusterSysInfo(bp BaseParams) (info apc.ClusterSysInfo, err error) {
return
}

// How to compute throughputs:
//
// - AIS supports several enumerated metric "kinds", including `KindThroughput`
// (for complete enumeration, see stats/api.go)
// - By convention, metrics that have `KindThroughput` kind are named with ".bps"
// ("bytes per second") suffix.
// - ".bps" metrics reported by api.GetClusterStats and api.GetDaemonStats are,
// in fact, cumulative byte numbers.
// - It is the client's responsibility to compute the actual throughputs
// as only the client knows _when_ exactly the same ".bps" metric was queried
// the previous time.
//
// - See also: `api.GetDaemonStats`, stats/api.go
func GetClusterStats(bp BaseParams) (res stats.Cluster, err error) {
bp.Method = http.MethodGet
reqParams := AllocRp()
{
reqParams.BaseParams = bp
reqParams.Path = apc.URLPathClu.S
reqParams.Query = url.Values{apc.QparamWhat: []string{apc.WhatNodeStats}}
}

var rawStats stats.ClusterRaw
_, err = reqParams.DoReqAny(&rawStats)
FreeRp(reqParams)
if err != nil {
return
}

res.Proxy = rawStats.Proxy
res.Target = make(map[string]*stats.Node)
for tid := range rawStats.Target {
var ts stats.Node
if err := jsoniter.Unmarshal(rawStats.Target[tid], &ts); err == nil {
res.Target[tid] = &ts
}
}
return
}

func GetRemoteAIS(bp BaseParams) (remais meta.RemAisVec, err error) {
bp.Method = http.MethodGet
reqParams := AllocRp()
Expand Down Expand Up @@ -290,11 +248,6 @@ func SetClusterConfigUsingMsg(bp BaseParams, configToUpdate *cmn.ConfigToSet, tr
return err
}

// zero out: all metrics _or_ only error counters
func ResetClusterStats(bp BaseParams, errorsOnly bool) (err error) {
return _putCluster(bp, apc.ActMsg{Action: apc.ActResetStats, Value: errorsOnly})
}

// all nodes: reset configuration to cluster defaults
func ResetClusterConfig(bp BaseParams) error {
return _putCluster(bp, apc.ActMsg{Action: apc.ActResetConfig})
Expand Down
Loading

0 comments on commit 85e15b9

Please sign in to comment.