-
Notifications
You must be signed in to change notification settings - Fork 6
Added failure list code, tested #11
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
288acb6
*: use list to track latencies
fuweid 14563d3
Merge pull request #6 from fuweid/remove-prom-deps
fuweid 520665f
cmd: init virtualcluster subcommand
fuweid c6080af
runner: use default value if flag is not set
fuweid a57838b
Merge pull request #7 from fuweid/weifu/init-vc
fuweid 2c93ca6
Merge pull request #8 from fuweid/weifu/fix-runner-option
fuweid 411bb35
Added failure list code, tested
mchinta7 b53f59c
Removed failureCount field in ResponseMetric and ResponseStat, added …
mchinta7 cff5f22
Adding mutex inside ObserveFailure() instead of where it is called
mchinta7 f061cfb
addressing more comments
mchinta7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package virtualcluster | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/urfave/cli" | ||
) | ||
|
||
var nodepoolCommand = cli.Command{ | ||
Name: "nodepool", | ||
Usage: "Manage virtual node pools", | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "kubeconfig", | ||
Usage: "Path to the kubeconfig file", | ||
}, | ||
}, | ||
Subcommands: []cli.Command{ | ||
nodepoolAddCommand, | ||
nodepoolDelCommand, | ||
nodepoolListCommand, | ||
}, | ||
} | ||
|
||
var nodepoolAddCommand = cli.Command{ | ||
Name: "add", | ||
Usage: "Add a virtual node pool", | ||
ArgsUsage: "NAME", | ||
Flags: []cli.Flag{ | ||
cli.IntFlag{ | ||
Name: "nodes", | ||
Usage: "The number of virtual nodes", | ||
Value: 10, | ||
}, | ||
cli.IntFlag{ | ||
Name: "cpu", | ||
Usage: "The allocatable CPU resource per node", | ||
Value: 8, | ||
}, | ||
cli.IntFlag{ | ||
Name: "memory", | ||
Usage: "The allocatable Memory resource per node (GiB)", | ||
Value: 16, | ||
}, | ||
}, | ||
Action: func(cliCtx *cli.Context) error { | ||
return fmt.Errorf("nodepool add - not implemented") | ||
}, | ||
} | ||
|
||
var nodepoolDelCommand = cli.Command{ | ||
Name: "delete", | ||
ShortName: "del", | ||
ArgsUsage: "NAME", | ||
Usage: "Delete a virtual node pool", | ||
Action: func(cliCtx *cli.Context) error { | ||
return fmt.Errorf("nodepool delete - not implemented") | ||
}, | ||
} | ||
|
||
var nodepoolListCommand = cli.Command{ | ||
Name: "list", | ||
Usage: "List virtual node pools", | ||
Action: func(cliCtx *cli.Context) error { | ||
return fmt.Errorf("nodepool list - not implemented") | ||
}, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package virtualcluster | ||
|
||
import "github.com/urfave/cli" | ||
|
||
// const namespace = "kperf-virtualcluster" | ||
|
||
// Command represents virtualcluster subcommand. | ||
var Command = cli.Command{ | ||
Name: "virtualcluster", | ||
ShortName: "vc", | ||
Usage: "Setup virtual cluster and run workload on that", | ||
Subcommands: []cli.Command{ | ||
nodepoolCommand, | ||
}, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,84 @@ | ||
package metrics | ||
|
||
import ( | ||
"fmt" | ||
"container/list" | ||
"math" | ||
"sort" | ||
"sync" | ||
"sync/atomic" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// ResponseMetric is a measurement related to http response. | ||
type ResponseMetric interface { | ||
// ObserveLatency observes latency. | ||
ObserveLatency(seconds float64) | ||
// ObserveFailure observes failure response. | ||
ObserveFailure() | ||
ObserveFailure(err error) | ||
// Gather returns the summary. | ||
Gather() (latencies map[float64]float64, failure int, _ error) | ||
Gather() (latencies []float64, percentileLatencies map[float64]float64, failure int, failureList []error) | ||
} | ||
|
||
type responseMetricImpl struct { | ||
latencySeconds *prometheus.SummaryVec | ||
failureCount int64 | ||
mu sync.Mutex | ||
failureCount int64 | ||
failureList []error | ||
latencies *list.List | ||
} | ||
|
||
func NewResponseMetric() ResponseMetric { | ||
return &responseMetricImpl{ | ||
latencySeconds: prometheus.NewSummaryVec( | ||
prometheus.SummaryOpts{ | ||
Namespace: "request", | ||
Name: "request_latency_seconds", | ||
Objectives: map[float64]float64{0: 0, 0.5: 0, 0.9: 0, 0.95: 0, 0.99: 0, 1: 0}, | ||
}, | ||
[]string{}, | ||
), | ||
latencies: list.New(), | ||
failureList: []error{}, | ||
manasachi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
// ObserveLatency implements ResponseMetric. | ||
func (m *responseMetricImpl) ObserveLatency(seconds float64) { | ||
m.latencySeconds.WithLabelValues().Observe(seconds) | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
m.latencies.PushBack(seconds) | ||
} | ||
|
||
// ObserveFailure implements ResponseMetric. | ||
func (m *responseMetricImpl) ObserveFailure() { | ||
func (m *responseMetricImpl) ObserveFailure(err error) { | ||
m.failureList = append(m.failureList, err) | ||
manasachi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
atomic.AddInt64(&m.failureCount, 1) | ||
} | ||
|
||
// Gather implements ResponseMetric. | ||
func (m *responseMetricImpl) Gather() (map[float64]float64, int, error) { | ||
reg := prometheus.NewRegistry() | ||
reg.MustRegister(m.latencySeconds) | ||
func (m *responseMetricImpl) Gather() ([]float64, map[float64]float64, int, []error) { | ||
latencies := m.dumpLatencies() | ||
|
||
return latencies, buildPercentileLatencies(latencies), int(atomic.LoadInt64(&m.failureCount)), m.failureList | ||
} | ||
|
||
metricFamilies, err := reg.Gather() | ||
if err != nil { | ||
return nil, 0, fmt.Errorf("failed to gather from local registry: %w", err) | ||
func (m *responseMetricImpl) dumpLatencies() []float64 { | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
res := make([]float64, 0, m.latencies.Len()) | ||
for e := m.latencies.Front(); e != nil; e = e.Next() { | ||
res = append(res, e.Value.(float64)) | ||
} | ||
return res | ||
} | ||
|
||
latencies := map[float64]float64{} | ||
for _, q := range metricFamilies[0].GetMetric()[0].GetSummary().GetQuantile() { | ||
latencies[q.GetQuantile()] = q.GetValue() | ||
var percentiles = []float64{0, 50, 90, 95, 99, 100} | ||
|
||
func buildPercentileLatencies(latencies []float64) map[float64]float64 { | ||
if len(latencies) == 0 { | ||
return nil | ||
} | ||
|
||
return latencies, int(atomic.LoadInt64(&m.failureCount)), nil | ||
res := make(map[float64]float64, len(percentiles)) | ||
|
||
n := len(latencies) | ||
sort.Float64s(latencies) | ||
for _, p := range percentiles { | ||
idx := int(math.Ceil(float64(n) * p / 100)) | ||
if idx > 0 { | ||
idx-- | ||
} | ||
res[p] = latencies[idx] | ||
} | ||
return res | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.