Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Commit

Permalink
Fix/use fthealth v1.1 (#22)
Browse files Browse the repository at this point in the history
Using go-fthealth v1.1
Added vendoring (govendor).
  • Loading branch information
bogdanguranda committed Apr 18, 2017
1 parent b3a841f commit cfd5956
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
content-preview.exe
*.exe
*.log
*.html
*coverage.*
*.iml
.idea/
content-preview
vendor/*/**
31 changes: 22 additions & 9 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"time"

fthealth "github.com/Financial-Times/go-fthealth/v1a"
fthealth "github.com/Financial-Times/go-fthealth/v1_1"
oldhttphandlers "github.com/Financial-Times/http-handlers-go/httphandlers"
"github.com/Financial-Times/service-status-go/gtg"
"github.com/Financial-Times/service-status-go/httphandlers"
Expand All @@ -22,9 +22,15 @@ var client = &http.Client{Timeout: timeout}

func main() {
app := cli.App("content-preview", serviceDescription)
serviceName := app.String(cli.StringOpt{
Name: "app-name",
appSystemCode := app.String(cli.StringOpt{
Name: "app-system-code",
Value: "content-preview",
Desc: "The system code of this service",
EnvVar: "APP_SYSTEM_CODE",
})
appName := app.String(cli.StringOpt{
Name: "app-name",
Value: "Content Preview",
Desc: "The name of this service",
EnvVar: "APP_NAME",
})
Expand Down Expand Up @@ -120,7 +126,8 @@ func main() {
})
app.Action = func() {
sc := ServiceConfig{
*serviceName,
*appSystemCode,
*appName,
*appPort,
*sourceAppAuth,
*transformAppHostHeader,
Expand All @@ -140,7 +147,7 @@ func main() {
metricsHandler := NewMetrics()
contentHandler := ContentHandler{&sc, appLogger, &metricsHandler}
h := setupServiceHandler(sc, metricsHandler, contentHandler)
appLogger.ServiceStartedEvent(*serviceName, sc.asMap())
appLogger.ServiceStartedEvent(*appSystemCode, sc.asMap())
metricsHandler.OutputMetricsIfRequired(*graphiteTCPAddress, *graphitePrefix, *logMetrics)
err := http.ListenAndServe(":"+*appPort, h)
if err != nil {
Expand All @@ -156,15 +163,20 @@ func setupServiceHandler(sc ServiceConfig, metricsHandler Metrics, contentHandle
oldhttphandlers.TransactionAwareRequestLoggingHandler(logrus.StandardLogger(), contentHandler))})
r.Path(httphandlers.BuildInfoPath).HandlerFunc(httphandlers.BuildInfoHandler)
r.Path(httphandlers.PingPath).HandlerFunc(httphandlers.PingHandler)

gtgHandler := httphandlers.NewGoodToGoHandler(gtg.StatusChecker(sc.gtgCheck))
r.Path(httphandlers.GTGPath).HandlerFunc(gtgHandler)
r.Path("/__health").Handler(handlers.MethodHandler{"GET": http.HandlerFunc(fthealth.Handler(sc.serviceName, serviceDescription, sc.nativeContentSourceCheck(), sc.transformerServiceCheck()))})

hc := fthealth.HealthCheck{SystemCode: sc.appSystemCode, Description: serviceDescription, Name: sc.appName, Checks: []fthealth.Check{sc.nativeContentSourceCheck(), sc.transformerServiceCheck()}}
r.Path("/__health").Handler(handlers.MethodHandler{"GET": http.HandlerFunc(fthealth.Handler(&hc))})

r.Path("/__metrics").Handler(handlers.MethodHandler{"GET": http.HandlerFunc(metricsHttpEndpoint)})
return r
}

type ServiceConfig struct {
serviceName string
appSystemCode string
appName string
appPort string
sourceAppAuth string
transformAppHostHeader string
Expand All @@ -183,8 +195,9 @@ type ServiceConfig struct {

func (sc ServiceConfig) asMap() map[string]interface{} {
return map[string]interface{}{
"service-name": sc.serviceName,
"service-port": sc.appPort,
"app-system-code": sc.appSystemCode,
"app-name": sc.appName,
"app-port": sc.appPort,
"source-app-name": sc.sourceAppName,
"source-app-uri": sc.sourceAppUri,
"transform-app-name": sc.transformAppName,
Expand Down
4 changes: 2 additions & 2 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"os"
"testing"

fthealth "github.com/Financial-Times/go-fthealth/v1a"
fthealth "github.com/Financial-Times/go-fthealth/v1_1"
tid "github.com/Financial-Times/transactionid-utils-go"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -134,14 +134,14 @@ func stopServices() {
}

func startContentPreviewService() {

methodeApiUrl := methodeApiMock.URL + "/eom-file/"
nativeContentAppHealthUri := methodeApiMock.URL + "/build-info"
methodArticleTransformerUrl := methodeArticleTransformerMock.URL + "/map"
transformAppHealthUrl := methodeArticleTransformerMock.URL + "/build-info"

sc := ServiceConfig{
"content-preview",
"Content Preview",
"8084",
"default",
"methode-article-transformer",
Expand Down
27 changes: 21 additions & 6 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
machine:
environment:
GOPATH: "${HOME}/.go_workspace:/usr/local/go_workspace:${HOME}/.go_project"
GO_PROJECT_PATH: "${HOME}/.go_project/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}"

checkout:
post:
- mkdir -p $(dirname ${GO_PROJECT_PATH})
- ln -fs $HOME/$CIRCLE_PROJECT_REPONAME $GO_PROJECT_PATH

dependencies:
pre:
- go get github.com/axw/gocov/gocov; go get github.com/matm/gocov-html
- go get -u github.com/jstemmer/go-junit-report
- go get -u github.com/kardianos/govendor
override:
- cd $GO_PROJECT_PATH && govendor sync
- cd $GO_PROJECT_PATH && go get -t -d -v ./...
- cd $GO_PROJECT_PATH && go build -v

test:
pre:
- go get github.com/mattn/goveralls
- go get -u github.com/jstemmer/go-junit-report
- go get -u github.com/mattn/goveralls
override:
- mkdir -p $CIRCLE_TEST_REPORTS/golang
- go test -race -v ./... | go-junit-report > $CIRCLE_TEST_REPORTS/golang/junit.xml
- go test -v -cover -race -coverprofile=$CIRCLE_ARTIFACTS/coverage.out ./...
- cd $GO_PROJECT_PATH && govendor test -race -v +local | go-junit-report > $CIRCLE_TEST_REPORTS/golang/junit.xml
- cd $GO_PROJECT_PATH && govendor test -v -cover -race -coverprofile=$CIRCLE_ARTIFACTS/coverage.out +local
- cd $CIRCLE_ARTIFACTS && sed -i '1d' *.out
- |
echo "mode: atomic" > $CIRCLE_ARTIFACTS/overall-coverage.result
- cd $CIRCLE_ARTIFACTS && cat *.out >> overall-coverage.result
post:
- goveralls -coverprofile=$CIRCLE_ARTIFACTS/overall-coverage.result -service=circle-ci -repotoken=$COVERALLS_TOKEN
- goveralls -coverprofile=$CIRCLE_ARTIFACTS/overall-coverage.result -service=circle-ci -repotoken=$COVERALLS_TOKEN
6 changes: 3 additions & 3 deletions healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"net/http"

fthealth "github.com/Financial-Times/go-fthealth/v1a"
fthealth "github.com/Financial-Times/go-fthealth/v1_1"
"github.com/Financial-Times/service-status-go/gtg"
)

Expand All @@ -15,7 +15,7 @@ func (sc *ServiceConfig) nativeContentSourceCheck() fthealth.Check {
Name: sc.sourceAppName,
PanicGuide: sc.sourceAppPanicGuide,
Severity: 1,
TechnicalSummary: "Checks that " + sc.sourceAppName + " is reachable. " + sc.serviceName + " requests native content from " + sc.sourceAppName,
TechnicalSummary: "Checks that " + sc.sourceAppName + " is reachable. " + sc.appName + " requests native content from " + sc.sourceAppName,
Checker: func() (string, error) {
return checkServiceAvailability(sc.sourceAppName, sc.sourceAppHealthUri, sc.sourceAppAuth, "")
},
Expand All @@ -28,7 +28,7 @@ func (sc *ServiceConfig) transformerServiceCheck() fthealth.Check {
Name: sc.transformAppName,
PanicGuide: sc.transformAppPanicGuide,
Severity: 1,
TechnicalSummary: "Checks that " + sc.transformAppName + " is reachable. " + sc.serviceName + " relies on " + sc.transformAppName + " to process content",
TechnicalSummary: "Checks that " + sc.transformAppName + " is reachable. " + sc.appName + " relies on " + sc.transformAppName + " to process content",
Checker: func() (string, error) {
return checkServiceAvailability(sc.transformAppName, sc.transformAppHealthUri, "", sc.transformAppHostHeader)
},
Expand Down
123 changes: 123 additions & 0 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"comment": "",
"ignore": "test",
"package": [
{
"checksumSHA1": "2dtgENfeO6SICvxjruwb9f1CzLY=",
"path": "github.com/Financial-Times/go-fthealth/v1_1",
"revision": "bc27ed19189994eef0364e4a07879d5a3f3be76f",
"revisionTime": "2017-03-24T12:21:32Z",
"version": "0.2.0",
"versionExact": "0.2.0"
},
{
"checksumSHA1": "zUpINnstJChGK0LAtkt7jBc3RY0=",
"path": "github.com/Financial-Times/http-handlers-go/httphandlers",
"revision": "bb69c454da9050fe1c4b92fe1345a01583ee70be",
"revisionTime": "2016-08-03T10:40:03Z",
"version": "0.1.0",
"versionExact": "0.1.0"
},
{
"checksumSHA1": "fqpohN7Qp2qj7TLMbUxh/cK4oH0=",
"path": "github.com/Financial-Times/service-status-go/buildinfo",
"revision": "3f5199736a3d7ae52394c63aac36834786825e21",
"revisionTime": "2016-03-23T11:15:42Z",
"version": "0.1.0",
"versionExact": "0.1.0"
},
{
"checksumSHA1": "2rGNLXdRC3qr5n5ll7BpYt8HCK8=",
"path": "github.com/Financial-Times/service-status-go/gtg",
"revision": "3f5199736a3d7ae52394c63aac36834786825e21",
"revisionTime": "2016-03-23T11:15:42Z",
"version": "0.1.0",
"versionExact": "0.1.0"
},
{
"checksumSHA1": "973POGyMCoyaKQuIYX2f7EKFwlQ=",
"path": "github.com/Financial-Times/service-status-go/httphandlers",
"revision": "3f5199736a3d7ae52394c63aac36834786825e21",
"revisionTime": "2016-03-23T11:15:42Z",
"version": "0.1.0",
"versionExact": "0.1.0"
},
{
"checksumSHA1": "+sjiZBzrsk91W1A3Md1azCkZadg=",
"path": "github.com/Financial-Times/transactionid-utils-go",
"revision": "df2f00c734957c9dd651ce23ab0e0902504c7636",
"revisionTime": "2017-03-28T16:39:54Z",
"version": "v0.2.0",
"versionExact": "v0.2.0"
},
{
"checksumSHA1": "ZKxETlJdB2XubMrZnXB0FQimVA8=",
"path": "github.com/Sirupsen/logrus",
"revision": "10f801ebc38b33738c9d17d50860f484a0988ff5",
"revisionTime": "2017-03-17T14:32:14Z"
},
{
"checksumSHA1": "/6H1rhQmbq8mEP29pnmLmdwBKUE=",
"path": "github.com/cyberdelia/go-metrics-graphite",
"revision": "39f87cc3b432bbb898d7c643c0e93cac2bc865ad",
"revisionTime": "2016-12-19T23:08:53Z"
},
{
"checksumSHA1": "OFu4xJEIjiI8Suu+j/gabfp+y6Q=",
"origin": "github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew",
"path": "github.com/davecgh/go-spew/spew",
"revision": "4d4bfba8f1d1027c4fdbe371823030df51419987",
"revisionTime": "2017-01-30T11:31:45Z"
},
{
"checksumSHA1": "I+GdpjQMP4tAYwF4CAklylRWeYI=",
"path": "github.com/gorilla/handlers",
"revision": "3a5767ca75ece5f7f1440b1d16975247f8d8b221",
"revisionTime": "2016-12-06T05:51:44Z"
},
{
"checksumSHA1": "urMd7A9QPAJYY0GZJL9qBhlUmD8=",
"path": "github.com/gorilla/mux",
"revision": "757bef944d0f21880861c2dd9c871ca543023cba",
"revisionTime": "2016-09-20T23:08:13Z"
},
{
"checksumSHA1": "EcZfls6vcqjasWV/nBlu+C+EFmc=",
"path": "github.com/hashicorp/go-version",
"revision": "e96d3840402619007766590ecea8dd7af1292276",
"revisionTime": "2016-10-31T18:26:05Z"
},
{
"checksumSHA1": "lvjAdn0k3UFBN9rbH2cVKmlhgoQ=",
"path": "github.com/jawher/mow.cli",
"revision": "660b9261e2c80bb92e5a0eaa581596084656140e",
"revisionTime": "2016-09-19T11:45:49Z"
},
{
"checksumSHA1": "zKKp5SZ3d3ycKe4EKMNT0BqAWBw=",
"origin": "github.com/stretchr/testify/vendor/github.com/pmezard/go-difflib/difflib",
"path": "github.com/pmezard/go-difflib/difflib",
"revision": "4d4bfba8f1d1027c4fdbe371823030df51419987",
"revisionTime": "2017-01-30T11:31:45Z"
},
{
"checksumSHA1": "KAzbLjI9MzW2tjfcAsK75lVRp6I=",
"path": "github.com/rcrowley/go-metrics",
"revision": "1f30fe9094a513ce4c700b9a54458bbb0c96996c",
"revisionTime": "2016-11-28T21:05:44Z"
},
{
"checksumSHA1": "JXUVA1jky8ZX8w09p2t5KLs97Nc=",
"path": "github.com/stretchr/testify/assert",
"revision": "4d4bfba8f1d1027c4fdbe371823030df51419987",
"revisionTime": "2017-01-30T11:31:45Z"
},
{
"checksumSHA1": "9jjO5GjLa0XF/nfWihF02RoH4qc=",
"path": "golang.org/x/net/context",
"revision": "f2499483f923065a842d38eb4c7f1927e6fc6e6d",
"revisionTime": "2017-01-14T04:22:49Z"
}
],
"rootPath": "github.com/Financial-Times/content-preview"
}

0 comments on commit cfd5956

Please sign in to comment.