mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
20191215 code improvements (#790)
* Upgrade godo to latest * Fix a bunch of issues found by * Running staticcheck on a codebase for the first time is a sobering experience * go mod tidy * More static improvements Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
@@ -2,14 +2,14 @@ package newrelic
|
||||
|
||||
// AlertCondition describes what triggers an alert for a specific policy.
|
||||
type AlertCondition struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Enabled bool `json:"name,omitempty"`
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Entities []string `json:"entities,omitempty"`
|
||||
ID int `json:"id,omitempty"`
|
||||
Metric string `json:"metric,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
RunbookURL string `json:"runbook_url,omitempty"`
|
||||
Terms []AlertConditionTerm `json:"terms,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
UserDefined AlertUserDefined `json:"user_defined,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
package newrelic
|
||||
|
||||
type getAlertEventsTestsInput struct {
|
||||
options *AlertEventOptions
|
||||
data string
|
||||
}
|
||||
|
||||
type getAlertEventsTestsOutput struct {
|
||||
data []AlertEvent
|
||||
err error
|
||||
}
|
||||
|
||||
const (
|
||||
testAlertEventJSON = `
|
||||
{
|
||||
"id": 123,
|
||||
"event_type": "VIOLATION_OPEN",
|
||||
"product": "APM",
|
||||
"entity_type": "Application",
|
||||
"entity_group_id": 1234,
|
||||
"entity_id": 12,
|
||||
"priority": "Warning",
|
||||
"description": "Test Alert",
|
||||
"timestamp": 1472355451353,
|
||||
"incident_id": 23
|
||||
}
|
||||
`
|
||||
)
|
||||
|
||||
var (
|
||||
testAlertEvent = AlertEvent{
|
||||
ID: 123,
|
||||
EventType: "VIOLATION_OPEN",
|
||||
Product: "APM",
|
||||
EntityType: "Application",
|
||||
EntityGroupID: 1234,
|
||||
EntityID: 12,
|
||||
Priority: "Warning",
|
||||
Description: "Test Alert",
|
||||
Timestamp: 1472355451353,
|
||||
IncidentID: 23,
|
||||
}
|
||||
getAlertEventsTests = []struct {
|
||||
in getAlertEventsTestsInput
|
||||
out getAlertEventsTestsOutput
|
||||
}{
|
||||
{
|
||||
getAlertEventsTestsInput{
|
||||
options: nil,
|
||||
data: `{"recent_events": [` + testAlertEventJSON + `]}`,
|
||||
},
|
||||
getAlertEventsTestsOutput{
|
||||
data: []AlertEvent{
|
||||
testAlertEvent,
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
alertEventOptionsStringerTests = []struct {
|
||||
in *AlertEventOptions
|
||||
out string
|
||||
}{
|
||||
{
|
||||
&AlertEventOptions{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
nil,
|
||||
"",
|
||||
},
|
||||
{
|
||||
&AlertEventOptions{
|
||||
Filter: AlertEventFilter{
|
||||
Product: "testProduct",
|
||||
EntityType: "testEntityType",
|
||||
EntityGroupID: 123,
|
||||
EntityID: 1234,
|
||||
EventType: "testEventType",
|
||||
},
|
||||
Page: 1,
|
||||
},
|
||||
"filter%5Bentity_group_id%5D=123" +
|
||||
"&filter%5Bentity_id%5D=1234" +
|
||||
"&filter%5Bentity_type%5D=testEntityType" +
|
||||
"&filter%5Bevent_type%5D=testEventType" +
|
||||
"&filter%5Bproduct%5D=testProduct" +
|
||||
"&page=1",
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -24,7 +24,7 @@ type ApplicationDeployment struct {
|
||||
Revision string `json:"revision,omitempty"`
|
||||
Changelog string `json:"changelog,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
User string `json:"user,omitemtpy"`
|
||||
User string `json:"user,omitempty"`
|
||||
Timestamp time.Time `json:"timestamp,omitempty"`
|
||||
Links ApplicationDeploymentLinks `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
package newrelic
|
||||
|
||||
type getApplicationMetricsTestsInput struct {
|
||||
id int
|
||||
options *MetricsOptions
|
||||
data string
|
||||
}
|
||||
|
||||
type getApplicationMetricsTestsOutput struct {
|
||||
data []Metric
|
||||
err error
|
||||
}
|
||||
|
||||
type getApplicationMetricDataTestsInput struct {
|
||||
id int
|
||||
Names []string
|
||||
options *MetricDataOptions
|
||||
data string
|
||||
}
|
||||
|
||||
type getApplicationMetricDataTestsOutput struct {
|
||||
data *MetricDataResponse
|
||||
err error
|
||||
}
|
||||
|
||||
const (
|
||||
testApplicationMetricJSON = `
|
||||
{
|
||||
"name": "testMetric",
|
||||
"values": [
|
||||
"testValue1",
|
||||
"testValue2"
|
||||
]
|
||||
}
|
||||
`
|
||||
)
|
||||
|
||||
var (
|
||||
testApplicationMetric = Metric{
|
||||
Name: "testMetric",
|
||||
Values: []string{"testValue1", "testValue2"},
|
||||
}
|
||||
getApplicaitonMetricsTests = []struct {
|
||||
in getApplicationMetricsTestsInput
|
||||
out getApplicationMetricsTestsOutput
|
||||
}{
|
||||
{
|
||||
getApplicationMetricsTestsInput{
|
||||
id: 123,
|
||||
options: nil,
|
||||
data: `{"metrics": [` +
|
||||
testApplicationMetricJSON + `,` +
|
||||
testApplicationMetricJSON +
|
||||
`]}`,
|
||||
},
|
||||
getApplicationMetricsTestsOutput{
|
||||
data: []Metric{
|
||||
testApplicationMetric,
|
||||
testApplicationMetric,
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
applicationMetricOptionsStringerTests = []struct {
|
||||
in *MetricsOptions
|
||||
out string
|
||||
}{
|
||||
{
|
||||
&MetricsOptions{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
nil,
|
||||
"",
|
||||
},
|
||||
{
|
||||
&MetricsOptions{
|
||||
Name: "testName",
|
||||
Page: 5,
|
||||
},
|
||||
"name=testName" +
|
||||
"&page=5",
|
||||
},
|
||||
}
|
||||
applicationMetricDataOptionsStringerTests = []struct {
|
||||
in *MetricDataOptions
|
||||
out string
|
||||
}{
|
||||
{
|
||||
&MetricDataOptions{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
nil,
|
||||
"",
|
||||
},
|
||||
{
|
||||
&MetricDataOptions{
|
||||
Names: Array{[]string{"test1", "test2"}},
|
||||
Values: Array{[]string{"value1", "value2"}},
|
||||
From: testTime,
|
||||
To: testTime,
|
||||
Period: 123,
|
||||
Summarize: true,
|
||||
Raw: true,
|
||||
},
|
||||
"from=" + testTimeStringEscaped +
|
||||
"&names%5B%5D=test1" +
|
||||
"&names%5B%5D=test2" +
|
||||
"&period=123" +
|
||||
"&raw=true" +
|
||||
"&summarize=true" +
|
||||
"&to=" + testTimeStringEscaped +
|
||||
"&values%5B%5D=value1&values%5B%5D=value2",
|
||||
},
|
||||
}
|
||||
testApplicationMetricDataJSON = `
|
||||
{
|
||||
"metric_data": {
|
||||
"from": "` + testTimeRawString + `",
|
||||
"to": "` + testTimeRawString + `",
|
||||
"metrics_found": ["name1"],
|
||||
"metrics_not_found": ["name2"],
|
||||
"metrics": [
|
||||
{
|
||||
"name": "testName",
|
||||
"timeslices": [
|
||||
{
|
||||
"from": "` + testTimeRawString + `",
|
||||
"to": "` + testTimeRawString + `",
|
||||
"values": {"testVal": 1.234}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`
|
||||
testApplicationMetricData = MetricData{
|
||||
Name: "testName",
|
||||
Timeslices: []MetricTimeslice{
|
||||
MetricTimeslice{
|
||||
From: testTime,
|
||||
To: testTime,
|
||||
Values: map[string]float64{
|
||||
"testVal": 1.234,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
getApplicaitonMetricDataTests = []struct {
|
||||
in getApplicationMetricDataTestsInput
|
||||
out getApplicationMetricDataTestsOutput
|
||||
}{
|
||||
{
|
||||
getApplicationMetricDataTestsInput{
|
||||
id: 1234,
|
||||
Names: []string{"name1", "name2"},
|
||||
options: &MetricDataOptions{},
|
||||
data: testApplicationMetricDataJSON,
|
||||
},
|
||||
getApplicationMetricDataTestsOutput{
|
||||
data: &MetricDataResponse{
|
||||
From: testTime,
|
||||
To: testTime,
|
||||
MetricsFound: []string{"name1"},
|
||||
MetricsNotFound: []string{"name2"},
|
||||
Metrics: []MetricData{testApplicationMetricData},
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -1,165 +0,0 @@
|
||||
package newrelic
|
||||
|
||||
type getApplicationsTestsInput struct {
|
||||
options *ApplicationOptions
|
||||
data string
|
||||
}
|
||||
|
||||
type getApplicationsTestsOutput struct {
|
||||
data []Application
|
||||
err error
|
||||
}
|
||||
|
||||
type getApplicationTestsInput struct {
|
||||
id int
|
||||
data string
|
||||
}
|
||||
|
||||
type getApplicationTestsOutput struct {
|
||||
data *Application
|
||||
err error
|
||||
}
|
||||
|
||||
var (
|
||||
testApplicationJSON = `
|
||||
{
|
||||
"application_summary": {
|
||||
"apdex_score": 1.0,
|
||||
"apdex_target": 0.5,
|
||||
"error_rate": 0.0,
|
||||
"host_count": 1,
|
||||
"instance_count": 1,
|
||||
"response_time": 0.263,
|
||||
"throughput": 12.3
|
||||
},
|
||||
"end_user_summary": {
|
||||
"response_time": 0.263,
|
||||
"throughput": 12.3,
|
||||
"apdex_target": 0.5,
|
||||
"apdex_score": 1
|
||||
},
|
||||
"health_status": "green",
|
||||
"id": 12345,
|
||||
"language": "java",
|
||||
"last_reported_at": "` + testTimeRawString + `",
|
||||
"links": {
|
||||
"alert_policy": 123,
|
||||
"application_hosts": [
|
||||
1234567
|
||||
],
|
||||
"application_instances": [
|
||||
1234568
|
||||
],
|
||||
"servers": [
|
||||
54321
|
||||
]
|
||||
},
|
||||
"name": "test.example.com",
|
||||
"reporting": true,
|
||||
"settings": {
|
||||
"app_apdex_threshold": 0.5,
|
||||
"enable_real_user_monitoring": true,
|
||||
"end_user_apdex_threshold": 1.0,
|
||||
"use_server_side_config": false
|
||||
}
|
||||
}
|
||||
`
|
||||
testApplication = Application{
|
||||
ID: 12345,
|
||||
Name: "test.example.com",
|
||||
Language: "java",
|
||||
HealthStatus: "green",
|
||||
Reporting: true,
|
||||
LastReportedAt: testTime,
|
||||
ApplicationSummary: ApplicationSummary{
|
||||
ResponseTime: 0.263,
|
||||
Throughput: 12.3,
|
||||
ErrorRate: 0,
|
||||
ApdexTarget: 0.5,
|
||||
ApdexScore: 1,
|
||||
HostCount: 1,
|
||||
InstanceCount: 1,
|
||||
ConcurrentInstanceCount: 0,
|
||||
},
|
||||
EndUserSummary: EndUserSummary{
|
||||
ResponseTime: 0.263,
|
||||
Throughput: 12.3,
|
||||
ApdexTarget: 0.5,
|
||||
ApdexScore: 1,
|
||||
},
|
||||
Settings: Settings{
|
||||
AppApdexThreshold: 0.5,
|
||||
EndUserApdexThreshold: 1,
|
||||
EnableRealUserMonitoring: true,
|
||||
UseServerSideConfig: false,
|
||||
},
|
||||
Links: Links{
|
||||
Servers: []int{54321},
|
||||
ApplicationHosts: []int{1234567},
|
||||
ApplicationInstances: []int{1234568},
|
||||
AlertPolicy: 123,
|
||||
},
|
||||
}
|
||||
testApplications = []Application{
|
||||
testApplication,
|
||||
testApplication,
|
||||
}
|
||||
getApplicationTests = []struct {
|
||||
in getApplicationTestsInput
|
||||
out getApplicationTestsOutput
|
||||
}{
|
||||
{
|
||||
getApplicationTestsInput{
|
||||
id: 12345,
|
||||
data: `{ "application":` + testApplicationJSON + `}`,
|
||||
},
|
||||
getApplicationTestsOutput{
|
||||
data: &testApplication,
|
||||
},
|
||||
},
|
||||
}
|
||||
getApplicationsTests = []struct {
|
||||
in getApplicationsTestsInput
|
||||
out getApplicationsTestsOutput
|
||||
}{
|
||||
{
|
||||
getApplicationsTestsInput{
|
||||
options: nil,
|
||||
data: `{"applications":[` + testApplicationJSON + "," + testApplicationJSON + "]}",
|
||||
},
|
||||
getApplicationsTestsOutput{
|
||||
data: testApplications,
|
||||
err: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
applicationOptionsStringerTests = []struct {
|
||||
in *ApplicationOptions
|
||||
out string
|
||||
}{
|
||||
{
|
||||
&ApplicationOptions{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
&ApplicationOptions{
|
||||
Filter: ApplicationFilter{
|
||||
Name: "testName",
|
||||
Host: "testHost",
|
||||
IDs: []int{123, 456},
|
||||
Language: "java",
|
||||
},
|
||||
Page: 5,
|
||||
},
|
||||
`filter%5Bhost%5D=testHost` +
|
||||
`&filter%5Bids%5D=123%2C456` +
|
||||
`&filter%5Blanguage%5D=java` +
|
||||
`&filter%5Bname%5D=testName` +
|
||||
`&page=5`,
|
||||
},
|
||||
{
|
||||
nil,
|
||||
"",
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -1,17 +0,0 @@
|
||||
package newrelic
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
testAPIKey = "test_api_key"
|
||||
testTimeRawString = "2016-01-20T20:29:38Z"
|
||||
)
|
||||
|
||||
var (
|
||||
testTime, _ = time.Parse(time.RFC3339, testTimeRawString)
|
||||
testTimeString = testTime.String()
|
||||
testTimeStringEscaped = url.QueryEscape(testTimeString)
|
||||
)
|
||||
@@ -52,25 +52,20 @@ func (c *Client) doRequest(req *http.Request, out interface{}) error {
|
||||
func encodeGetParams(params map[string]interface{}) string {
|
||||
s := url.Values{}
|
||||
for k, v := range params {
|
||||
switch v.(type) {
|
||||
switch val := v.(type) {
|
||||
case string:
|
||||
val := v.(string)
|
||||
if val != "" {
|
||||
s.Add(k, val)
|
||||
}
|
||||
case int:
|
||||
val := v.(int)
|
||||
// TODO: Zero values versus not defined
|
||||
if val != 0 {
|
||||
s.Add(k, strconv.Itoa(val))
|
||||
}
|
||||
case []string:
|
||||
val := v.([]string)
|
||||
if len(val) != 0 {
|
||||
s.Add(k, strings.Join(val, ","))
|
||||
}
|
||||
case []int:
|
||||
val := v.([]int)
|
||||
arr := []string{}
|
||||
for _, v := range val {
|
||||
arr = append(arr, strconv.Itoa(v))
|
||||
@@ -79,19 +74,15 @@ func encodeGetParams(params map[string]interface{}) string {
|
||||
s.Add(k, strings.Join(arr, ","))
|
||||
}
|
||||
case time.Time:
|
||||
val := v.(time.Time)
|
||||
if !val.IsZero() {
|
||||
s.Add(k, val.String())
|
||||
}
|
||||
case Array:
|
||||
val := v.(Array)
|
||||
for _, v := range val.arr {
|
||||
s.Add(k, v)
|
||||
}
|
||||
case bool:
|
||||
if v.(bool) {
|
||||
s.Add(k, "true")
|
||||
}
|
||||
s.Add(k, "true")
|
||||
default:
|
||||
s.Add(k, fmt.Sprintf("%v", v))
|
||||
}
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
package newrelic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type testJSONInterface struct {
|
||||
data string `json:"data"id,omitempty"`
|
||||
}
|
||||
|
||||
type testParamsInterface struct {
|
||||
data string
|
||||
}
|
||||
|
||||
type doGetTestsInput struct {
|
||||
path string
|
||||
params *testParamsInterface
|
||||
out testJSONInterface
|
||||
status int
|
||||
data string
|
||||
}
|
||||
|
||||
type doGetTestsOutput struct {
|
||||
data testJSONInterface
|
||||
err error
|
||||
}
|
||||
|
||||
type doRequestTestsInput struct {
|
||||
req *http.Request
|
||||
out testJSONInterface
|
||||
status int
|
||||
data string
|
||||
}
|
||||
|
||||
type doRequestTestOutput struct {
|
||||
data testJSONInterface
|
||||
err error
|
||||
}
|
||||
|
||||
var (
|
||||
doGetTests = []struct {
|
||||
in doGetTestsInput
|
||||
out doGetTestsOutput
|
||||
}{
|
||||
{
|
||||
doGetTestsInput{
|
||||
path: "somePath",
|
||||
params: &testParamsInterface{"testData"},
|
||||
out: testJSONInterface{"testData"},
|
||||
status: 200,
|
||||
data: `{"data": "testStructData"}`,
|
||||
},
|
||||
doGetTestsOutput{
|
||||
data: testJSONInterface{"testData"},
|
||||
err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
doGetTestsInput{
|
||||
status: 404,
|
||||
data: "Not Found",
|
||||
},
|
||||
doGetTestsOutput{
|
||||
err: errors.New("newrelic http error (404 Not Found): Not Found"),
|
||||
},
|
||||
},
|
||||
}
|
||||
testRequest, _ = http.NewRequest("GET", "http://testPath",
|
||||
strings.NewReader("testBody"))
|
||||
doRequestTests = []struct {
|
||||
in doRequestTestsInput
|
||||
out doRequestTestOutput
|
||||
}{
|
||||
{
|
||||
doRequestTestsInput{
|
||||
req: testRequest,
|
||||
out: testJSONInterface{"testData"},
|
||||
status: 200,
|
||||
data: `{"data": "testStructData"}`,
|
||||
},
|
||||
doRequestTestOutput{
|
||||
data: testJSONInterface{"testData"},
|
||||
err: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
encodeGetParamsTests = []struct {
|
||||
in map[string]interface{}
|
||||
out string
|
||||
}{
|
||||
{
|
||||
map[string]interface{}{
|
||||
"testInt": 5,
|
||||
"testString": "test",
|
||||
"testStringSlice": []string{"test1", "test2"},
|
||||
"testArray": Array{[]string{"test1", "test2"}},
|
||||
"testTime": testTime,
|
||||
},
|
||||
"testArray=test1" +
|
||||
"&testArray=test2" +
|
||||
"&testInt=5" +
|
||||
"&testString=test" +
|
||||
"&testStringSlice=test1%2Ctest2" +
|
||||
"&testTime=" + testTimeStringEscaped,
|
||||
},
|
||||
{
|
||||
map[string]interface{}{
|
||||
"unexpectedType": map[string]string{"unexpected": "type"},
|
||||
},
|
||||
"unexpectedType=map%5Bunexpected%3Atype%5D",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func (m *testParamsInterface) String() string {
|
||||
return "data=testData"
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
// Usage describes usage over a single time period.
|
||||
type Usage struct {
|
||||
From time.Time `json"from,omitempty"`
|
||||
From time.Time `json:"from,omitempty"`
|
||||
To time.Time `json:"to,omitempty"`
|
||||
Usage int `json:"usage,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user