mirror of
https://github.com/openfaas/faas.git
synced 2025-06-11 17:56:47 +00:00
Specify Linux constraints by default
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
parent
1a78ec9234
commit
78daa9cd39
@ -5,16 +5,13 @@ services:
|
|||||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||||
ports:
|
ports:
|
||||||
- 8080:8080
|
- 8080:8080
|
||||||
image: functions/gateway:0.6.2
|
image: functions/gateway:0.6.3
|
||||||
networks:
|
networks:
|
||||||
- functions
|
- functions
|
||||||
environment:
|
environment:
|
||||||
dnsrr: "true" # Temporarily use dnsrr in place of VIP while issue persists on PWD
|
dnsrr: "true" # Temporarily use dnsrr in place of VIP while issue persists on PWD
|
||||||
faas_nats_address: "nats"
|
faas_nats_address: "nats"
|
||||||
faas_nats_port: 4222
|
faas_nats_port: 4222
|
||||||
deploy:
|
|
||||||
placement:
|
|
||||||
constraints: [node.role == manager]
|
|
||||||
# Start Add for NATS Streaming
|
# Start Add for NATS Streaming
|
||||||
depends_on:
|
depends_on:
|
||||||
- nats
|
- nats
|
||||||
@ -24,6 +21,11 @@ services:
|
|||||||
delay: 5s
|
delay: 5s
|
||||||
max_attempts: 20
|
max_attempts: 20
|
||||||
window: 380s
|
window: 380s
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.role == manager'
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
nats:
|
nats:
|
||||||
image: nats-streaming:0.5.0
|
image: nats-streaming:0.5.0
|
||||||
ports:
|
ports:
|
||||||
@ -32,6 +34,11 @@ services:
|
|||||||
command: "--store memory --cluster_id faas-cluster"
|
command: "--store memory --cluster_id faas-cluster"
|
||||||
networks:
|
networks:
|
||||||
- functions
|
- functions
|
||||||
|
deploy:
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
queue-worker:
|
queue-worker:
|
||||||
image: functions/queue-worker:0.1.1
|
image: functions/queue-worker:0.1.1
|
||||||
networks:
|
networks:
|
||||||
@ -42,6 +49,10 @@ services:
|
|||||||
delay: 5s
|
delay: 5s
|
||||||
max_attempts: 20
|
max_attempts: 20
|
||||||
window: 380s
|
window: 380s
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
# End
|
# End
|
||||||
|
|
||||||
prometheus:
|
prometheus:
|
||||||
@ -58,7 +69,9 @@ services:
|
|||||||
- functions
|
- functions
|
||||||
deploy:
|
deploy:
|
||||||
placement:
|
placement:
|
||||||
constraints: [node.role == manager]
|
constraints:
|
||||||
|
- 'node.role == manager'
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
alertmanager:
|
alertmanager:
|
||||||
image: functions/alertmanager:latest # autobuild from Dockerfile in repo.
|
image: functions/alertmanager:latest # autobuild from Dockerfile in repo.
|
||||||
@ -74,7 +87,9 @@ services:
|
|||||||
- 9093:9093
|
- 9093:9093
|
||||||
deploy:
|
deploy:
|
||||||
placement:
|
placement:
|
||||||
constraints: [node.role == manager]
|
constraints:
|
||||||
|
- 'node.role == manager'
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
# Sample functions go here.
|
# Sample functions go here.
|
||||||
|
|
||||||
@ -90,6 +105,10 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
no_proxy: "gateway"
|
no_proxy: "gateway"
|
||||||
https_proxy: $https_proxy
|
https_proxy: $https_proxy
|
||||||
|
deploy:
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
# Node.js gives OS info about the node (Host)
|
# Node.js gives OS info about the node (Host)
|
||||||
nodeinfo:
|
nodeinfo:
|
||||||
@ -103,6 +122,10 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
no_proxy: "gateway"
|
no_proxy: "gateway"
|
||||||
https_proxy: $https_proxy
|
https_proxy: $https_proxy
|
||||||
|
deploy:
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
# Uses `cat` to echo back response, fastest function to execute.
|
# Uses `cat` to echo back response, fastest function to execute.
|
||||||
echoit:
|
echoit:
|
||||||
@ -117,6 +140,10 @@ services:
|
|||||||
fprocess: "cat"
|
fprocess: "cat"
|
||||||
no_proxy: "gateway"
|
no_proxy: "gateway"
|
||||||
https_proxy: $https_proxy
|
https_proxy: $https_proxy
|
||||||
|
deploy:
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
functions:
|
functions:
|
||||||
|
@ -5,15 +5,16 @@ services:
|
|||||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||||
ports:
|
ports:
|
||||||
- 8080:8080
|
- 8080:8080
|
||||||
image: functions/gateway:0.6.2
|
image: functions/gateway:0.6.3
|
||||||
networks:
|
networks:
|
||||||
- functions
|
- functions
|
||||||
environment:
|
environment:
|
||||||
dnsrr: "true" # Temporarily use dnsrr in place of VIP while issue persists on PWD
|
dnsrr: "true" # Temporarily use dnsrr in place of VIP while issue persists on PWD
|
||||||
deploy:
|
deploy:
|
||||||
placement:
|
placement:
|
||||||
constraints: [node.role == manager]
|
constraints:
|
||||||
|
- 'node.role == manager'
|
||||||
|
- 'node.platform.os == linux'
|
||||||
prometheus:
|
prometheus:
|
||||||
image: functions/prometheus:latest # autobuild from Dockerfile in repo.
|
image: functions/prometheus:latest # autobuild from Dockerfile in repo.
|
||||||
command: "-config.file=/etc/prometheus/prometheus.yml -storage.local.path=/prometheus -storage.local.memory-chunks=10000 --alertmanager.url=http://alertmanager:9093"
|
command: "-config.file=/etc/prometheus/prometheus.yml -storage.local.path=/prometheus -storage.local.memory-chunks=10000 --alertmanager.url=http://alertmanager:9093"
|
||||||
@ -28,7 +29,9 @@ services:
|
|||||||
- functions
|
- functions
|
||||||
deploy:
|
deploy:
|
||||||
placement:
|
placement:
|
||||||
constraints: [node.role == manager]
|
constraints:
|
||||||
|
- 'node.role == manager'
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
alertmanager:
|
alertmanager:
|
||||||
image: functions/alertmanager:latest # autobuild from Dockerfile in repo.
|
image: functions/alertmanager:latest # autobuild from Dockerfile in repo.
|
||||||
@ -44,8 +47,9 @@ services:
|
|||||||
- 9093:9093
|
- 9093:9093
|
||||||
deploy:
|
deploy:
|
||||||
placement:
|
placement:
|
||||||
constraints: [node.role == manager]
|
constraints:
|
||||||
|
- 'node.role == manager'
|
||||||
|
- 'node.platform.os == linux'
|
||||||
# Sample functions go here.
|
# Sample functions go here.
|
||||||
|
|
||||||
# Service label of "function" allows functions to show up in UI on http://gateway:8080/
|
# Service label of "function" allows functions to show up in UI on http://gateway:8080/
|
||||||
@ -60,6 +64,10 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
no_proxy: "gateway"
|
no_proxy: "gateway"
|
||||||
https_proxy: $https_proxy
|
https_proxy: $https_proxy
|
||||||
|
deploy:
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
# Pass a username as an argument to find how many images user has pushed to Docker Hub.
|
# Pass a username as an argument to find how many images user has pushed to Docker Hub.
|
||||||
hubstats:
|
hubstats:
|
||||||
@ -73,6 +81,11 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
no_proxy: "gateway"
|
no_proxy: "gateway"
|
||||||
https_proxy: $https_proxy
|
https_proxy: $https_proxy
|
||||||
|
deploy:
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
|
|
||||||
# Node.js gives OS info about the node (Host)
|
# Node.js gives OS info about the node (Host)
|
||||||
nodeinfo:
|
nodeinfo:
|
||||||
@ -86,6 +99,11 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
no_proxy: "gateway"
|
no_proxy: "gateway"
|
||||||
https_proxy: $https_proxy
|
https_proxy: $https_proxy
|
||||||
|
deploy:
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
|
|
||||||
# Uses `cat` to echo back response, fastest function to execute.
|
# Uses `cat` to echo back response, fastest function to execute.
|
||||||
echoit:
|
echoit:
|
||||||
@ -100,6 +118,11 @@ services:
|
|||||||
fprocess: "cat"
|
fprocess: "cat"
|
||||||
no_proxy: "gateway"
|
no_proxy: "gateway"
|
||||||
https_proxy: $https_proxy
|
https_proxy: $https_proxy
|
||||||
|
deploy:
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
|
|
||||||
# Counts words in request with `wc` utility
|
# Counts words in request with `wc` utility
|
||||||
wordcount:
|
wordcount:
|
||||||
@ -115,6 +138,11 @@ services:
|
|||||||
fprocess: "wc"
|
fprocess: "wc"
|
||||||
no_proxy: "gateway"
|
no_proxy: "gateway"
|
||||||
https_proxy: $https_proxy
|
https_proxy: $https_proxy
|
||||||
|
deploy:
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
|
|
||||||
# Calculates base64 representation of request body.
|
# Calculates base64 representation of request body.
|
||||||
base64:
|
base64:
|
||||||
@ -129,6 +157,11 @@ services:
|
|||||||
fprocess: "base64"
|
fprocess: "base64"
|
||||||
no_proxy: "gateway"
|
no_proxy: "gateway"
|
||||||
https_proxy: $https_proxy
|
https_proxy: $https_proxy
|
||||||
|
deploy:
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
|
|
||||||
# Decodes base64 representation of request body.
|
# Decodes base64 representation of request body.
|
||||||
decodebase64:
|
decodebase64:
|
||||||
@ -143,6 +176,10 @@ services:
|
|||||||
fprocess: "base64 -d"
|
fprocess: "base64 -d"
|
||||||
no_proxy: "gateway"
|
no_proxy: "gateway"
|
||||||
https_proxy: $https_proxy
|
https_proxy: $https_proxy
|
||||||
|
deploy:
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
# Converts body in (markdown format) -> (html)
|
# Converts body in (markdown format) -> (html)
|
||||||
markdown:
|
markdown:
|
||||||
@ -156,6 +193,10 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
no_proxy: "gateway"
|
no_proxy: "gateway"
|
||||||
https_proxy: $https_proxy
|
https_proxy: $https_proxy
|
||||||
|
deploy:
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.platform.os == linux'
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
functions:
|
functions:
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
// Copyright (c) Alex Ellis 2017. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -9,103 +6,21 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
"github.com/alexellis/faas/gateway/metrics"
|
"github.com/alexellis/faas/gateway/metrics"
|
||||||
"github.com/alexellis/faas/gateway/requests"
|
"github.com/alexellis/faas/gateway/requests"
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/registry"
|
"github.com/docker/docker/registry"
|
||||||
"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
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeDeleteFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Client) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
req := requests.DeleteFunctionRequest{}
|
|
||||||
defer r.Body.Close()
|
|
||||||
reqData, _ := ioutil.ReadAll(r.Body)
|
|
||||||
unmarshalErr := json.Unmarshal(reqData, &req)
|
|
||||||
|
|
||||||
if (len(req.FunctionName) == 0) || unmarshalErr != nil {
|
|
||||||
log.Printf("Error parsing request to remove service: %s\n", unmarshalErr)
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("Attempting to remove service %s\n", req.FunctionName)
|
|
||||||
|
|
||||||
serviceFilter := filters.NewArgs()
|
|
||||||
options := types.ServiceListOptions{
|
|
||||||
Filters: serviceFilter,
|
|
||||||
}
|
|
||||||
|
|
||||||
services, err := c.ServiceList(context.Background(), options)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Filter only "faas" functions (via metadata?)
|
|
||||||
var serviceIDs []string
|
|
||||||
for _, service := range services {
|
|
||||||
isFunction := len(service.Spec.TaskTemplate.ContainerSpec.Labels["function"]) > 0
|
|
||||||
|
|
||||||
if isFunction && req.FunctionName == service.Spec.Name {
|
|
||||||
serviceIDs = append(serviceIDs, service.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println(len(serviceIDs))
|
|
||||||
if len(serviceIDs) == 0 {
|
|
||||||
w.WriteHeader(http.StatusNotFound)
|
|
||||||
w.Write([]byte(fmt.Sprintf("No such service found: %s.", req.FunctionName)))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var serviceRemoveErrors []error
|
|
||||||
for _, serviceID := range serviceIDs {
|
|
||||||
err := c.ServiceRemove(context.Background(), serviceID)
|
|
||||||
if err != nil {
|
|
||||||
serviceRemoveErrors = append(serviceRemoveErrors, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(serviceRemoveErrors) > 0 {
|
|
||||||
log.Printf("Error(s) removing service: %s\n", req.FunctionName)
|
|
||||||
log.Println(serviceRemoveErrors)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
} else {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MakeNewFunctionHandler creates a new function (service) inside the swarm network.
|
// MakeNewFunctionHandler creates a new function (service) inside the swarm network.
|
||||||
func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Client, maxRestarts uint64) http.HandlerFunc {
|
func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Client, maxRestarts uint64) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -146,6 +61,7 @@ func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Clie
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64) swarm.ServiceSpec {
|
func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64) swarm.ServiceSpec {
|
||||||
|
linuxOnlyConstraints := []string{"node.platform.os == linux"}
|
||||||
|
|
||||||
nets := []swarm.NetworkAttachmentConfig{
|
nets := []swarm.NetworkAttachmentConfig{
|
||||||
{Target: request.Network},
|
{Target: request.Network},
|
||||||
@ -164,6 +80,9 @@ func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64) swarm
|
|||||||
Labels: map[string]string{"function": "true"},
|
Labels: map[string]string{"function": "true"},
|
||||||
},
|
},
|
||||||
Networks: nets,
|
Networks: nets,
|
||||||
|
Placement: &swarm.Placement{
|
||||||
|
Constraints: linuxOnlyConstraints,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Annotations: swarm.Annotations{
|
Annotations: swarm.Annotations{
|
||||||
Name: request.Service,
|
Name: request.Service,
|
82
gateway/handlers/deletehandler.go
Normal file
82
gateway/handlers/deletehandler.go
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
// Copyright (c) Alex Ellis 2017. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/alexellis/faas/gateway/metrics"
|
||||||
|
"github.com/alexellis/faas/gateway/requests"
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/api/types/filters"
|
||||||
|
"github.com/docker/docker/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MakeDeleteFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Client) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
req := requests.DeleteFunctionRequest{}
|
||||||
|
defer r.Body.Close()
|
||||||
|
reqData, _ := ioutil.ReadAll(r.Body)
|
||||||
|
unmarshalErr := json.Unmarshal(reqData, &req)
|
||||||
|
|
||||||
|
if (len(req.FunctionName) == 0) || unmarshalErr != nil {
|
||||||
|
log.Printf("Error parsing request to remove service: %s\n", unmarshalErr)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Attempting to remove service %s\n", req.FunctionName)
|
||||||
|
|
||||||
|
serviceFilter := filters.NewArgs()
|
||||||
|
options := types.ServiceListOptions{
|
||||||
|
Filters: serviceFilter,
|
||||||
|
}
|
||||||
|
|
||||||
|
services, err := c.ServiceList(context.Background(), options)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Filter only "faas" functions (via metadata?)
|
||||||
|
var serviceIDs []string
|
||||||
|
for _, service := range services {
|
||||||
|
isFunction := len(service.Spec.TaskTemplate.ContainerSpec.Labels["function"]) > 0
|
||||||
|
|
||||||
|
if isFunction && req.FunctionName == service.Spec.Name {
|
||||||
|
serviceIDs = append(serviceIDs, service.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(len(serviceIDs))
|
||||||
|
if len(serviceIDs) == 0 {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
w.Write([]byte(fmt.Sprintf("No such service found: %s.", req.FunctionName)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var serviceRemoveErrors []error
|
||||||
|
for _, serviceID := range serviceIDs {
|
||||||
|
err := c.ServiceRemove(context.Background(), serviceID)
|
||||||
|
if err != nil {
|
||||||
|
serviceRemoveErrors = append(serviceRemoveErrors, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(serviceRemoveErrors) > 0 {
|
||||||
|
log.Printf("Error(s) removing service: %s\n", req.FunctionName)
|
||||||
|
log.Println(serviceRemoveErrors)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,8 @@ import (
|
|||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
io_prometheus_client "github.com/prometheus/client_model/go"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MakeFunctionReader gives a summary of Function structs with Docker service stats overlaid with Prometheus counters.
|
// MakeFunctionReader gives a summary of Function structs with Docker service stats overlaid with Prometheus counters.
|
||||||
@ -68,3 +70,19 @@ func MakeFunctionReader(metricsOptions metrics.MetricOptions, c *client.Client)
|
|||||||
w.Write(functionBytes)
|
w.Write(functionBytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user