Skip to content

Commit

Permalink
Merge pull request #144 from suizman/cmd_workload
Browse files Browse the repository at this point in the history
Create "workload" cmd subcommand
  • Loading branch information
suizman committed Jul 12, 2019
2 parents b9ae3bc + 4287cfe commit 2fd75b1
Show file tree
Hide file tree
Showing 35 changed files with 367 additions and 321 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
storage
!storage
**deploy
**riot
**workload
**prometheus
**/.git
**/.terraform
Expand Down
21 changes: 12 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.12.1
FROM golang:1.12.5

# Allow cloning custom repo & branch for testing
ARG QED_REPO=https://github.com/bbva/qed.git
ARG QED_REPO_BRANCH=master

ENV GO111MODULE=on
ENV CGO_LDFLAGS_ALLOW='.*'
ENV REPO=${QED_REPO}
ENV BRANCH=${QED_REPO_BRANCH}

WORKDIR /go/src/github.com/bbva/qed

# Install deps.
RUN apt update -qq && apt install -qq -y autoconf cmake

# Build C deps.
# This step acts as cache to avoid recompiling when Go code changes.
RUN git clone https://github.com/BBVA/qed.git . &&\
git submodule update --init --recursive &&\
cd c-deps &&\
./builddeps.sh &&\
RUN git clone --depth 1 -b ${BRANCH} ${REPO} . &&\
git submodule update --init --recursive &&\
cd c-deps &&\
./builddeps.sh &&\
go mod download

# Build QED, Storage binary and riot
# Build QED, Storage binary
RUN go build -o /usr/local/bin/qed &&\
go build -o /usr/local/bin/riot testutils/riot/riot.go &&\
go build -o /usr/local/bin/storage testutils/notifierstore.go

# Clean
Expand All @@ -41,7 +45,6 @@ RUN rm -rf /var/lib/apt/lists/*
FROM ubuntu:19.10

COPY --from=0 /usr/local/bin/qed /usr/local/bin/qed
COPY --from=0 /usr/local/bin/riot /usr/local/bin/riot
COPY --from=0 /usr/local/bin/storage /usr/local/bin/storage

RUN /usr/local/bin/qed generate signerkeys
3 changes: 1 addition & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,12 @@ func NewHTTPClient(options ...HTTPClientOptionF) (*HTTPClient, error) {
healthCheckStopCh: make(chan bool),
discoveryStopCh: make(chan bool),
}

// Run the options on the client
for _, option := range options {
if err := option(client); err != nil {
return nil, err
}
}

// configure retrier
_ = client.setRetrier(client.maxRetries)

Expand Down Expand Up @@ -405,6 +403,7 @@ func (c *HTTPClient) discover() error {
}

body, err := c.doReq("GET", e, "/info/shards", nil)

if err == nil {
var shards protocol.Shards
err = json.Unmarshal(body, &shards)
Expand Down
9 changes: 5 additions & 4 deletions cmd/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd

import (
"context"
"fmt"

"github.com/bbva/qed/gossip"
"github.com/bbva/qed/log"
Expand Down Expand Up @@ -69,19 +70,19 @@ func runAgent(cmd *cobra.Command, args []string) error {
gossipStartJoin, _ := cmd.Flags().GetStringSlice("start-join")
err = urlParseNoSchemaRequired(gossipStartJoin...)
if err != nil {
return err
return fmt.Errorf("Gosspip start join: %v", err)
}

bindAddress, _ := cmd.Flags().GetString("bind-addr")
err = urlParseNoSchemaRequired(bindAddress)
if err != nil {
return err
return fmt.Errorf("Bind address: %v", err)
}

advertiseAddress, _ := cmd.Flags().GetString("advertise-addr")
err = urlParse(advertiseAddress)
err = urlParseNoSchemaRequired(advertiseAddress)
if err != nil {
return err
return fmt.Errorf("Advertise address: %v", err)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions cmd/agent_auditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,17 @@ func checkAuditorParams(conf *auditorConfig) error {
var err error
err = urlParse(conf.Notifier.Endpoint...)
if err != nil {
return err
return fmt.Errorf("Notifier endpoint: %v", err)
}

err = urlParse(conf.Store.Endpoint...)
if err != nil {
return err
return fmt.Errorf("Store endpoint: %v", err)
}

err = urlParse(conf.Qed.Endpoints...)
if err != nil {
return err
return fmt.Errorf("QED endpoint: %v", err)
}

return nil
Expand Down
8 changes: 8 additions & 0 deletions cmd/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
errFQDNHyp = "labels cannot start or end with hyphens"
errTLDLen = "TLD length is not valid"
errTLDLet = "TLD allow only letters"
errAPIKeyEmpty = "empty value"
)

/*
Expand All @@ -63,6 +64,13 @@ upper case and a through z in lower case
<digit> ::= any one of the ten digits 0 through 9
*/

func checkAPIKey(s string) error {
if s == "" {
return fmt.Errorf("Missing Api-Key: %s", errAPIKeyEmpty)
}
return nil
}

func isHyphen(s rune) bool {
return s == '-'
}
Expand Down
82 changes: 82 additions & 0 deletions cmd/workload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A.
licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
you may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
withouT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
see the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"context"
"fmt"
"net/http"

"github.com/bbva/qed/log"
"github.com/bbva/qed/testutils/workload"
"github.com/octago/sflags/gen/gpflag"
"github.com/spf13/cobra"
)

func workloadConfig() context.Context {

conf := workload.DefaultConfig()

err := gpflag.ParseTo(conf, workloadCmd.PersistentFlags())
if err != nil {
log.Fatalf("err: %v", err)
}

return context.WithValue(Ctx, k("workload.config"), conf)
}

var workloadCmd *cobra.Command = &cobra.Command{
Use: "workload",
Short: "Workload tool for qed server",
Long: workload.WorkloadHelp,
TraverseChildren: true,
RunE: runWorkload,
}

var workloadCtx context.Context

func init() {
workloadCtx = workloadConfig()
Root.AddCommand(workloadCmd)
}

func runWorkload(cmd *cobra.Command, args []string) error {
config := workloadCtx.Value(k("workload.config")).(*workload.Config)

workload := workload.Workload{Config: *config}

log.SetLogger("workload", config.Log)

if workload.Config.Profiling {
go func() {
log.Info(" * Starting workload Profiling server at :6060")
log.Info(http.ListenAndServe(":6060", nil))
}()
}

if err := checkAPIKey(config.APIKey); err != nil {
return fmt.Errorf("%v", err)
}

if !config.APIMode && config.Kind == "" {
log.Fatal("Argument `kind` is required")
}

workload.Start(config.APIMode)

return nil
}
4 changes: 2 additions & 2 deletions deploy/aws/flavour.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resource null_resource "qed-base" {
triggers {
qed = "${format("%s",module.qed.private_ip)}"
prometheus = "${module.prometheus.private_ip}"
riot = "${module.riot.private_ip}"
workload = "${module.workload.private_ip}"
gateway = "${aws_internet_gateway.qed.id}"
aws_route = "${aws_route.qed.id}"
aws_vpc_dhcp_options = "${aws_vpc_dhcp_options.qed.id}"
Expand All @@ -35,7 +35,7 @@ resource null_resource "qed-full" {
triggers {
qed = "${format("%s",module.qed.private_ip)}"
prometheus = "${module.prometheus.private_ip}"
riot = "${module.riot.private_ip}"
workload = "${module.workload.private_ip}"
auditor = "${format("%s", module.agent-auditor.private_ip)}"
monitor = "${format("%s", module.agent-monitor.private_ip)}"
publisher = "${format("%s", module.agent-publisher.private_ip)}"
Expand Down
4 changes: 2 additions & 2 deletions deploy/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ module "prometheus" {
key_path = "${var.keypath}"
}

module "riot" {
source = "./modules/riot"
module "workload" {
source = "./modules/workload"

instance_type = "m5.large"
iam_instance_profile = "${aws_iam_instance_profile.qed-profile.name}"
Expand Down
7 changes: 0 additions & 7 deletions deploy/aws/modules/riot/outputs.tf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data "aws_ami" "amazon_linux" {
}
}

resource "aws_instance" "riot" {
resource "aws_instance" "workload" {
count = "1"
ami = "${data.aws_ami.amazon_linux.id}"
instance_type = "${var.instance_type}"
Expand All @@ -43,7 +43,7 @@ resource "aws_instance" "riot" {
}]

tags {
Name = "qed-riot"
Name = "qed-workload"
Role = "${var.role}"
DAM_OnOff = "NO"
Workspace = "${terraform.workspace}"
Expand Down
7 changes: 7 additions & 0 deletions deploy/aws/modules/workload/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "private_ip" {
value = "${aws_instance.workload.private_ip}"
}

output "public_ip" {
value = "${aws_instance.workload.public_ip}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ variable "path" {
}

variable "role" {
default = "riot"
default = "workload"
}

variable "endpoint" {}
Expand Down
4 changes: 2 additions & 2 deletions deploy/aws/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ output "prometheus" {
value = "${module.prometheus.public_ip}"
}

output "riot" {
value = "${module.riot.public_ip}"
output "workload" {
value = "${module.workload.public_ip}"
}

output "inmemory-storage" {
Expand Down
4 changes: 2 additions & 2 deletions deploy/aws/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ $ terraform workspace new <workspace_name>
$ terraform select <workspace_name>
```

## Deploy QED cluster with agents, storage, Riot and monitoring
## Deploy QED cluster with agents, storage, workload and monitoring
```
$ terraform apply -auto-approve
```
## Deploy QED cluster, Riot and monitoring
## Deploy QED cluster, workload and monitoring
```
$ terraform apply -target=null_resource.qed-base
```
Expand Down
11 changes: 9 additions & 2 deletions deploy/local/agents_start
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ QED="go run $GOPATH/src/github.com/bbva/qed/main.go"
# Agent options
AGENT_CONFIG=()
AGENT_CONFIG+=('--log debug')
AGENT_CONFIG+=('--bind-addr 127.0.0.1:810${i}')
AGENT_CONFIG+=('--metrics-addr 127.0.0.1:1810${i}')
AGENT_CONFIG+=('--start-join 127.0.0.1:8400')

# Notifier options
Expand All @@ -49,14 +47,23 @@ QED_CONFIG+=("--qed-endpoints http://127.0.0.1:8800")
MONITOR_CONFIG=("${AGENT_CONFIG[@]}" "${NOTIFIER_CONFIG[@]}" "${STORE_CONFIG[@]}" "${TASKS_CONFIG[@]}" "${QED_CONFIG[@]}")
MONITOR_CONFIG+=('--role monitor')
MONITOR_CONFIG+=('--node-name monitor${i}')
MONITOR_CONFIG+=('--bind-addr 127.0.0.1:810${i}')
MONITOR_CONFIG+=('--advertise-addr 127.0.0.1:810${i}')
MONITOR_CONFIG+=('--metrics-addr 127.0.0.1:1810${i}')

PUBLISHER_CONFIG=("${AGENT_CONFIG[@]}" "${NOTIFIER_CONFIG[@]}" "${STORE_CONFIG[@]}" "${TASKS_CONFIG[@]}" )
PUBLISHER_CONFIG+=('--role publisher')
PUBLISHER_CONFIG+=('--node-name publisher${i}')
PUBLISHER_CONFIG+=('--bind-addr 127.0.0.1:811${i}')
PUBLISHER_CONFIG+=('--advertise-addr 127.0.0.1:811${i}')
PUBLISHER_CONFIG+=('--metrics-addr 127.0.0.1:1811${i}')

AUDITOR_CONFIG=("${AGENT_CONFIG[@]}" "${NOTIFIER_CONFIG[@]}" "${STORE_CONFIG[@]}" "${TASKS_CONFIG[@]}" "${QED_CONFIG[@]}")
AUDITOR_CONFIG+=('--role auditor')
AUDITOR_CONFIG+=('--node-name auditor${i}')
AUDITOR_CONFIG+=('--bind-addr 127.0.0.1:812${i}')
AUDITOR_CONFIG+=('--advertise-addr 127.0.0.1:812${i}')
AUDITOR_CONFIG+=('--metrics-addr 127.0.0.1:1821${i}')

start() {
local type="$1"
Expand Down
15 changes: 9 additions & 6 deletions testutils/riot/riot_start → deploy/local/workload_start
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# 1000 million requests
# Set compile flags
CGO_LDFLAGS_ALLOW='.*'
QED="go run $GOPATH/src/github.com/bbva/qed/main.go"
reqs=$((10**10))

go run riot.go --api \
-l debug \
--apikey key \
--n ${reqs} \
--endpoint "http://127.0.0.1:8800"
${QED} workload \
--api-mode \
--log debug \
--api-key key \
--num-requests ${reqs} \
--endpoints "http://127.0.0.1:8800"

0 comments on commit 2fd75b1

Please sign in to comment.