Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update metrics #34

Merged
merged 1 commit into from
Dec 6, 2018
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
4 changes: 2 additions & 2 deletions files/Dockerfile-build
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ ARG VERSION=$VERSION
ENV VERSION=$VERSION

### required to build
RUN mkdir -p /root/butler/cmd/butler /root/butler/internal/monitor /root/butler/internal/stats /root/butler/internal/config /root/butler/internal/methods /root/butler/internal/reloaders /root/butler/internal/environment /root/butler/internal/alog
RUN mkdir -p /root/butler/cmd/butler /root/butler/internal/monitor /root/butler/internal/metrics /root/butler/internal/config /root/butler/internal/methods /root/butler/internal/reloaders /root/butler/internal/environment /root/butler/internal/alog
COPY ./files/build.sh /root/build.sh
COPY ./cmd/butler/main.go /root/butler/cmd/butler/main.go
COPY ./internal/config/*.go /root/butler/internal/config/
COPY ./internal/methods/*.go /root/butler/internal/methods/
COPY ./internal/reloaders/*.go /root/butler/internal/reloaders/
COPY ./internal/stats/*.go /root/butler/internal/stats/
COPY ./internal/metrics/*.go /root/butler/internal/metrics/
COPY ./internal/monitor/*.go /root/butler/internal/monitor/
COPY ./internal/environment/*.go /root/butler/internal/environment
COPY ./internal/alog/*.go /root/butler/internal/alog
Expand Down
4 changes: 2 additions & 2 deletions files/Dockerfile-testaccept
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ COPY ./files/nginx.conf-accept /etc/nginx/nginx.conf
### required for test

### required to build
RUN mkdir -p /root/butler/cmd/butler /root/butler/internal/monitor /root/butler/internal/stats /root/butler/internal/config /root/butler/internal/methods /root/butler/internal/reloaders /root/butler/internal/environment /root/butler/internal/alog
RUN mkdir -p /root/butler/cmd/butler /root/butler/internal/monitor /root/butler/internal/metrics /root/butler/internal/config /root/butler/internal/methods /root/butler/internal/reloaders /root/butler/internal/environment /root/butler/internal/alog
COPY ./cmd/butler/*.go /root/butler/cmd/butler/
COPY ./internal/config/*.go /root/butler/internal/config/
COPY ./internal/methods/*.go /root/butler/internal/methods/
COPY ./internal/reloaders/*.go /root/butler/internal/reloaders/
COPY ./internal/stats/*.go /root/butler/internal/stats/
COPY ./internal/metrics/*.go /root/butler/internal/metrics/
COPY ./internal/monitor/*.go /root/butler/internal/monitor/
COPY ./internal/environment/*.go /root/butler/internal/environment/
COPY ./internal/alog/*.go /root/butler/internal/alog/
Expand Down
4 changes: 2 additions & 2 deletions files/Dockerfile-testunit
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ COPY ./files/build_test_unit.sh /root/build.sh
### required for test

### required to build
RUN mkdir -p /root/butler/cmd/butler /root/butler/internal/monitor /root/butler/internal/stats /root/butler/internal/config /root/butler/internal/methods /root/butler/internal/reloaders /root/butler/internal/environment /root/butler/internal/alog
RUN mkdir -p /root/butler/cmd/butler /root/butler/internal/monitor /root/butler/internal/metrics /root/butler/internal/config /root/butler/internal/methods /root/butler/internal/reloaders /root/butler/internal/environment /root/butler/internal/alog
COPY ./cmd/butler/*.go /root/butler/cmd/butler/
COPY ./internal/config/*.go /root/butler/internal/config/
COPY ./internal/methods/*.go /root/butler/internal/methods/
COPY ./internal/reloaders/*.go /root/butler/internal/reloaders/
COPY ./internal/stats/*.go /root/butler/internal/stats/
COPY ./internal/metrics/*.go /root/butler/internal/metrics/
COPY ./internal/monitor/*.go /root/butler/internal/monitor/
COPY ./internal/environment/*.go /root/butler/internal/environment/
COPY ./internal/alog/*.go /root/butler/internal/alog/
Expand Down
6 changes: 3 additions & 3 deletions files/build_test_accept.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ cd $BUTLER_GO_PATH
mv /root/butler/vendor .

## make butler directories
mkdir -p cmd/butler internal/monitor internal/stats internal/config internal/alog internal/environment internal/methods internal/reloaders
mkdir -p cmd/butler internal/monitor internal/metrics internal/config internal/alog internal/environment internal/methods internal/reloaders

## move butler main
mv /root/butler/cmd/butler/*.go cmd/butler

## move stats files
mv /root/butler/internal/stats/*.go internal/stats
## move metrics files
mv /root/butler/internal/metrics/*.go internal/metrics

## move config files
mv /root/butler/internal/config/*.go internal/config
Expand Down
14 changes: 7 additions & 7 deletions files/build_test_unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ mv /root/butler/vendor .
mv /root/butler/.git .

## make butler directories
mkdir -p cmd/butler internal/monitor internal/stats internal/config internal/alog internal/environment internal/methods internal/reloaders
mkdir -p cmd/butler internal/monitor internal/metrics internal/config internal/alog internal/environment internal/methods internal/reloaders

## move butler main
mv /root/butler/cmd/butler/*.go cmd/butler

## move stats files
mv /root/butler/internal/stats/*.go internal/stats
## move metrics files
mv /root/butler/internal/metrics/*.go internal/metrics

## move config files
mv /root/butler/internal/config/*.go internal/config
Expand Down Expand Up @@ -90,8 +90,8 @@ if [ $ret -ne 0 ]; then
exit $ret
fi

cd $BUTLER_GO_PATH/internal/stats
go test -check.vv -coverprofile=/tmp/coverage-stats.out
cd $BUTLER_GO_PATH/internal/metrics
go test -check.vv -coverprofile=/tmp/coverage-metrics.out
ret=$?

if [ $ret -ne 0 ]; then
Expand All @@ -118,8 +118,8 @@ if [ -f /tmp/coverage-config-reloaders.out ]; then
echo
fi

if [ -f /tmp/coverage-stats.out ]; then
go tool cover -func /tmp/coverage-stats.out
if [ -f /tmp/coverage-metrics.out ]; then
go tool cover -func /tmp/coverage-metrics.out
echo
fi

Expand Down
8 changes: 4 additions & 4 deletions internal/config/chan.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"os"
"sort"

"github.com/adobe/butler/internal/stats"
"github.com/adobe/butler/internal/metrics"

log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -172,7 +172,7 @@ func (c *ConfigChanEvent) CopyPrimaryConfigFiles(opts map[string]*ManagerOpts) b
out, err := os.OpenFile(c.TmpFile.Name(), os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
log.Infof("ConfigChanEvent::CopyPrimaryConfigFiles(): Could not process and merge new %v err=%s.", c.ConfigFile, err.Error())
stats.SetButlerConfigVal(stats.FAILURE, "local", stats.GetStatsLabel(*c.ConfigFile))
metrics.SetButlerConfigVal(metrics.FAILURE, "local", metrics.GetStatsLabel(*c.ConfigFile))
c.CleanTmpFiles()
return false
} else {
Expand All @@ -183,15 +183,15 @@ func (c *ConfigChanEvent) CopyPrimaryConfigFiles(opts map[string]*ManagerOpts) b
in, err := os.Open(t.File)
if err != nil {
log.Infof("ConfigChanEvent::CopyPrimaryConfigFiles(): Could not process and merge new %v err=%s.", c.ConfigFile, err.Error())
stats.SetButlerConfigVal(stats.FAILURE, "local", stats.GetStatsLabel(t.Name))
metrics.SetButlerConfigVal(metrics.FAILURE, "local", metrics.GetStatsLabel(t.Name))
c.CleanTmpFiles()
out.Close()
return false
}
_, err = io.Copy(out, in)
if err != nil {
log.Infof("ConfigChanEvent::CopyPrimaryConfigFiles(): Could not process and merge new %v err=%s.", c.ConfigFile, err.Error())
stats.SetButlerConfigVal(stats.FAILURE, "local", stats.GetStatsLabel(t.Name))
metrics.SetButlerConfigVal(metrics.FAILURE, "local", metrics.GetStatsLabel(t.Name))
c.CleanTmpFiles()
out.Close()
return false
Expand Down
34 changes: 17 additions & 17 deletions internal/config/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"time"

"github.com/adobe/butler/internal/methods"
"github.com/adobe/butler/internal/metrics"
"github.com/adobe/butler/internal/reloaders"
"github.com/adobe/butler/internal/stats"

"github.com/jasonlvhit/gocron"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -271,13 +271,13 @@ func (bc *ButlerConfig) Handler() error {
log.Errorf("ButlerConfig::Handler()[count=%v]: Cannot retrieve butler configuration. err=%s", handlerCounter, err.Error())
log.Errorf("ButlerConfig::Handler()[count=%v]: done.", handlerCounter)
handlerCounter++
stats.SetButlerContactVal(stats.FAILURE, bc.URL.Host, bc.URL.Path)
metrics.SetButlerContactVal(metrics.FAILURE, bc.URL.Host, bc.URL.Path)
return err
}
defer response.GetResponseBody().Close()

if response.GetResponseStatusCode() != 200 {
stats.SetButlerContactVal(stats.FAILURE, bc.URL.Host, bc.URL.Path)
metrics.SetButlerContactVal(metrics.FAILURE, bc.URL.Host, bc.URL.Path)
log.Errorf("ButlerConfig::Handler()[count=%v]: Did not receive 200 response code for %s. code=%d", handlerCounter, bc.URL.String(), response.GetResponseStatusCode())
log.Errorf("ButlerConfig::Handler()[count=%v] done.", handlerCounter)
handlerCounter++
Expand All @@ -287,7 +287,7 @@ func (bc *ButlerConfig) Handler() error {

body, err := ioutil.ReadAll(response.GetResponseBody())
if err != nil {
stats.SetButlerContactVal(stats.FAILURE, bc.URL.Host, bc.URL.Path)
metrics.SetButlerContactVal(metrics.FAILURE, bc.URL.Host, bc.URL.Path)
log.Errorf("ButlerConfig::Handler()[count=%v]: Could not read response body for %s. err=%s", handlerCounter, bc.URL.String(), err)
log.Errorf("ButlerConfig::Handler()[count=%v] done.", handlerCounter)
handlerCounter++
Expand All @@ -297,7 +297,7 @@ func (bc *ButlerConfig) Handler() error {

err = ValidateConfig(NewValidateOpts().WithData(body).WithFileName("butler.toml").WithManager("butler-config"))
if err != nil {
stats.SetButlerContactVal(stats.FAILURE, bc.URL.Host, bc.URL.Path)
metrics.SetButlerContactVal(metrics.FAILURE, bc.URL.Host, bc.URL.Path)
return err
}

Expand All @@ -307,7 +307,7 @@ func (bc *ButlerConfig) Handler() error {
if bc.Config.Globals.ExitOnFailure {
log.Fatal(err)
} else {
stats.SetButlerContactVal(stats.FAILURE, bc.URL.Host, bc.URL.Path)
metrics.SetButlerContactVal(metrics.FAILURE, bc.URL.Host, bc.URL.Path)
return err
}
} else {
Expand All @@ -322,7 +322,7 @@ func (bc *ButlerConfig) Handler() error {
if bc.Config.Globals.ExitOnFailure {
log.Fatal(err)
} else {
stats.SetButlerContactVal(stats.FAILURE, bc.URL.Host, bc.URL.Path)
metrics.SetButlerContactVal(metrics.FAILURE, bc.URL.Host, bc.URL.Path)
return err
}
} else {
Expand Down Expand Up @@ -360,7 +360,7 @@ func (bc *ButlerConfig) Handler() error {
bc.SetCMPrevInterval(bc.GetCMInterval())
}
}
stats.SetButlerContactVal(stats.SUCCESS, bc.URL.Host, bc.URL.Path)
metrics.SetButlerContactVal(metrics.SUCCESS, bc.URL.Host, bc.URL.Path)
log.Infof("ButlerConfig::Handler()[count=%v]: done.", handlerCounter)
handlerCounter++
return nil
Expand Down Expand Up @@ -397,8 +397,8 @@ func (bc *ButlerConfig) RunCMHandler() error {
}
PrimaryChan.CleanTmpFiles()
AdditionalChan.CleanTmpFiles()
stats.SetButlerRemoteRepoUp(stats.SUCCESS, m.Name)
stats.SetButlerRemoteRepoSanity(stats.SUCCESS, m.Name)
metrics.SetButlerRemoteRepoUp(metrics.SUCCESS, m.Name)
metrics.SetButlerRemoteRepoSanity(metrics.SUCCESS, m.Name)
} else {
log.Debugf("Config::RunCMHandler()[count=%v]: cannot copy files. cleaning up...", cmHandlerCounter)
// Failure statistics for RemoteRepoUp and RemoteRepoSanity
Expand All @@ -414,7 +414,7 @@ func (bc *ButlerConfig) RunCMHandler() error {
// We are going to run through the managers and ensure that the status file
// is in an OK state for the manager. If it is not, then we will attempt a reload
for _, m := range bc.GetManagers() {
stats.SetButlerRepoInSync(stats.SUCCESS, m.Name)
metrics.SetButlerRepoInSync(metrics.SUCCESS, m.Name)
if !GetManagerStatus(bc.GetStatusFile(), m.Name) {
log.Debugf("Config::RunCMHandler()[count=%v]: Could not find manager status. Going to reload to get in sync.", cmHandlerCounter)
err := m.Reload()
Expand All @@ -426,14 +426,14 @@ func (bc *ButlerConfig) RunCMHandler() error {
if e.Code == 1 && m.ManagerTimeoutOk == true {
// we really don't care about here
// let's make sure we at least delete our metrics
stats.DeleteButlerReloadVal(m.Name)
metrics.DeleteButlerReloadVal(m.Name)
} else {
log.Errorf("Config::RunCMHandler()[count=%v]: err=%#v", cmHandlerCounter, err)
err := SetManagerStatus(bc.GetStatusFile(), m.Name, false)
if err != nil {
log.Fatalf("Config::RunCMHandler()[count=%v]: could not write to %v err=%v", cmHandlerCounter, bc.GetStatusFile(), err.Error())
}
stats.SetButlerReloadVal(stats.FAILURE, m.Name)
metrics.SetButlerReloadVal(metrics.FAILURE, m.Name)
if m.EnableCache && m.GoodCache {
RestoreCachedConfigs(m.Name, bc.Config.GetAllConfigLocalPaths(m.Name), m.CleanFiles)
}
Expand All @@ -444,7 +444,7 @@ func (bc *ButlerConfig) RunCMHandler() error {
if err != nil {
log.Fatalf("Config::RunCMHandler()[count=%v]: could not write to %v err=%v", cmHandlerCounter, bc.GetStatusFile(), err.Error())
}
stats.SetButlerReloadVal(stats.SUCCESS, m.Name)
metrics.SetButlerReloadVal(metrics.SUCCESS, m.Name)
if m.EnableCache {
CacheConfigs(m.Name, bc.Config.GetAllConfigLocalPaths(m.Name))
m.GoodCache = true
Expand All @@ -465,14 +465,14 @@ func (bc *ButlerConfig) RunCMHandler() error {
if e.Code == 1 && mgr.ManagerTimeoutOk == true {
// we really don't care about here, but
// let's make sure we at least delete our metrics
stats.DeleteButlerReloadVal(mgr.Name)
metrics.DeleteButlerReloadVal(mgr.Name)
} else {
log.Errorf("Config::RunCMHandler()[count=%v]: Could not reload manager \"%v\" err=%#v", cmHandlerCounter, mgr.Name, err)
err := SetManagerStatus(bc.GetStatusFile(), m, false)
if err != nil {
log.Fatalf("Config::RunCMHandler()[count=%v]: could not write to %v err=%v", cmHandlerCounter, bc.GetStatusFile(), err.Error())
}
stats.SetButlerReloadVal(stats.FAILURE, m)
metrics.SetButlerReloadVal(metrics.FAILURE, m)
if mgr.EnableCache && mgr.GoodCache {
RestoreCachedConfigs(m, bc.Config.GetAllConfigLocalPaths(mgr.Name), mgr.CleanFiles)
}
Expand All @@ -483,7 +483,7 @@ func (bc *ButlerConfig) RunCMHandler() error {
if err != nil {
log.Fatalf("Config::RunCMHandler()[count=%v]: could not write to %v err=%v", cmHandlerCounter, bc.GetStatusFile(), err.Error())
}
stats.SetButlerReloadVal(stats.SUCCESS, m)
metrics.SetButlerReloadVal(metrics.SUCCESS, m)
if mgr.EnableCache {
CacheConfigs(m, bc.Config.GetAllConfigLocalPaths(mgr.Name))
mgr.GoodCache = true
Expand Down
18 changes: 9 additions & 9 deletions internal/config/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (

"github.com/adobe/butler/internal/environment"
"github.com/adobe/butler/internal/methods"
"github.com/adobe/butler/internal/metrics"
"github.com/adobe/butler/internal/reloaders"
"github.com/adobe/butler/internal/stats"

"github.com/Jeffail/gabs"
"github.com/hashicorp/go-retryablehttp"
Expand Down Expand Up @@ -365,11 +365,11 @@ func CompareAndCopy(source string, dest string, m string) bool {
log.Infof("helpers.CompareAndCopy()[count=%v][manager=%v]: Found difference in \"%s.\" Updating.", cmHandlerCounter, m, dest)
err = CopyFile(source, dest)
if err != nil {
stats.SetButlerWriteVal(stats.FAILURE, stats.GetStatsLabel(dest))
metrics.SetButlerWriteVal(metrics.FAILURE, metrics.GetStatsLabel(dest))
log.Errorf("helpers.CompareAndCopy()[count=%v][manager=%v]: could not copy source=%v to dest=%v. err=%#v", cmHandlerCounter, m, source, dest, err)
return false
}
stats.SetButlerWriteVal(stats.SUCCESS, stats.GetStatsLabel(dest))
metrics.SetButlerWriteVal(metrics.SUCCESS, metrics.GetStatsLabel(dest))
return true
} else {
return false
Expand Down Expand Up @@ -449,8 +449,8 @@ func CacheConfigs(manager string, files []string) error {
}
}
log.Infof("helpers.CacheConfig()[count=%v][manager=%v]: Done storing known good configurations to cache.", cmHandlerCounter, manager)
stats.SetButlerKnownGoodCachedVal(stats.SUCCESS, manager)
stats.SetButlerKnownGoodRestoredVal(stats.FAILURE, manager)
metrics.SetButlerKnownGoodCachedVal(metrics.SUCCESS, manager)
metrics.SetButlerKnownGoodRestoredVal(metrics.FAILURE, manager)
return nil
}

Expand All @@ -469,8 +469,8 @@ func RestoreCachedConfigs(manager string, files []string, cleanFiles bool) error
}
log.Infof("helpers.RestoreCachedConfigs()[count=%v][manager=%v]: Done cleaning broken configuration. Returning...", cmHandlerCounter, manager)
}
stats.SetButlerKnownGoodCachedVal(stats.FAILURE, manager)
stats.SetButlerKnownGoodRestoredVal(stats.FAILURE, manager)
metrics.SetButlerKnownGoodCachedVal(metrics.FAILURE, manager)
metrics.SetButlerKnownGoodRestoredVal(metrics.FAILURE, manager)
return nil
}

Expand All @@ -494,8 +494,8 @@ func RestoreCachedConfigs(manager string, files []string, cleanFiles bool) error
}
}
log.Warnf("helpers.RestoreCachedConfigs()[count=%v][manager=%v]: Done restoring known good configurations from cache.", cmHandlerCounter, manager)
stats.SetButlerKnownGoodCachedVal(stats.FAILURE, manager)
stats.SetButlerKnownGoodRestoredVal(stats.SUCCESS, manager)
metrics.SetButlerKnownGoodCachedVal(metrics.FAILURE, manager)
metrics.SetButlerKnownGoodRestoredVal(metrics.SUCCESS, manager)
return nil
}

Expand Down
Loading