Skip to content

Commit

Permalink
Nov fixes (#67)
Browse files Browse the repository at this point in the history
* maxDialyGB check

* add no-content success response code

* case insensitive endpoint type

* lint
  • Loading branch information
yyyogev authored Nov 10, 2020
1 parent 5bf74cf commit 538d15a
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 96 deletions.
6 changes: 2 additions & 4 deletions alerts/alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"testing"
)



var (
mux *http.ServeMux
server *httptest.Server
Expand Down Expand Up @@ -53,7 +51,7 @@ func createValidAlert() alerts.CreateAlertType {
Filter: "",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand All @@ -77,7 +75,7 @@ func createUpdateAlert() alerts.CreateAlertType {
Filter: "",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand Down
8 changes: 4 additions & 4 deletions alerts/client_alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const (
fldTitle string = "title"
fldValueAggregationField string = "valueAggregationField"
fldValueAggregationType string = "valueAggregationType"
fldTags string = "tags"
fldTags string = "tags"
)

type CreateAlertType struct {
Expand All @@ -71,7 +71,7 @@ type CreateAlertType struct {
Title string
ValueAggregationField interface{}
ValueAggregationType string
Tags []string
Tags []string
}

type AlertType struct {
Expand All @@ -96,7 +96,7 @@ type AlertType struct {
Title string
ValueAggregationField interface{}
ValueAggregationType string
Tags []string
Tags []string
}

type SeverityThresholdType struct {
Expand All @@ -121,7 +121,7 @@ func jsonAlertToAlert(jsonAlert map[string]interface{}) AlertType {
Threshold: int(jsonAlert[fldThreshold].(float64)),
Title: jsonAlert[fldTitle].(string),
ValueAggregationType: jsonAlert[fldValueAggregationType].(string),
Tags: []string{},
Tags: []string{},
}

if jsonAlert[fldGroupByAggregationFields] != nil {
Expand Down
1 change: 0 additions & 1 deletion alerts/client_alerts_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,5 @@ func (c *AlertsClient) CreateAlert(alert CreateAlertType) (*AlertType, error) {

retVal := jsonAlertToAlert(jsonResponse)


return &retVal, nil
}
22 changes: 11 additions & 11 deletions alerts/create_alerts_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestIntegrationAlerts_CreateAlert(t *testing.T) {
Filter: "",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand All @@ -33,7 +33,7 @@ func TestIntegrationAlerts_CreateAlert(t *testing.T) {
ValueAggregationField: nil,
GroupByAggregationFields: []interface{}{"my_field"},
AlertNotificationEndpoints: []interface{}{},
Tags: []string{"some", "words"},
Tags: []string{"some", "words"},
})

time.Sleep(3 * time.Second)
Expand All @@ -54,7 +54,7 @@ func TestIntegrationAlerts_CreateAlertWithFilter(t *testing.T) {
Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestIntegrationAlerts_CreateAlertInvalidFilter(t *testing.T) {
Filter: "Invalid Filter",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestIntegrationAlerts_CreateAlertInvalidAggregationType(t *testing.T) {
Filter: "",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestIntegrationAlerts_CreateAlertInvaldValueAggregationField(t *testing.T)
Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestIntegrationAlerts_CreateAlertInvalidValueAggregationTypeNone(t *testing
Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestIntegrationAlerts_CreateAlertInvalidValueAggregationTypeCount(t *testin
Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestIntegrationAlerts_CreateAlertNoNotifications(t *testing.T) {
Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand Down Expand Up @@ -273,7 +273,7 @@ func TestIntegrationAlerts_CreateAlertNoQueryString(t *testing.T) {
Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestIntegrationAlerts_CreateAlertInvalidSeverity(t *testing.T) {
Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
"TEST",
10,
},
Expand Down
2 changes: 1 addition & 1 deletion alerts/create_alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestAlerts_CreateAlert(t *testing.T) {
ValueAggregationField: nil,
GroupByAggregationFields: []interface{}{"my_field"},
AlertNotificationEndpoints: []interface{}{},
Tags: []string{"some", "words"},
Tags: []string{"some", "words"},
}

alert, err := underTest.CreateAlert(testAlert)
Expand Down
2 changes: 1 addition & 1 deletion alerts/delete_alerts_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestIntegrationAlerts_DeleteAlert(t *testing.T) {
Filter: "",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand Down
2 changes: 1 addition & 1 deletion alerts/get_alerts_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestIntegrationAlerts_GetAlert(t *testing.T) {
Filter: "",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand Down
4 changes: 2 additions & 2 deletions alerts/update_alerts_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestIntegrationAlerts_UpdateAlert(t *testing.T) {
Filter: "",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand All @@ -43,7 +43,7 @@ func TestIntegrationAlerts_UpdateAlert(t *testing.T) {
Filter: "",
Operation: alerts.OperatorGreaterThan,
SeverityThresholdTiers: []alerts.SeverityThresholdType{
alerts.SeverityThresholdType{
{
alerts.SeverityHigh,
10,
},
Expand Down
1 change: 0 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
)


const (
ERROR_CODE = "errorCode"
ERROR_MESSAGE = "errorMessage"
Expand Down
14 changes: 7 additions & 7 deletions endpoints/client_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ const (
)

const (
EndpointTypeSlack endpointType = "Slack"
EndpointTypeCustom endpointType = "Custom"
EndpointTypePagerDuty endpointType = "PagerDuty"
EndpointTypeBigPanda endpointType = "BigPanda"
EndpointTypeDataDog endpointType = "Datadog"
EndpointTypeVictorOps endpointType = "VictorOps"
EndpointTypeSlack endpointType = "slack"
EndpointTypeCustom endpointType = "custom"
EndpointTypePagerDuty endpointType = "pagerduty"
EndpointTypeBigPanda endpointType = "bigpanda"
EndpointTypeDataDog endpointType = "datadog"
EndpointTypeVictorOps endpointType = "victorops"
)

type (
Expand All @@ -65,7 +65,7 @@ type Endpoint struct {
}

func jsonEndpointToEndpoint(jsonEndpoint map[string]interface{}) Endpoint {
t := jsonEndpoint[fldEndpointType].(string)
t := strings.ToLower(jsonEndpoint[fldEndpointType].(string))

endpoint := Endpoint{
Id: int64(jsonEndpoint[fldEndpointId].(float64)),
Expand Down
70 changes: 37 additions & 33 deletions sub_accounts/client_sub_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

const (
subAccountServiceEndpoint = "%s/v1/account-management/time-based-accounts"
loggerName = "logzio-client"
loggerName = "logzio-client"
)

const (
fldAccountId string = "accountId" //required
fldAccountId string = "accountId" //required
fldEmail string = "email" //required
fldAccountName string = "accountName" //required
fldMaxDailyGB string = "maxDailyGB"
Expand Down Expand Up @@ -42,33 +42,34 @@ type SubAccount struct {
}

type SubAccountRelation struct {
OwnerAccountId int64 `json:"ownerAccountId"`
SubAccountId int64 `json:"subAccountId"`
Searchable bool `json:"searchable"`
Accessible bool `json:"accessible"`
CreatedDate int64 `json:"createdDate"`
LastUpdatedDate int64 `json:"lastUpdatedDate"`
LastUpdaterUserId int64 `json:"lastUpdaterUserId"`
Type string `json:"type"`
OwnerAccountId int64 `json:"ownerAccountId"`
SubAccountId int64 `json:"subAccountId"`
Searchable bool `json:"searchable"`
Accessible bool `json:"accessible"`
CreatedDate int64 `json:"createdDate"`
LastUpdatedDate int64 `json:"lastUpdatedDate"`
LastUpdaterUserId int64 `json:"lastUpdaterUserId"`
Type string `json:"type"`
}

type Account struct {
AccountId int64 `json:"accountId"`
AccountToken string `json:"accountToken"`
AccountName string `json:"accountName"`
Active bool `json:"active"`
EsIndexPrefix string `json:"esIndexPrefix"`
MaxDailyGB int64 `json:"maxDailyGB"`
RetentionDays int64 `json:"retentionDays"`
AccountId int64 `json:"accountId"`
AccountToken string `json:"accountToken"`
AccountName string `json:"accountName"`
Active bool `json:"active"`
EsIndexPrefix string `json:"esIndexPrefix"`
MaxDailyGB int64 `json:"maxDailyGB"`
RetentionDays int64 `json:"retentionDays"`
}

type SubAccountDetailed struct {
SubAccountRelation SubAccountRelation `json:"subAccountRelation"`
Account Account `json:"account"`
SharingObjectAccounts []interface{} `json:"sharingObjectsAccounts"`
UtilizationSettings map[string]interface{} `json:"utilizationSettings"`
DailyUsagesList map[string]interface{} `json:"dailyUsagesList"`
DocSizeSetting bool `json:"docSizeSetting"`}
SubAccountRelation SubAccountRelation `json:"subAccountRelation"`
Account Account `json:"account"`
SharingObjectAccounts []interface{} `json:"sharingObjectsAccounts"`
UtilizationSettings map[string]interface{} `json:"utilizationSettings"`
DailyUsagesList map[string]interface{} `json:"dailyUsagesList"`
DocSizeSetting bool `json:"docSizeSetting"`
}

type SubAccountCreate struct {
Email string
Expand All @@ -86,7 +87,7 @@ type SubAccountCreate struct {

type SubAccountClient struct {
*client.Client
logger hclog.Logger
logger hclog.Logger
}

// Creates a new entry point into the sub-account functions, accepts the user's logz.io API token and account Id
Expand All @@ -110,10 +111,14 @@ func New(apiToken string, baseUrl string) (*SubAccountClient, error) {
}

func jsonToSubAccount(json map[string]interface{}) SubAccount {
var maxDailyGB float32 = 0
if json[fldMaxDailyGB] != nil {
maxDailyGB = float32(json[fldMaxDailyGB].(float64))
}
subAccount := SubAccount{
Id: int64(json[fldAccountId].(float64)),
AccountName: json[fldAccountName].(string),
MaxDailyGB: float32(json[fldMaxDailyGB].(float64)),
MaxDailyGB: maxDailyGB,
RetentionDays: int32(json[fldRetentionDays].(float64)),
Searchable: json[fldSearchable].(bool),
Accessible: json[fldAccessible].(bool),
Expand All @@ -122,18 +127,17 @@ func jsonToSubAccount(json map[string]interface{}) SubAccount {
UtilizationSettings: json[fldUtilizationSettings].(map[string]interface{}),
}

if json[fldUtilizationSettings] != nil {
subAccount.UtilizationSettings = json[fldUtilizationSettings].(map[string]interface{})
for key, value := range subAccount.UtilizationSettings {
if value == nil {
delete(subAccount.UtilizationSettings, key)
}
if json[fldUtilizationSettings] != nil {
subAccount.UtilizationSettings = json[fldUtilizationSettings].(map[string]interface{})
for key, value := range subAccount.UtilizationSettings {
if value == nil {
delete(subAccount.UtilizationSettings, key)
}
}
}
return subAccount
}


func jsonToDetailedSubAccount(jsonMap map[string]interface{}) (*SubAccountDetailed, error) {
jsonBytes, err := json.Marshal(jsonMap)
if err != nil {
Expand All @@ -145,4 +149,4 @@ func jsonToDetailedSubAccount(jsonMap map[string]interface{}) (*SubAccountDetail
return nil, err
}
return &subAccount, nil
}
}
Loading

0 comments on commit 538d15a

Please sign in to comment.