Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openfaas-faas
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Team Jaz CS 598 CCC Final Project
openfaas-faas
Commits
38713184
Commit
38713184
authored
8 years ago
by
Alex
Committed by
Alex Ellis
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add status code instrumentation for functions
parent
5802cd11
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gateway/handlers/functionshandler.go
+17
-7
17 additions, 7 deletions
gateway/handlers/functionshandler.go
gateway/handlers/proxy.go
+14
-5
14 additions, 5 deletions
gateway/handlers/proxy.go
gateway/metrics/metrics.go
+1
-1
1 addition, 1 deletion
gateway/metrics/metrics.go
with
32 additions
and
13 deletions
gateway/handlers/functionshandler.go
+
17
−
7
View file @
38713184
...
...
@@ -15,9 +15,24 @@ import (
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client"
"github.com/prometheus/client_golang/prometheus"
io_prometheus_client
"github.com/prometheus/client_model/go"
)
func
getCounterValue
(
service
string
,
code
string
,
metricsOptions
*
metrics
.
MetricOptions
)
float64
{
metric
,
err
:=
metricsOptions
.
GatewayFunctionInvocation
.
GetMetricWith
(
prometheus
.
Labels
{
"function_name"
:
service
,
"code"
:
code
})
if
err
!=
nil
{
return
0
}
// Get the metric's value from ProtoBuf interface (idea via Julius Volz)
var
protoMetric
io_prometheus_client
.
Metric
metric
.
Write
(
&
protoMetric
)
invocations
:=
protoMetric
.
GetCounter
()
.
GetValue
()
return
invocations
}
// MakeFunctionReader gives a summary of Function structs with Docker service stats overlaid with Prometheus counters.
func
MakeFunctionReader
(
metricsOptions
metrics
.
MetricOptions
,
c
*
client
.
Client
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -39,13 +54,8 @@ func MakeFunctionReader(metricsOptions metrics.MetricOptions, c *client.Client)
for
_
,
service
:=
range
services
{
if
len
(
service
.
Spec
.
TaskTemplate
.
ContainerSpec
.
Labels
[
"function"
])
>
0
{
counter
,
_
:=
metricsOptions
.
GatewayFunctionInvocation
.
GetMetricWithLabelValues
(
service
.
Spec
.
Name
)
// Get the metric's value from ProtoBuf interface (idea via Julius Volz)
var
protoMetric
io_prometheus_client
.
Metric
counter
.
Write
(
&
protoMetric
)
invocations
:=
protoMetric
.
GetCounter
()
.
GetValue
()
invocations
:=
getCounterValue
(
service
.
Spec
.
Name
,
"200"
,
&
metricsOptions
)
+
getCounterValue
(
service
.
Spec
.
Name
,
"500"
,
&
metricsOptions
)
f
:=
requests
.
Function
{
Name
:
service
.
Spec
.
Name
,
...
...
This diff is collapsed.
Click to expand it.
gateway/handlers/proxy.go
+
14
−
5
View file @
38713184
...
...
@@ -15,6 +15,7 @@ import (
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
)
// MakeProxy creates a proxy for HTTP web requests which can be routed to a function.
...
...
@@ -46,13 +47,21 @@ func MakeProxy(metrics metrics.MetricOptions, wildcard bool, c *client.Client, l
}
}
func
writeHead
(
service
string
,
metrics
metrics
.
MetricOptions
,
code
int
,
w
http
.
ResponseWriter
)
{
w
.
WriteHeader
(
code
)
metrics
.
GatewayFunctionInvocation
.
With
(
prometheus
.
Labels
{
"function_name"
:
service
,
"code"
:
strconv
.
Itoa
(
code
)})
.
Inc
()
// metrics.GatewayFunctionInvocation.WithLabelValues(service).Add(1)
}
func
lookupInvoke
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
metrics
metrics
.
MetricOptions
,
name
string
,
c
*
client
.
Client
,
logger
*
logrus
.
Logger
)
{
exists
,
err
:=
lookupSwarmService
(
name
,
c
)
if
err
!=
nil
||
exists
==
false
{
if
err
!=
nil
{
logger
.
Fatalln
(
err
)
}
w
.
W
riteHead
er
(
http
.
StatusInternalServerError
)
writeHead
(
name
,
metrics
,
http
.
StatusInternalServerError
,
w
)
w
.
Write
([]
byte
(
"Error resolving service."
))
defer
r
.
Body
.
Close
()
}
...
...
@@ -72,7 +81,6 @@ func lookupSwarmService(serviceName string, c *client.Client) (bool, error) {
}
func
invokeService
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
metrics
metrics
.
MetricOptions
,
service
string
,
requestBody
[]
byte
,
logger
*
logrus
.
Logger
)
{
metrics
.
GatewayFunctionInvocation
.
WithLabelValues
(
service
)
.
Add
(
1
)
stamp
:=
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
(),
10
)
...
...
@@ -89,7 +97,7 @@ func invokeService(w http.ResponseWriter, r *http.Request, metrics metrics.Metri
response
,
err
:=
http
.
Post
(
url
,
r
.
Header
.
Get
(
"Content-Type"
),
buf
)
if
err
!=
nil
{
logger
.
Infoln
(
err
)
w
.
W
riteHead
er
(
500
)
writeHead
(
service
,
metrics
,
http
.
StatusInternalServerError
,
w
)
buf
:=
bytes
.
NewBufferString
(
"Can't reach service: "
+
service
)
w
.
Write
(
buf
.
Bytes
())
return
...
...
@@ -98,7 +106,8 @@ func invokeService(w http.ResponseWriter, r *http.Request, metrics metrics.Metri
responseBody
,
readErr
:=
ioutil
.
ReadAll
(
response
.
Body
)
if
readErr
!=
nil
{
fmt
.
Println
(
readErr
)
w
.
WriteHeader
(
500
)
writeHead
(
service
,
metrics
,
http
.
StatusInternalServerError
,
w
)
buf
:=
bytes
.
NewBufferString
(
"Error reading response from service: "
+
service
)
w
.
Write
(
buf
.
Bytes
())
return
...
...
@@ -107,7 +116,7 @@ func invokeService(w http.ResponseWriter, r *http.Request, metrics metrics.Metri
// Match header for strict services
w
.
Header
()
.
Set
(
"Content-Type"
,
r
.
Header
.
Get
(
"Content-Type"
))
w
.
W
riteHead
er
(
http
.
StatusOK
)
writeHead
(
service
,
metrics
,
http
.
StatusOK
,
w
)
w
.
Write
(
responseBody
)
seconds
:=
time
.
Since
(
start
)
.
Seconds
()
...
...
This diff is collapsed.
Click to expand it.
gateway/metrics/metrics.go
+
1
−
1
View file @
38713184
...
...
@@ -37,7 +37,7 @@ func BuildMetricsOptions() MetricOptions {
Name
:
"gateway_function_invocation_total"
,
Help
:
"Individual function metrics"
,
},
[]
string
{
"function_name"
},
[]
string
{
"function_name"
,
"code"
},
)
metricsOptions
:=
MetricOptions
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment