diff --git a/.circleci/config.yml b/.circleci/config.yml index abbf4c81c..50392b166 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ defaults: &defaults client-defaults: &client-defaults working_directory: /home/weave/scope docker: - - image: weaveworks/scope-ui-build:master-fda40b83 + - image: weaveworks/scope-ui-build:master-c0b60a16 workflows: version: 2 @@ -62,26 +62,52 @@ jobs: <<: *client-defaults steps: - checkout - # Convoluted set of steps here to mimic Makefile actions of bind-mounting different dirs into container - - run: mv client/app /home/weave/ - - run: cd /home/weave; mkdir build ; yarn run build ; mv build scope/client - - run: cd /home/weave; mkdir build-external; yarn run build-external; mv build-external scope/client - - run: cd /home/weave; mkdir tmp ; yarn run bundle ; mv tmp scope + - restore_cache: + name: Restoring Yarn Cache + key: yarn-cache-2-{{ checksum "client/yarn.lock" }} + - restore_cache: + name: Restoring client/node_modules + key: node-modules-{{ checksum "client/yarn.lock" }}-{{ checksum ".circleci/config.yml" }} + - run: cd client; yarn install + - save_cache: + name: Saving Yarn Cache + key: yarn-cache-2-{{ checksum "client/yarn.lock" }} + paths: + - "/home/weave/scope/.cache/yarn" + - save_cache: + name: Saving client/node_modules + # include the CI config in the checksum because it will change when the docker image changes + key: node-modules-{{ checksum "client/yarn.lock" }}-{{ checksum ".circleci/config.yml" }} + paths: + - "/home/weave/scope/client/node_modules" + - run: | + cd client + yarn run build + yarn run build-external + yarn run bundle - persist_to_workspace: root: /home/weave/scope paths: - client/build/ - client/build-external/ - - tmp/weave-scope.tgz + - client/bundle/weave-scope.tgz + client-test: <<: *client-defaults steps: - checkout + - restore_cache: + name: Restoring Yarn Cache + key: yarn-cache-2-{{ checksum "client/yarn.lock" }} + - restore_cache: + name: Restoring client/node_modules + key: node-modules-{{ checksum "client/yarn.lock" }}-{{ checksum ".circleci/config.yml" }} - run: | - mv client/app client/test /home/weave/ - cd /home/weave; yarn run lint - cd /home/weave; yarn test + cd client + yarn install + yarn run lint + yarn test xplatform-build: <<: *defaults diff --git a/.gitignore b/.gitignore index 061010ce1..5a0d74c59 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,7 @@ client/build-external/* prog/staticui/* prog/externalui/* client/build-pkg +client/bundle # Website site-build diff --git a/LICENSE b/LICENSE index e21766f6d..0eb9687b6 100644 --- a/LICENSE +++ b/LICENSE @@ -176,7 +176,7 @@ END OF TERMS AND CONDITIONS - Copyright 2014-2017 Weaveworks Ltd. + Copyright 2014-2018 Weaveworks Ltd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Makefile b/Makefile index f42be4121..608b00e90 100644 --- a/Makefile +++ b/Makefile @@ -143,51 +143,91 @@ endif ifeq ($(BUILD_IN_CONTAINER),true) -client/build/index.html: $(shell find client/app -type f) $(SCOPE_UI_BUILD_UPTODATE) +SCOPE_UI_TOOLCHAIN=.cache/build_node_modules +SCOPE_UI_TOOLCHAIN_UPTODATE=$(SCOPE_UI_TOOLCHAIN)/.uptodate + +$(SCOPE_UI_TOOLCHAIN_UPTODATE): client/yarn.lock $(SCOPE_UI_BUILD_UPTODATE) + mkdir -p $(SCOPE_UI_TOOLCHAIN) client/node_modules + if test "true" != "$(SCOPE_SKIP_UI_ASSETS)"; then \ + $(SUDO) docker run $(RM) $(RUN_FLAGS) \ + -v $(shell pwd)/.cache:/home/weave/scope/.cache \ + -v $(shell pwd)/client:/home/weave/scope/client \ + -v $(shell pwd)/$(SCOPE_UI_TOOLCHAIN):/home/weave/scope/client/node_modules \ + -w /home/weave/scope/client \ + $(SCOPE_UI_BUILD_IMAGE) yarn install; \ + fi + touch $(SCOPE_UI_TOOLCHAIN_UPTODATE) + +client/build/index.html: $(shell find client/app -type f) $(SCOPE_UI_TOOLCHAIN_UPTODATE) mkdir -p client/build if test "true" != "$(SCOPE_SKIP_UI_ASSETS)"; then \ - $(SUDO) docker run $(RM) $(RUN_FLAGS) -v $(shell pwd)/client/app:/home/weave/app \ - -v $(shell pwd)/client/build:/home/weave/build \ + $(SUDO) docker run $(RM) $(RUN_FLAGS) \ + -v $(shell pwd)/.cache:/home/weave/scope/.cache \ + -v $(shell pwd)/client:/home/weave/scope/client \ + -v $(shell pwd)/$(SCOPE_UI_TOOLCHAIN):/home/weave/scope/client/node_modules \ + -w /home/weave/scope/client \ $(SCOPE_UI_BUILD_IMAGE) yarn run build; \ fi -client/build-external/index.html: $(shell find client/app -type f) $(SCOPE_UI_BUILD_UPTODATE) +client/build-external/index.html: $(shell find client/app -type f) $(SCOPE_UI_TOOLCHAIN_UPTODATE) mkdir -p client/build-external if test "true" != "$(SCOPE_SKIP_UI_ASSETS)"; then \ - $(SUDO) docker run $(RM) $(RUN_FLAGS) -v $(shell pwd)/client/app:/home/weave/app \ - -v $(shell pwd)/client/build-external:/home/weave/build-external \ + $(SUDO) docker run $(RM) $(RUN_FLAGS) \ + -v $(shell pwd)/.cache:/home/weave/scope/.cache \ + -v $(shell pwd)/client:/home/weave/scope/client \ + -v $(shell pwd)/$(SCOPE_UI_TOOLCHAIN):/home/weave/scope/client/node_modules \ + -w /home/weave/scope/client \ $(SCOPE_UI_BUILD_IMAGE) yarn run build-external; \ fi -client-test: $(shell find client/app/scripts -type f) $(SCOPE_UI_BUILD_UPTODATE) - $(SUDO) docker run $(RM) $(RUN_FLAGS) -v $(shell pwd)/client/app:/home/weave/app \ - -v $(shell pwd)/client/test:/home/weave/test \ +client-test: $(shell find client/app/scripts -type f) $(SCOPE_UI_TOOLCHAIN_UPTODATE) + $(SUDO) docker run $(RM) $(RUN_FLAGS) \ + -v $(shell pwd)/.cache:/home/weave/scope/.cache \ + -v $(shell pwd)/client/client:/home/weave/scope/client \ + -v $(shell pwd)/$(SCOPE_UI_TOOLCHAIN):/home/weave/scope/client/node_modules \ + -w /home/weave/scope/client \ $(SCOPE_UI_BUILD_IMAGE) yarn test -client-lint: $(SCOPE_UI_BUILD_UPTODATE) - $(SUDO) docker run $(RM) $(RUN_FLAGS) -v $(shell pwd)/client/app:/home/weave/app \ - -v $(shell pwd)/client/test:/home/weave/test \ +client-lint: $(SCOPE_UI_TOOLCHAIN_UPTODATE) + $(SUDO) docker run $(RM) $(RUN_FLAGS) \ + -v $(shell pwd)/.cache:/home/weave/scope/.cache \ + -v $(shell pwd)/client:/home/weave/scope/client \ + -v $(shell pwd)/$(SCOPE_UI_TOOLCHAIN):/home/weave/scope/client/node_modules \ + -w /home/weave/scope/client \ $(SCOPE_UI_BUILD_IMAGE) yarn run lint -client-start: $(SCOPE_UI_BUILD_UPTODATE) - $(SUDO) docker run $(RM) $(RUN_FLAGS) --net=host -v $(shell pwd)/client/app:/home/weave/app \ - -v $(shell pwd)/client/build:/home/weave/build -e WEBPACK_SERVER_HOST \ +client-start: $(SCOPE_UI_TOOLCHAIN_UPTODATE) + $(SUDO) docker run $(RM) $(RUN_FLAGS) --net=host \ + -v $(shell pwd)/.cache:/home/weave/scope/.cache \ + -v $(shell pwd)/client:/home/weave/scope/client \ + -v $(shell pwd)/$(SCOPE_UI_TOOLCHAIN):/home/weave/scope/client/node_modules \ + -e WEBPACK_SERVER_HOST \ + -w /home/weave/scope/client \ $(SCOPE_UI_BUILD_IMAGE) yarn start -tmp/weave-scope.tgz: $(shell find client/app -type f) $(SCOPE_UI_BUILD_UPTODATE) +client/bundle/weave-scope.tgz: $(shell find client/app -type f) $(SCOPE_UI_TOOLCHAIN_UPTODATE) $(sudo) docker run $(RUN_FLAGS) \ - -v $(shell pwd)/client/app:/home/weave/app \ - -v $(shell pwd)/tmp:/home/weave/tmp \ - $(SCOPE_UI_BUILD_IMAGE) \ - yarn run bundle + -v $(shell pwd)/.cache:/home/weave/scope/.cache \ + -v $(shell pwd)/client:/home/weave/scope/client \ + -v $(shell pwd)/$(SCOPE_UI_TOOLCHAIN):/home/weave/scope/client/node_modules \ + -v $(shell pwd)/tmp:/home/weave/tmp \ + -w /home/weave/scope/client \ + $(SCOPE_UI_BUILD_IMAGE) yarn run bundle else -client/build/index.html: +SCOPE_UI_TOOLCHAIN=client/node_modules +SCOPE_UI_TOOLCHAIN_UPTODATE=$(SCOPE_UI_TOOLCHAIN)/.uptodate + +$(SCOPE_UI_TOOLCHAIN_UPTODATE): client/yarn.lock + if test "true" = "$(SCOPE_SKIP_UI_ASSETS)"; then mkdir -p $(SCOPE_UI_TOOLCHAIN); else cd client && yarn install; fi + touch $(SCOPE_UI_TOOLCHAIN_UPTODATE) + +client/build/index.html: $(SCOPE_UI_TOOLCHAIN_UPTODATE) mkdir -p client/build if test "true" != "$(SCOPE_SKIP_UI_ASSETS)"; then cd client && yarn run build; fi -client/build-external/index.html: +client/build-external/index.html: $(SCOPE_UI_TOOLCHAIN_UPTODATE) mkdir -p client/build-external if test "true" != "$(SCOPE_SKIP_UI_ASSETS)"; then cd client && yarn run build-external; fi @@ -208,10 +248,10 @@ ui-upload: client/build-external/index.html AWS_SECRET_ACCESS_KEY=$$UI_BUCKET_KEY_SECRET \ aws s3 cp client/build-external/ s3://static.weave.works/scope-ui/ --recursive --exclude '*.html' -ui-pkg-upload: tmp/weave-scope.tgz +ui-pkg-upload: client/bundle/weave-scope.tgz AWS_ACCESS_KEY_ID=$$UI_BUCKET_KEY_ID \ AWS_SECRET_ACCESS_KEY=$$UI_BUCKET_KEY_SECRET \ - aws s3 cp tmp/weave-scope.tgz s3://weaveworks-js-modules/weave-scope/$(shell echo $(SCOPE_VERSION))/weave-scope.tgz + aws s3 cp client/bundle/weave-scope.tgz s3://weaveworks-js-modules/weave-scope/$(shell echo $(SCOPE_VERSION))/weave-scope.tgz # We don't rmi images here; rm'ing the .uptodate files is enough to # get the build images rebuilt, and rm'ing the scope exe is enough to @@ -220,7 +260,7 @@ ui-pkg-upload: tmp/weave-scope.tgz # rmi'ng images is desirable sometimes. Invoke `realclean` for that. clean: $(GO) clean ./... - rm -rf $(SCOPE_EXPORT) $(SCOPE_UI_BUILD_UPTODATE) $(SCOPE_BACKEND_BUILD_UPTODATE) \ + rm -rf $(SCOPE_EXPORT) $(SCOPE_UI_BUILD_UPTODATE) $(SCOPE_UI_TOOLCHAIN_UPTODATE) $(SCOPE_BACKEND_BUILD_UPTODATE) \ $(SCOPE_EXE) $(RUNSVINIT) prog/staticui/staticui.go prog/externalui/externalui.go client/build/*.js client/build-external/*.js docker/weave .pkg \ $(CODECGEN_TARGETS) $(CODECGEN_DIR)/bin @@ -236,6 +276,7 @@ clean-codecgen: # # Doing this is important for release builds. realclean: clean + rm -rf $(SCOPE_UI_TOOLCHAIN) $(SUDO) docker rmi -f $(SCOPE_UI_BUILD_IMAGE) $(SCOPE_BACKEND_BUILD_IMAGE) \ $(DOCKERHUB_USER)/scope $(DOCKERHUB_USER)/cloud-agent \ $(DOCKERHUB_USER)/scope:$(IMAGE_TAG) $(DOCKERHUB_USER)/cloud-agent:$(IMAGE_TAG) \ diff --git a/README.md b/README.md index 051887fee..2d79c3245 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ [![GoDoc](https://godoc.org/github.com/weaveworks/scope?status.svg)](https://godoc.org/github.com/weaveworks/scope) Weave Scope automatically generates a map of your application, enabling you to -intuitively understand, monitor, and control your containerized, microservices based application. +intuitively understand, monitor, and control your containerized, microservices-based application. -### Understand your Docker containers in real-time +### Understand your Docker containers in real time Map you architecture @@ -20,19 +20,19 @@ Choose an overview of your container infrastructure, or focus on a specific micr Focus on a single container -View contextual metrics, tags and metadata for your containers. Effortlessly navigate between processes inside your container to hosts your containers run on, arranged in expandable, sortable tables. Easily find the container using the most CPU or memory for a given host or service. +View contextual metrics, tags, and metadata for your containers. Effortlessly navigate between processes inside your container to hosts your containers run on, arranged in expandable, sortable tables. Easily find the container using the most CPU or memory for a given host or service. ### Interact with and manage containers Launch a command line. -Interact with your containers directly: pause, restart and stop containers. Launch a command line. All without leaving the scope browser window. +Interact with your containers directly: pause, restart, and stop containers. Launch a command line. All without leaving the scope browser window. ### Extend and customize via plugins -Add custom details or interactions for your hosts, containers and/or processes by creating Scope plugins; or just choose from some that others have already written at the Github [Weaveworks Scope Plugins](https://github.com/weaveworks-plugins/) organization. +Add custom details or interactions for your hosts, containers, and/or processes by creating Scope plugins. Or, just choose from some that others have already written at the GitHub [Weaveworks Scope Plugins](https://github.com/weaveworks-plugins/) organization. -## Getting started +## Getting Started ```console sudo curl -L git.io/scope -o /usr/local/bin/scope @@ -44,18 +44,18 @@ This script downloads and runs a recent Scope image from Docker Hub. Now, open your web browser to **http://localhost:4040**. (If you're using boot2docker, replace localhost with the output of `boot2docker ip`.) -For instructions on installing Scope on [Kubernetes](https://www.weave.works/docs/scope/latest/installing/#k8s), [DCOS](https://www.weave.works/docs/scope/latest/installing/#dcos) or [ECS](https://www.weave.works/docs/scope/latest/installing/#ecs), see [the docs](https://www.weave.works/docs/scope/latest/introducing/). +For instructions on installing Scope on [Kubernetes](https://www.weave.works/docs/scope/latest/installing/#k8s), [DCOS](https://www.weave.works/docs/scope/latest/installing/#dcos), or [ECS](https://www.weave.works/docs/scope/latest/installing/#ecs), see [the docs](https://www.weave.works/docs/scope/latest/introducing/). -## Getting help +## Getting Help -If you have any questions about, feedback for or problems with Scope: +If you have any questions, feedback, or problems with Scope: - Read [the Weave Scope docs](https://www.weave.works/docs/scope/latest/introducing/). -- Invite yourself to the Weave community slack. -- Ask a question on the [#scope](https://weave-community.slack.com/messages/scope/) slack channel. +- Invite yourself to the Weave community Slack. +- Ask a question on the [#scope](https://weave-community.slack.com/messages/scope/) Slack channel. - Join the [Weave User Group](https://www.meetup.com/pro/Weave/) and get invited to online talks, hands-on training and meetups in your area. - Send an email to [Scope community group](https://groups.google.com/forum/#!forum/scope-community). - Join (and read up on) the regular [Scope community meetings](https://docs.google.com/document/d/103_60TuEkfkhz_h2krrPJH8QOx-vRnPpbcCZqrddE1s/edit). - [File an issue](https://github.com/weaveworks/scope/issues/new). -Your feedback is always welcome! \ No newline at end of file +Your feedback is always welcome! diff --git a/app/router.go b/app/router.go index 28ad84c5a..c3347092c 100644 --- a/app/router.go +++ b/app/router.go @@ -43,7 +43,7 @@ type CtxHandlerFunc func(context.Context, http.ResponseWriter, *http.Request) func requestContextDecorator(f CtxHandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - ctx := context.WithValue(context.Background(), RequestCtxKey, r) + ctx := context.WithValue(r.Context(), RequestCtxKey, r) f(ctx, w, r) } } diff --git a/backend/Dockerfile b/backend/Dockerfile index 48d932d43..952a30643 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -19,7 +19,7 @@ RUN go clean -i net && \ fi; \ go get -tags netgo \ github.com/fzipp/gocyclo \ - github.com/golang/lint/golint \ + golang.org/x/lint/golint \ github.com/kisielk/errcheck \ github.com/fatih/hclfmt \ github.com/mjibson/esc \ diff --git a/client/Dockerfile b/client/Dockerfile index 4c19dc2f2..c71ea6327 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -1,13 +1,14 @@ +# Changes to this file will not take effect in CI +# until the image version in the CI config is updated. See +# https://github.com/weaveworks/scope/blob/master/.circleci/config.yml#L11 FROM node:8.11 -WORKDIR /home/weave -COPY package.json yarn.lock /home/weave/ -ENV NPM_CONFIG_LOGLEVEL=warn NPM_CONFIG_PROGRESS=false -RUN yarn --pure-lockfile -COPY webpack.local.config.js webpack.production.config.js server.js .babelrc .eslintrc .eslintignore .stylelintrc .sass-lint.yml /home/weave/ +ENV NPM_CONFIG_LOGLEVEL=warn +ENV NPM_CONFIG_PROGRESS=false +ENV XDG_CACHE_HOME=/home/weave/scope/.cache ARG revision LABEL maintainer="Weaveworks " \ - org.opencontainers.image.title="client" \ + org.opencontainers.image.title="scope-ui-build" \ org.opencontainers.image.source="https://github.com/weaveworks/scope" \ org.opencontainers.image.revision="${revision}" \ org.opencontainers.image.vendor="Weaveworks" diff --git a/client/app/scripts/components/view-mode-selector.js b/client/app/scripts/components/view-mode-selector.js index b915bae3a..0451ae0bf 100644 --- a/client/app/scripts/components/view-mode-selector.js +++ b/client/app/scripts/components/view-mode-selector.js @@ -29,7 +29,7 @@ class ViewModeSelector extends React.Component {
diff --git a/client/app/styles/contrast.scss b/client/app/styles/contrast.scss index 2862d3842..7533c1d9d 100644 --- a/client/app/styles/contrast.scss +++ b/client/app/styles/contrast.scss @@ -1,3 +1,4 @@ @import "variables"; @import "contrast-overrides"; @import "base"; +@import "terminal"; diff --git a/client/package.json b/client/package.json index 84358a277..ee9b7c574 100644 --- a/client/package.json +++ b/client/package.json @@ -102,7 +102,7 @@ "build-external": "EXTERNAL=true webpack --config webpack.production.config.js", "copy-pkg-files": "cp package.json build-pkg/ && cp -R app/styles build-pkg/", "build-pkg": "mkdir -p build-pkg && node node_modules/.bin/babel app/scripts --ignore __tests__ --out-dir build-pkg && yarn run copy-pkg-files", - "bundle": "yarn run build-pkg && cd ./build-pkg && yarn pack --filename ../tmp/weave-scope.tgz", + "bundle": "mkdir -p bundle && yarn run build-pkg && cd ./build-pkg && yarn pack --filename ../bundle/weave-scope.tgz", "start": "node server.js", "start-production": "NODE_ENV=production node server.js", "test": "jest", diff --git a/docker/Dockerfile.cloud-agent b/docker/Dockerfile.cloud-agent index 627fcfa2b..8f7434854 100644 --- a/docker/Dockerfile.cloud-agent +++ b/docker/Dockerfile.cloud-agent @@ -2,7 +2,6 @@ FROM alpine:3.7 WORKDIR /home/weave RUN apk add --update bash conntrack-tools iproute2 util-linux curl && \ rm -rf /var/cache/apk/* -ADD ./weave ./weaveutil /usr/bin/ COPY ./scope /home/weave/ ENTRYPOINT ["/home/weave/scope", "--mode=probe", "--no-app", "--probe.docker=true"] diff --git a/docker/Dockerfile.scope b/docker/Dockerfile.scope index 9f2dc2851..7e0af4571 100644 --- a/docker/Dockerfile.scope +++ b/docker/Dockerfile.scope @@ -2,6 +2,7 @@ FROM weaveworks/cloud-agent RUN apk add --update runit && \ rm -rf /var/cache/apk/* ADD ./demo.json / +ADD ./weave ./weaveutil /usr/bin/ COPY ./runsvinit ./entrypoint.sh /home/weave/ COPY ./run-app /etc/service/app/run COPY ./run-probe /etc/service/probe/run diff --git a/examples/k8s/cluster-role.yaml b/examples/k8s/cluster-role.yaml index 5f70075ef..391d175b5 100644 --- a/examples/k8s/cluster-role.yaml +++ b/examples/k8s/cluster-role.yaml @@ -51,6 +51,14 @@ rules: verbs: - list - watch +- apigroups: + - extensions + resourcenames: + - weave-scope + resources: + - podsecuritypolicies + verbs: + - use - apiGroups: - volumesnapshot.external-storage.k8s.io resources: @@ -58,4 +66,4 @@ rules: - volumesnapshotdatas verbs: - list - - watch + - watch \ No newline at end of file diff --git a/examples/k8s/psp.yaml b/examples/k8s/psp.yaml new file mode 100644 index 000000000..555a7c027 --- /dev/null +++ b/examples/k8s/psp.yaml @@ -0,0 +1,21 @@ +apiVersion: extensions/v1beta1 +kind: PodSecurityPolicy +metadata: + name: weave-scope +spec: + privileged: true + hostPID: true + hostNetwork: true + allowedCapabilities: + - 'NET_ADMIN' + fsGroup: + rule: RunAsAny + runAsUser: + rule: RunAsAny + seLinux: + rule: RunAsAny + supplementalGroups: + rule: RunAsAny + volumes: + - secret + - hostPath \ No newline at end of file diff --git a/probe/cri/registry_test.go b/probe/cri/registry_test.go new file mode 100644 index 000000000..916f06e4f --- /dev/null +++ b/probe/cri/registry_test.go @@ -0,0 +1,21 @@ +package cri_test + +import ( + "testing" + + "github.com/bmizerany/assert" + "github.com/weaveworks/scope/probe/cri" +) + +func TestParseHttpEndpointUrl(t *testing.T) { + _, err := cri.NewCRIClient("http://xyz.com") + + assert.Equal(t, "protocol \"http\" not supported", err.Error()) +} + +func TestParseTcpEndpointUrl(t *testing.T) { + client, err := cri.NewCRIClient("127.0.0.1") + + assert.Equal(t, nil, err) + assert.NotEqual(t, nil, client) +} diff --git a/probe/kubernetes/reporter.go b/probe/kubernetes/reporter.go index 3bc120cd4..29493c54a 100644 --- a/probe/kubernetes/reporter.go +++ b/probe/kubernetes/reporter.go @@ -210,6 +210,10 @@ func (r *Reporter) Stop() { func (Reporter) Name() string { return "K8s" } func (r *Reporter) podEvent(e Event, pod Pod) { + // filter out non-local pods, if we have been given a node name to report on + if r.nodeName != "" && pod.NodeName() != r.nodeName { + return + } switch e { case ADD: rpt := report.MakeReport() diff --git a/probe/probe.go b/probe/probe.go index b34f21cde..4e9bac59e 100644 --- a/probe/probe.go +++ b/probe/probe.go @@ -1,17 +1,20 @@ package probe import ( + "context" "sync" "time" "github.com/armon/go-metrics" log "github.com/sirupsen/logrus" + "golang.org/x/time/rate" "github.com/weaveworks/scope/report" ) const ( - reportBufferSize = 16 + spiedReportBufferSize = 16 + shortcutReportBufferSize = 1024 ) // ReportPublisher publishes reports, probably to a remote collector. @@ -23,6 +26,7 @@ type ReportPublisher interface { type Probe struct { spyInterval, publishInterval time.Duration publisher ReportPublisher + rateLimiter *rate.Limiter noControls bool tickers []Ticker @@ -79,10 +83,11 @@ func New( spyInterval: spyInterval, publishInterval: publishInterval, publisher: publisher, + rateLimiter: rate.NewLimiter(rate.Every(publishInterval/100), 1), noControls: noControls, quit: make(chan struct{}), - spiedReports: make(chan report.Report, reportBufferSize), - shortcutReports: make(chan report.Report, reportBufferSize), + spiedReports: make(chan report.Report, spiedReportBufferSize), + shortcutReports: make(chan report.Report, shortcutReportBufferSize), } return result } @@ -197,6 +202,7 @@ func (p *Probe) tag(r report.Report) report.Report { } func (p *Probe) drainAndPublish(rpt report.Report, rs chan report.Report) { + p.rateLimiter.Wait(context.Background()) ForLoop: for { select { diff --git a/probe/process/walker_linux.go b/probe/process/walker_linux.go index 05240bd97..b0cad69cd 100644 --- a/probe/process/walker_linux.go +++ b/probe/process/walker_linux.go @@ -3,6 +3,7 @@ package process import ( "bytes" "encoding/binary" + "errors" "fmt" "os" "path" @@ -31,6 +32,8 @@ var ( // key: filename in /proc. Example: "42" // value: two strings separated by a '\0' cmdlineCache = freecache.NewCache(1024 * 16) + + errDeadProcess = errors.New("The process is dead") ) const ( @@ -75,6 +78,7 @@ func readStats(path string) (ppid, threads int, jiffies, rss, rssLimit uint64, e const ( // /proc//stat field positions, counting from zero // see "man 5 proc" + procStatFieldState int = 2 procStatFieldPpid int = 3 procStatFieldUserJiffies int = 13 procStatFieldSysJiffies int = 14 @@ -94,7 +98,16 @@ func readStats(path string) (ppid, threads int, jiffies, rss, rssLimit uint64, e // Parse the file without using expensive extra string allocations pos := 0 - skipNSpaces(&buf, &pos, procStatFieldPpid) + skipNSpaces(&buf, &pos, procStatFieldState) + + // Error on processes which are in zombie (defunct) or dead state, so they will be skipped + switch buf[pos] { + case 'Z', 'X', 'x': + err = errDeadProcess + return + } + + pos += 2 // Move past state and space after state ppid = parseIntWithSpaces(&buf, &pos) skipNSpaces(&buf, &pos, procStatFieldUserJiffies-procStatFieldPpid) diff --git a/site/ami.md b/site/ami.md index 409670891..3b8993471 100644 --- a/site/ami.md +++ b/site/ami.md @@ -54,8 +54,8 @@ The latest Weave ECS AMIs are based on Amazon's [ECS-Optimized Amazon Linux AMI](https://aws.amazon.com/marketplace/pp/B06XS8WHGJ), version `2017.03.f` and also includes: -* [Weave Net 2.0.4](https://github.com/weaveworks/weave/blob/master/CHANGELOG.md#release-204) -* [Weave Scope 1.6.4](https://github.com/weaveworks/scope/blob/master/CHANGELOG.md#release-164) +* [Weave Net 2.3.0](https://github.com/weaveworks/weave/blob/master/CHANGELOG.md#release-230) +* [Weave Scope 1.9.0](https://github.com/weaveworks/scope/blob/master/CHANGELOG.md#release-190) ## Deployment Requirements @@ -250,6 +250,12 @@ that region when invoking the script: ONLY_REGION=us-east-1 AWS_ACCSS_KEY_ID=XXXX AWS_SECRET_ACCESS_KEY=YYYY ./build-all-amis.sh ~~~ +To make an AMI public: + +~~~bash +aws ec2 modify-image-attribute --region=us-east-2 --image-id ami-6a0b350f --launch-permission "{\"Add\": [{\"Group\":\"all\"}]}" +~~~ + ## Further Reading Read the