Skip to content
This repository has been archived by the owner on Feb 28, 2019. It is now read-only.

Initial main #1

Merged
merged 8 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@ env:
sudo: required
dist: trusty
script:
- make lint
- make test-ci-unit
- make test-ci-integration
- make m3ctl
- make all
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ services-linux-amd64:

$(foreach SERVICE,$(SERVICES),$(eval $(SERVICE_RULES)))

all: lint test-ci-unit services
@echo Made all successfully
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll fail fairly loudly if any of the build targets fail so don't think you actually need the echo here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do this in other places, its nice positive reenforcement.


lint:
@which golint > /dev/null || go get -u github.com/golang/lint/golint
$(lint_check)
Expand Down
163 changes: 163 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package: github.com/m3db/m3ctl

import:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe copy the packages (and their corresponding versions) that are in glide.lock but aren't in glide.yaml into glide.yaml so they don't change when someone runs glide update?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for direct dependencies, not transitive ones, yeah?

- package: github.com/m3db/m3cluster
version: d64606edb68599677fd335ceed86d990d13d2991
- package: github.com/m3db/m3metrics
version: 18bc01a7057d55b78e528236e0e9db297bcd4fa3
- package: github.com/m3db/m3x
version: 9e66dd6d48a872bae1bdddb9bf85a33e99129267
- package: github.com/apache/thrift
version: 9549b25c77587b29be4e0b5c258221a4ed85d37a
- package: github.com/beorn7/perks
version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9
- package: github.com/coreos/etcd
version: 8ba2897a21e4fc51b298ca553d251318425f93ae
- package: google.golang.org/grpc
version: 777daa17ff9b5daef1cfdf915088a2ada3332bf0
- package: gopkg.in/validator.v2
version: 3e4f037f12a1221a0864cf0dd2e81c452ab22448
- package: gopkg.in/yaml.v2
version: a83829b6f1293c91addabc89d0571c246397bbf4
- package: github.com/facebookgo/clock
version: 600d898af40aa09a7a93ecb9265d87b0504b6f03
- package: github.com/ghodss/yaml
version: 73d445a93680fa1a78ae23a5839bad48f32ba1ee
- package: github.com/go-ole/go-ole
version: de8695c8edbf8236f30d6e1376e20b198a028d42
- package: github.com/golang/mock
version: bd3c8e81be01eef76d4b503f5e687d2d1354d2d9
- package: github.com/golang/protobuf
version: 7390af9dcd3c33042ebaf2474a1724a83cf1a7e6
- package: github.com/grpc-ecosystem/go-grpc-prometheus
version: 6b7015e65d366bf3f19b2b2a000a831940f0f7e0
- package: github.com/grpc-ecosystem/grpc-gateway
version: 84398b94e188ee336f307779b57b3aa91af7063c
- package: github.com/matttproud/golang_protobuf_extensions
version: c12348ce28de40eed0136aa2b644d0ee0650e56c
- package: github.com/prometheus/client_golang
version: c5b7fccd204277076155f10851dad72b76a49317
- package: github.com/prometheus/client_model
version: fa8ad6fec33561be4280a8f0514318c79d7f6cb6
- package: github.com/prometheus/common
version: 195bde7883f7c39ea62b0d92ab7359b5327065cb
- package: github.com/prometheus/procfs
version: 1878d9fbb537119d24b21ca07effd591627cd160
- package: github.com/shirou/gopsutil
version: b62e301a8b9958eebb7299683eb57fab229a9501
- package: github.com/shirou/w32
version: bb4de0191aa41b5507caa14b0650cdbddcd9280b
- package: github.com/StackExchange/wmi
version: e542ed97d15e640bdc14b5c12162d59e8fc67324
- package: github.com/uber-go/atomic
version: e682c1008ac17bf26d2e4b5ad6cdd08520ed0b22
- package: github.com/uber-go/tally
version: <4.0.0
- package: golang.org/x/net
version: f2499483f923065a842d38eb4c7f1927e6fc6e6d
- package: github.com/gorilla/mux
version: 18fca31550181693b3a834a15b74b564b3605876
testImport:
- package: github.com/stretchr/testify
version: 6fe211e493929a8aac0469b93f28b1d0688a9a3a
- package: github.com/pmezard/go-difflib
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
- package: github.com/davecgh/go-spew
version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: insert newline at the end


29 changes: 29 additions & 0 deletions handler/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE

package handler

import "github.com/gorilla/mux"

// Controller defines functions around a controllable entity
type Controller interface {
// Registers the handlers for this controller with the given ServeMux
RegisterHandlers(*mux.Router)
}
101 changes: 101 additions & 0 deletions handler/health/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE

package health

import (
"encoding/json"
"fmt"
"net/http"
"os"
"time"

"github.com/m3db/m3ctl/handler"
"github.com/m3db/m3x/instrument"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: blank line between repo local and third-party imports


"github.com/gorilla/mux"
)

const (
ok healthStatus = "OK"
fail healthStatus = "FAIL"
healthURL = "/health"
unknownName = "unkown"
)

type healthStatus string

type healthCheckResult struct {
Host string `json:"host"`
Timestamp time.Time `json:"timestamp"`
ResponseTime time.Duration `json:"response_time"`
Status healthStatus `json:"status"`
}

type controller struct {
iOpts instrument.Options
}

// NewController creates a new rules controller
func NewController(iOpts instrument.Options) handler.Controller {
return &controller{iOpts: iOpts}
}

func healthCheck() healthStatus {
return ok
}

func hostName() string {
host, err := os.Hostname()
if err != nil {
host = unknownName
}
return host
}

func m3ctlHealthCheck(w http.ResponseWriter, r *http.Request) {
start := time.Now()
host := hostName()
h := healthCheckResult{Host: host, Timestamp: start}
status := healthCheck()
h.ResponseTime = time.Since(start)

h.Status = status
if status != ok {
w.WriteHeader(http.StatusInternalServerError)
}

body, err := json.Marshal(h)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Could not generate health check result")
return
}

w.Header().Set("Content-Type", "application/json")
w.Write(body)
}

// RegisterHandlers registers health handlers.
func (c *controller) RegisterHandlers(router *mux.Router) {
log := c.iOpts.Logger()
router.HandleFunc(healthURL, m3ctlHealthCheck)
log.Infof("Registered health endpoints")
}
Loading