/
metrics.go
115 lines (92 loc) · 3.84 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package windows
import (
"crypto/tls"
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/cloudfoundry-incubator/cf-test-helpers/cf"
"github.com/cloudfoundry-incubator/cf-test-helpers/helpers"
"github.com/cloudfoundry-incubator/cf-test-helpers/workflowhelpers"
"github.com/cloudfoundry/noaa"
"github.com/cloudfoundry/noaa/events"
. "github.com/cloudfoundry/cf-acceptance-tests/cats_suite_helpers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/assets"
. "github.com/cloudfoundry/cf-acceptance-tests/helpers/matchers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"time"
)
var _ = WindowsDescribe("Metrics", func() {
var appName string
const hundredthOfOneSecond = 10000 // this app uses millionth of seconds
BeforeEach(func() {
appName = random_name.CATSRandomName("APP")
Expect(cf.Cf("push",
appName,
"-s", Config.GetWindowsStack(),
"-b", Config.GetBinaryBuildpackName(),
"-m", DEFAULT_MEMORY_LIMIT,
"-p", assets.NewAssets().LoggregatorLoadGeneratorGo,
"-c", ".\\loggregator-load-generator.exe",
"-i", "2",
"-d", Config.GetAppsDomain()).Wait(Config.CfPushTimeoutDuration())).To(gexec.Exit(0))
})
AfterEach(func() {
app_helpers.AppReport(appName)
Expect(cf.Cf("delete", appName, "-f", "-r").Wait()).To(gexec.Exit(0))
})
It("shows logs and metrics", func() {
noaaConnection := noaa.NewConsumer(getDopplerEndpoint(), &tls.Config{InsecureSkipVerify: Config.GetSkipSSLValidation()}, nil)
msgChan := make(chan *events.Envelope, 100000)
errorChan := make(chan error)
stopchan := make(chan struct{})
go noaaConnection.Firehose(random_name.CATSRandomName("SUBSCRIPTION-ID"), getAdminUserAccessToken(), msgChan, errorChan, stopchan)
defer close(stopchan)
Eventually(func() string {
return helpers.CurlApp(Config, appName, fmt.Sprintf("/log/sleep/%d", hundredthOfOneSecond))
}).Should(ContainSubstring("Muahaha"))
Eventually(msgChan, Config.DefaultTimeoutDuration(), time.Millisecond).Should(Receive(EnvelopeContainingMessageLike("Muahaha")), "To enable the logging & metrics firehose feature, please ask your CF administrator to add the 'doppler.firehose' scope to your CF admin user.")
})
It("shows container metrics", func() {
appGuid := strings.TrimSpace(string(cf.Cf("app", appName, "--guid").Wait().Out.Contents()))
noaaConnection := noaa.NewConsumer(getDopplerEndpoint(), &tls.Config{InsecureSkipVerify: Config.GetSkipSSLValidation()}, nil)
msgChan := make(chan *events.Envelope, 100000)
errorChan := make(chan error)
stopchan := make(chan struct{})
go noaaConnection.Firehose(random_name.CATSRandomName("SUBSCRIPTION-ID"), getAdminUserAccessToken(), msgChan, errorChan, stopchan)
defer close(stopchan)
Eventually(msgChan, 2*Config.DefaultTimeoutDuration(), time.Millisecond).Should(Receive(NonZeroContainerMetricsFor(MetricsApp{AppGuid: appGuid, InstanceId: 0})))
Eventually(msgChan, 2*Config.DefaultTimeoutDuration(), time.Millisecond).Should(Receive(NonZeroContainerMetricsFor(MetricsApp{AppGuid: appGuid, InstanceId: 1})))
})
})
type cfHomeConfig struct {
AccessToken string
DopplerEndPoint string
}
func getCfHomeConfig() *cfHomeConfig {
myCfHomeConfig := &cfHomeConfig{}
workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() {
path := filepath.Join(os.Getenv("CF_HOME"), ".cf", "config.json")
configFile, err := os.Open(path)
if err != nil {
panic(err)
}
decoder := json.NewDecoder(configFile)
err = decoder.Decode(myCfHomeConfig)
if err != nil {
panic(err)
}
})
return myCfHomeConfig
}
func getAdminUserAccessToken() string {
return getCfHomeConfig().AccessToken
}
func getDopplerEndpoint() string {
return getCfHomeConfig().DopplerEndPoint
}