Skip to content

Commit

Permalink
Resolving merge conflict
Browse files Browse the repository at this point in the history
Signed-off-by: Raj Das <mail.rajdas@gmail.com>
  • Loading branch information
imrajdas committed Jun 18, 2020
2 parents f4c8b86 + 6af2fa5 commit 4cf5777
Show file tree
Hide file tree
Showing 33 changed files with 253 additions and 134 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ docker-manifest:
@echo skip manifest creation

.PHONY: docs
docs: build
docs:
./scripts/genflagdocs.sh

.PHONY: docs-check
Expand Down
4 changes: 2 additions & 2 deletions funcbench/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ clean: resource_delete cluster_delete

cluster_create:
$(INFRA_CMD) gke cluster create -a ${AUTH_FILE} \
-v PROJECT_ID:${PROJECT_ID} -v ZONE:${ZONE} -v CLUSTER_NAME:funcbench-${PR_NUMBER} \
-v PROJECT_ID:${PROJECT_ID} -v ZONE:${ZONE} -v CLUSTER_NAME:funcbench-${PR_NUMBER} -v PR_NUMBER:${PR_NUMBER} \
-f manifests/cluster.yaml

cluster_delete:
$(INFRA_CMD) gke cluster delete -a ${AUTH_FILE} \
-v PROJECT_ID:${PROJECT_ID} -v ZONE:${ZONE} -v CLUSTER_NAME:funcbench-${PR_NUMBER} \
-v PROJECT_ID:${PROJECT_ID} -v ZONE:${ZONE} -v CLUSTER_NAME:funcbench-${PR_NUMBER} -v PR_NUMBER:${PR_NUMBER} \
-f manifests/cluster.yaml

resource_apply:
Expand Down
14 changes: 7 additions & 7 deletions funcbench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ funcbench currently supports two modes, Local and GitHub. Running it in the Gith

> Clean git state is required.
[embedmd]: # "funcbench-flags.txt"

[embedmd]:# (funcbench-flags.txt)
```txt
usage: funcbench [<flags>] <target> [<bench-func-regex>]
Expand Down Expand Up @@ -47,11 +46,12 @@ Flags:
longer than duration d, panic.
Args:
<target> Can be one of '.', branch name or commit SHA of the
branch to compare against. If set to '.', branch/commit
is the same as the current one; funcbench will run once
and try to compare between 2 sub-benchmarks. Errors out
if there are no sub-benchmarks.
<target> Can be one of '.', tag name, branch name or commit SHA
of the branch to compare against. If set to '.',
branch/commit is the same as the current one; funcbench
will run once and try to compare between 2
sub-benchmarks. Errors out if there are no
sub-benchmarks.
[<bench-func-regex>] Function regex to use for benchmark.Supports RE2 regexp
and is fully anchored, by default will run all
benchmarks.
Expand Down
1 change: 0 additions & 1 deletion funcbench/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func newGitHubEnv(ctx context.Context, e environment, gc *gitHubClient, workspac
r, err := git.PlainCloneContext(ctx, fmt.Sprintf("%s/%s", workspace, gc.repo), false, &git.CloneOptions{
URL: fmt.Sprintf("https://github.com/%s/%s.git", gc.owner, gc.repo),
Progress: os.Stdout,
Depth: 1,
})
if err != nil {
return nil, errors.Wrap(err, "clone git repository")
Expand Down
56 changes: 21 additions & 35 deletions funcbench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -103,7 +102,7 @@ func main() {
"disabled if set to 0. If a test binary runs longer than duration d, panic.").
Short('d').Default("2h").DurationVar(&cfg.benchTimeout)

app.Arg("target", "Can be one of '.', branch name or commit SHA of the branch "+
app.Arg("target", "Can be one of '.', tag name, branch name or commit SHA of the branch "+
"to compare against. If set to '.', branch/commit is the same as the current one; "+
"funcbench will run once and try to compare between 2 sub-benchmarks. "+
"Errors out if there are no sub-benchmarks.").
Expand Down Expand Up @@ -215,14 +214,7 @@ func startBenchmark(
return nil, errors.Wrap(err, "not clean worktree")
}

// Get info about target.
targetCommit, compareWithItself, err := getTargetInfo(ctx, env.Repo(), env.CompareTarget())
if err != nil {
return nil, errors.Wrap(err, "getTargetInfo")
}
bench.logger.Println("Target:", targetCommit.String(), "Current Ref:", ref.Hash().String())

if compareWithItself {
if env.CompareTarget() == "." {
bench.logger.Println("Assuming sub-benchmarks comparison.")
subResult, err := bench.exec(ctx, wt.Filesystem.Root(), ref.Hash())
if err != nil {
Expand All @@ -236,6 +228,18 @@ func startBenchmark(
return cmps, nil
}

// Get info about target.
targetCommit := getTargetInfo(env.Repo(), env.CompareTarget())
if targetCommit == plumbing.ZeroHash {
return nil, fmt.Errorf("cannot find target %s", env.CompareTarget())
}

bench.logger.Println("Target:", targetCommit.String(), "Current Ref:", ref.Hash().String())

if targetCommit == ref.Hash() {
return nil, fmt.Errorf("target: %s is the same as current ref %s (or is on the same commit); No changes would be expected; Aborting", targetCommit, ref.String())
}

bench.logger.Println("Assuming comparing with target (clean workdir will be checked.)")

// Execute benchmark A.
Expand Down Expand Up @@ -285,33 +289,15 @@ func interrupt(logger Logger, cancel <-chan struct{}) error {
}
}

// getTargetInfo returns the hash of the target,
// if target is the same as the current ref, set compareWithItself to true.
func getTargetInfo(ctx context.Context, repo *git.Repository, target string) (ref plumbing.Hash, compareWithItself bool, _ error) {
if target == "." {
return plumbing.Hash{}, true, nil
}

currRef, err := repo.Head()
// getTargetInfo returns the hash of the target if found,
// otherwise returns plumbing.ZeroHash.
// NOTE: if both a branch and a tag have the same name, it always chooses the branch name.
func getTargetInfo(repo *git.Repository, target string) plumbing.Hash {
hash, err := repo.ResolveRevision(plumbing.Revision(target))
if err != nil {
return plumbing.ZeroHash, false, err
return plumbing.ZeroHash
}

if target == strings.TrimPrefix(currRef.Name().String(), "refs/heads/") || target == currRef.Hash().String() {
return currRef.Hash(), true, errors.Errorf("target: %s is the same as current ref %s (or is on the same commit); No changes would be expected; Aborting", target, currRef.String())
}

commitHash := plumbing.NewHash(target)
if !commitHash.IsZero() {
return commitHash, false, nil
}

targetRef, err := repo.Reference(plumbing.NewBranchReferenceName(target), false)
if err != nil {
return plumbing.ZeroHash, false, err
}

return targetRef.Hash(), false, nil
return *hash
}

type commander struct {
Expand Down
32 changes: 32 additions & 0 deletions funcbench/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ package main

import (
"testing"

fixtures "gopkg.in/src-d/go-git-fixtures.v3"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
)

func TestMarkdownFormatting(t *testing.T) {
Expand Down Expand Up @@ -49,3 +55,29 @@ BenchmarkBufferedSeriesIterator-8 0 0 +0.00%`
t.Errorf("Output did not match.\ngot:\n%#v\nwant:\n%#v", formattedTable, expectedTable)
}
}

func TestGetTargetInfo(t *testing.T) {
_ = fixtures.Init()
f := fixtures.Basic().One()
sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
r, err := git.Open(sto, f.DotGit())
if err != nil {
t.Errorf("error when open repository: %s", err)
}

testCases := map[string]string{
"notFound": plumbing.ZeroHash.String(),
"HEAD": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
"master": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
"branch": "e8d3ffab552895c19b9fcf7aa264d277cde33881",
"v1.0.0": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
"918c48b83bd081e863dbe1b80f8998f058cd8294": "918c48b83bd081e863dbe1b80f8998f058cd8294",
}

for target, hash := range testCases {
commit := getTargetInfo(r, target)
if commit.String() != hash {
t.Errorf("error when get target %s, expect %s, got %s", target, hash, commit)
}
}
}
2 changes: 1 addition & 1 deletion funcbench/manifests/benchmark/2_job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ spec:
- name: GITHUB_TOKEN
value: "{{ .GITHUB_TOKEN }}"
nodeSelector:
cloud.google.com/gke-nodepool: funcbench-{{ .PR_NUMBER }}
node-name: funcbench-{{ .PR_NUMBER }}
4 changes: 3 additions & 1 deletion funcbench/manifests/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ projectid: {{ .PROJECT_ID }}
zone: {{ .ZONE }}
cluster:
name: {{ .CLUSTER_NAME }}
initialclusterversion: 1.15
initialclusterversion: 1.16
nodepools:
- name: {{ .CLUSTER_NAME }}
initialnodecount: 1
config:
machinetype: n1-highmem-4
imagetype: COS
disksizegb: 100
labels:
node-name: funcbench-{{ .PR_NUMBER }}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940
google.golang.org/grpc v1.28.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/src-d/go-git-fixtures.v3 v3.5.0
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v2 v2.3.0
k8s.io/api v0.18.4
Expand Down
3 changes: 1 addition & 2 deletions infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Eg. `somefile.yaml` will be parsed, whereas `somefile_noparse.yaml` will not be

## Usage and examples:

[embedmd]: # "./infra-flags.txt"

[embedmd]:# (infra-flags.txt)
```txt
usage: infra [<flags>] <command> [<args> ...]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ spec:
successThreshold: 1
timeoutSeconds: 10
nodeSelector:
cloud.google.com/gke-nodepool: main-node
node-name: main-node

---
kind: Service
Expand Down
2 changes: 1 addition & 1 deletion prombench/manifests/cluster-infra/3b_prometheus-meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ spec:
claimName: prometheus-meta
terminationGracePeriodSeconds: 300
nodeSelector:
cloud.google.com/gke-nodepool: main-node
node-name: main-node
---
apiVersion: v1
kind: Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ spec:
claimName: prometheus-meta
terminationGracePeriodSeconds: 300
nodeSelector:
cloud.google.com/gke-nodepool: main-node
node-name: main-node
---
apiVersion: v1
kind: Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec:
secretName: oauth-token
terminationGracePeriodSeconds: 300
nodeSelector:
cloud.google.com/gke-nodepool: main-node
node-name: main-node
---
apiVersion: v1
kind: Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ spec:
securityContext:
readOnlyRootFilesystem: true
nodeSelector:
cloud.google.com/gke-nodepool: main-node
node-name: main-node
terminationGracePeriodSeconds: 30
volumes:
- name: config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ spec:
successThreshold: 1
timeoutSeconds: 1
nodeSelector:
cloud.google.com/gke-nodepool: main-node
node-name: main-node
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ data:
eventmap.yml: |
- event_type: prombench_start
regex_string: (?mi)^/prombench\s*(?P<RELEASE>master|v[0-9]+\.[0-9]+\.[0-9]+\S*)\s*$
label: prombench
comment_template: |
⏱️ Welcome to Prometheus Benchmarking Tool. ⏱️
Expand Down Expand Up @@ -51,6 +52,7 @@ data:
- event_type: funcbench_start
regex_string: (?m)^/funcbench[[:blank:]]+(?P<BRANCH>[\w\-\/\.]+)[[:blank:]]*(?P<BENCH_FUNC_REGEX>(?:Benchmark\w*)?(?:\.\*)?)?[[:blank:]]*$
label: funcbench
comment_template: |
⏱️ Welcome to Funcbench Tool. ⏱️
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ spec:
args:
- "--eventmap=/etc/cm/eventmap.yml"
- "--webhooksecretfile=/etc/github/whsecret"
- "--command-prefix=/prombench"
- "--command-prefix=/funcbench"
name: comment-monitor
env:
- name: DOMAIN_NAME
value: {{ .DOMAIN_NAME }}
- name: LABEL_NAME
value: prombench
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
Expand All @@ -49,7 +49,7 @@ spec:
name: comment-monitor-eventmap
terminationGracePeriodSeconds: 300
nodeSelector:
cloud.google.com/gke-nodepool: main-node
node-name: main-node
---
apiVersion: v1
kind: Service
Expand Down
2 changes: 1 addition & 1 deletion prombench/manifests/cluster-infra/grafana_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ spec:
configMap:
name: grafana-dashboards
nodeSelector:
cloud.google.com/gke-nodepool: main-node
node-name: main-node
---
apiVersion: v1
kind: Service
Expand Down
2 changes: 1 addition & 1 deletion prombench/manifests/cluster-infra/node-exporter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
hostNetwork: true
hostPID: true
nodeSelector:
cloud.google.com/gke-nodepool: main-node
node-name: main-node
containers:
- image: quay.io/prometheus/node-exporter:v0.16.0
args:
Expand Down
4 changes: 2 additions & 2 deletions prombench/manifests/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ cluster:
name: {{ .CLUSTER_NAME }}
initialclusterversion: 1.14
nodepools:
# GKE creates a label on every node in a pool
# cloud.google.com/gke-nodepool: <NODEPOOL_NAME>
# This node-pool will be used for running monitoring components
- name: main-node
initialnodecount: 1
config:
machinetype: n1-standard-4
imagetype: COS
disksizegb: 300
labels:
node-name: main-node
4 changes: 2 additions & 2 deletions prombench/manifests/prombench/benchmark/2_fake-webserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ data:
- name: metrics5
containerPort: 8084
nodeSelector:
cloud.google.com/gke-nodepool: nodes-{{ .PR_NUMBER }}
node-name: nodes-{{ .PR_NUMBER }}
isolation: none
---
apiVersion: apps/v1
Expand Down Expand Up @@ -70,7 +70,7 @@ spec:
- name: metrics5
containerPort: 8084
nodeSelector:
cloud.google.com/gke-nodepool: nodes-{{ .PR_NUMBER }}
node-name: nodes-{{ .PR_NUMBER }}
isolation: none
---
apiVersion: v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ spec:
emptyDir: {}
terminationGracePeriodSeconds: 300
nodeSelector:
cloud.google.com/gke-nodepool: prometheus-{{ .PR_NUMBER }}
node-name: prometheus-{{ .PR_NUMBER }}
isolation: prometheus
---
apiVersion: v1
Expand Down Expand Up @@ -178,7 +178,7 @@ spec:
path: /mnt/disks/ssd0
terminationGracePeriodSeconds: 300
nodeSelector:
cloud.google.com/gke-nodepool: prometheus-{{ .PR_NUMBER }}
node-name: prometheus-{{ .PR_NUMBER }}
isolation: prometheus
---
apiVersion: v1
Expand Down
Loading

0 comments on commit 4cf5777

Please sign in to comment.