mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Add appname to basic metrics (#547)
* Add app labels to queued/running/completed/failed metrics * Add app labels to queued/running/completed/failed metrics * Add app labels to queued/running/completed/failed metrics
This commit is contained in:
committed by
Reed Allman
parent
778c8b0495
commit
954f69e74a
@@ -192,7 +192,7 @@ func (a *agent) Submit(callI Call) error {
|
||||
}
|
||||
|
||||
// increment queued count
|
||||
a.stats.Enqueue(callI.Model().Path)
|
||||
a.stats.Enqueue(callI.Model().AppName, callI.Model().Path)
|
||||
|
||||
call := callI.(*call)
|
||||
ctx := call.req.Context()
|
||||
@@ -209,7 +209,7 @@ func (a *agent) Submit(callI Call) error {
|
||||
|
||||
slot, err := a.getSlot(ctx, call) // find ram available / running
|
||||
if err != nil {
|
||||
a.stats.Dequeue(callI.Model().Path)
|
||||
a.stats.Dequeue(callI.Model().AppName, callI.Model().Path)
|
||||
return transformTimeout(err, true)
|
||||
}
|
||||
// TODO if the call times out & container is created, we need
|
||||
@@ -219,12 +219,12 @@ func (a *agent) Submit(callI Call) error {
|
||||
// TODO Start is checking the timer now, we could do it here, too.
|
||||
err = call.Start(ctx, a)
|
||||
if err != nil {
|
||||
a.stats.Dequeue(callI.Model().Path)
|
||||
a.stats.Dequeue(callI.Model().AppName, callI.Model().Path)
|
||||
return transformTimeout(err, true)
|
||||
}
|
||||
|
||||
// decrement queued count, increment running count
|
||||
a.stats.DequeueAndStart(callI.Model().Path)
|
||||
a.stats.DequeueAndStart(callI.Model().AppName, callI.Model().Path)
|
||||
|
||||
err = slot.exec(ctx, call)
|
||||
// pass this error (nil or otherwise) to end directly, to store status, etc
|
||||
@@ -232,10 +232,10 @@ func (a *agent) Submit(callI Call) error {
|
||||
|
||||
if err == nil {
|
||||
// decrement running count, increment completed count
|
||||
a.stats.Complete(callI.Model().Path)
|
||||
a.stats.Complete(callI.Model().AppName, callI.Model().Path)
|
||||
} else {
|
||||
// decrement running count, increment failed count
|
||||
a.stats.Failed(callI.Model().Path)
|
||||
a.stats.Failed(callI.Model().AppName, callI.Model().Path)
|
||||
}
|
||||
|
||||
// TODO: we need to allocate more time to store the call + logs in case the call timed out,
|
||||
|
||||
@@ -53,28 +53,28 @@ var (
|
||||
Name: "fn_api_queued",
|
||||
Help: "Queued requests by path",
|
||||
},
|
||||
[](string){"path"},
|
||||
[](string){"app", "path"},
|
||||
)
|
||||
fnRunning = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "fn_api_running",
|
||||
Help: "Running requests by path",
|
||||
},
|
||||
[](string){"path"},
|
||||
[](string){"app", "path"},
|
||||
)
|
||||
fnCompleted = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "fn_api_completed",
|
||||
Help: "Completed requests by path",
|
||||
},
|
||||
[](string){"path"},
|
||||
[](string){"app", "path"},
|
||||
)
|
||||
fnFailed = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "fn_api_failed",
|
||||
Help: "Failed requests by path",
|
||||
},
|
||||
[](string){"path"},
|
||||
[](string){"app", "path"},
|
||||
)
|
||||
)
|
||||
|
||||
@@ -98,79 +98,79 @@ func (s *stats) getStatsForFunction(path string) *functionStats {
|
||||
return thisFunctionStats
|
||||
}
|
||||
|
||||
func (s *stats) Enqueue(path string) {
|
||||
func (s *stats) Enqueue(app string, path string) {
|
||||
s.mu.Lock()
|
||||
|
||||
s.queue++
|
||||
s.getStatsForFunction(path).queue++
|
||||
fnQueued.WithLabelValues(path).Inc()
|
||||
fnQueued.WithLabelValues(app, path).Inc()
|
||||
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
// Call when a function has been queued but cannot be started because of an error
|
||||
func (s *stats) Dequeue(path string) {
|
||||
func (s *stats) Dequeue(app string, path string) {
|
||||
s.mu.Lock()
|
||||
|
||||
s.queue--
|
||||
s.getStatsForFunction(path).queue--
|
||||
fnQueued.WithLabelValues(path).Dec()
|
||||
fnQueued.WithLabelValues(app, path).Dec()
|
||||
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
func (s *stats) DequeueAndStart(path string) {
|
||||
func (s *stats) DequeueAndStart(app string, path string) {
|
||||
s.mu.Lock()
|
||||
|
||||
s.queue--
|
||||
s.getStatsForFunction(path).queue--
|
||||
fnQueued.WithLabelValues(path).Dec()
|
||||
fnQueued.WithLabelValues(app, path).Dec()
|
||||
|
||||
s.running++
|
||||
s.getStatsForFunction(path).running++
|
||||
fnRunning.WithLabelValues(path).Inc()
|
||||
fnRunning.WithLabelValues(app, path).Inc()
|
||||
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
func (s *stats) Complete(path string) {
|
||||
func (s *stats) Complete(app string, path string) {
|
||||
s.mu.Lock()
|
||||
|
||||
s.running--
|
||||
s.getStatsForFunction(path).running--
|
||||
fnRunning.WithLabelValues(path).Dec()
|
||||
fnRunning.WithLabelValues(app, path).Dec()
|
||||
|
||||
s.complete++
|
||||
s.getStatsForFunction(path).complete++
|
||||
fnCompleted.WithLabelValues(path).Inc()
|
||||
fnCompleted.WithLabelValues(app, path).Inc()
|
||||
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
func (s *stats) Failed(path string) {
|
||||
func (s *stats) Failed(app string, path string) {
|
||||
s.mu.Lock()
|
||||
|
||||
s.running--
|
||||
s.getStatsForFunction(path).running--
|
||||
fnRunning.WithLabelValues(path).Dec()
|
||||
fnRunning.WithLabelValues(app, path).Dec()
|
||||
|
||||
s.failed++
|
||||
s.getStatsForFunction(path).failed++
|
||||
fnFailed.WithLabelValues(path).Inc()
|
||||
fnFailed.WithLabelValues(app, path).Inc()
|
||||
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
func (s *stats) DequeueAndFail(path string) {
|
||||
func (s *stats) DequeueAndFail(app string, path string) {
|
||||
s.mu.Lock()
|
||||
|
||||
s.queue--
|
||||
s.getStatsForFunction(path).queue--
|
||||
fnQueued.WithLabelValues(path).Dec()
|
||||
fnQueued.WithLabelValues(app, path).Dec()
|
||||
|
||||
s.failed++
|
||||
s.getStatsForFunction(path).failed++
|
||||
fnFailed.WithLabelValues(path).Inc()
|
||||
fnFailed.WithLabelValues(app, path).Inc()
|
||||
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user