diff --git a/alerting/provider/custom/custom.go b/alerting/provider/custom/custom.go index 7ef3fd20..c1a72d75 100644 --- a/alerting/provider/custom/custom.go +++ b/alerting/provider/custom/custom.go @@ -13,7 +13,7 @@ import ( // AlertProvider is the configuration necessary for sending an alert using a custom HTTP request // Technically, all alert providers should be reachable using the custom alert provider type AlertProvider struct { - Url string `yaml:"url"` + URL string `yaml:"url"` Method string `yaml:"method,omitempty"` Body string `yaml:"body,omitempty"` Headers map[string]string `yaml:"headers,omitempty"` @@ -21,7 +21,7 @@ type AlertProvider struct { // IsValid returns whether the provider's configuration is valid func (provider *AlertProvider) IsValid() bool { - return len(provider.Url) > 0 + return len(provider.URL) > 0 } // ToCustomAlertProvider converts the provider into a custom.AlertProvider @@ -31,7 +31,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler func (provider *AlertProvider) buildRequest(serviceName, alertDescription string, resolved bool) *http.Request { body := provider.Body - providerUrl := provider.Url + providerURL := provider.URL method := provider.Method if strings.Contains(body, "[ALERT_DESCRIPTION]") { body = strings.ReplaceAll(body, "[ALERT_DESCRIPTION]", alertDescription) @@ -46,24 +46,24 @@ func (provider *AlertProvider) buildRequest(serviceName, alertDescription string body = strings.ReplaceAll(body, "[ALERT_TRIGGERED_OR_RESOLVED]", "TRIGGERED") } } - if strings.Contains(providerUrl, "[ALERT_DESCRIPTION]") { - providerUrl = strings.ReplaceAll(providerUrl, "[ALERT_DESCRIPTION]", alertDescription) + if strings.Contains(providerURL, "[ALERT_DESCRIPTION]") { + providerURL = strings.ReplaceAll(providerURL, "[ALERT_DESCRIPTION]", alertDescription) } - if strings.Contains(providerUrl, "[SERVICE_NAME]") { - providerUrl = strings.ReplaceAll(providerUrl, "[SERVICE_NAME]", serviceName) + if strings.Contains(providerURL, "[SERVICE_NAME]") { + providerURL = strings.ReplaceAll(providerURL, "[SERVICE_NAME]", serviceName) } - if strings.Contains(providerUrl, "[ALERT_TRIGGERED_OR_RESOLVED]") { + if strings.Contains(providerURL, "[ALERT_TRIGGERED_OR_RESOLVED]") { if resolved { - providerUrl = strings.ReplaceAll(providerUrl, "[ALERT_TRIGGERED_OR_RESOLVED]", "RESOLVED") + providerURL = strings.ReplaceAll(providerURL, "[ALERT_TRIGGERED_OR_RESOLVED]", "RESOLVED") } else { - providerUrl = strings.ReplaceAll(providerUrl, "[ALERT_TRIGGERED_OR_RESOLVED]", "TRIGGERED") + providerURL = strings.ReplaceAll(providerURL, "[ALERT_TRIGGERED_OR_RESOLVED]", "TRIGGERED") } } if len(method) == 0 { method = "GET" } bodyBuffer := bytes.NewBuffer([]byte(body)) - request, _ := http.NewRequest(method, providerUrl, bodyBuffer) + request, _ := http.NewRequest(method, providerURL, bodyBuffer) for k, v := range provider.Headers { request.Header.Set(k, v) } @@ -73,7 +73,7 @@ func (provider *AlertProvider) buildRequest(serviceName, alertDescription string // Send a request to the alert provider and return the body func (provider *AlertProvider) Send(serviceName, alertDescription string, resolved bool) ([]byte, error) { request := provider.buildRequest(serviceName, alertDescription, resolved) - response, err := client.GetHttpClient(false).Do(request) + response, err := client.GetHTTPClient(false).Do(request) if err != nil { return nil, err } diff --git a/alerting/provider/custom/custom_test.go b/alerting/provider/custom/custom_test.go index 976d78d6..73e12d3b 100644 --- a/alerting/provider/custom/custom_test.go +++ b/alerting/provider/custom/custom_test.go @@ -7,11 +7,11 @@ import ( ) func TestAlertProvider_IsValid(t *testing.T) { - invalidProvider := AlertProvider{Url: ""} + invalidProvider := AlertProvider{URL: ""} if invalidProvider.IsValid() { t.Error("provider shouldn't have been valid") } - validProvider := AlertProvider{Url: "http://example.com"} + validProvider := AlertProvider{URL: "http://example.com"} if !validProvider.IsValid() { t.Error("provider should've been valid") } @@ -19,17 +19,17 @@ func TestAlertProvider_IsValid(t *testing.T) { func TestAlertProvider_buildRequestWhenResolved(t *testing.T) { const ( - ExpectedUrl = "http://example.com/service-name?event=RESOLVED&description=alert-description" + ExpectedURL = "http://example.com/service-name?event=RESOLVED&description=alert-description" ExpectedBody = "service-name,alert-description,RESOLVED" ) customAlertProvider := &AlertProvider{ - Url: "http://example.com/[SERVICE_NAME]?event=[ALERT_TRIGGERED_OR_RESOLVED]&description=[ALERT_DESCRIPTION]", + URL: "http://example.com/[SERVICE_NAME]?event=[ALERT_TRIGGERED_OR_RESOLVED]&description=[ALERT_DESCRIPTION]", Body: "[SERVICE_NAME],[ALERT_DESCRIPTION],[ALERT_TRIGGERED_OR_RESOLVED]", Headers: nil, } request := customAlertProvider.buildRequest("service-name", "alert-description", true) - if request.URL.String() != ExpectedUrl { - t.Error("expected URL to be", ExpectedUrl, "was", request.URL.String()) + if request.URL.String() != ExpectedURL { + t.Error("expected URL to be", ExpectedURL, "was", request.URL.String()) } body, _ := ioutil.ReadAll(request.Body) if string(body) != ExpectedBody { @@ -39,17 +39,17 @@ func TestAlertProvider_buildRequestWhenResolved(t *testing.T) { func TestAlertProvider_buildRequestWhenTriggered(t *testing.T) { const ( - ExpectedUrl = "http://example.com/service-name?event=TRIGGERED&description=alert-description" + ExpectedURL = "http://example.com/service-name?event=TRIGGERED&description=alert-description" ExpectedBody = "service-name,alert-description,TRIGGERED" ) customAlertProvider := &AlertProvider{ - Url: "http://example.com/[SERVICE_NAME]?event=[ALERT_TRIGGERED_OR_RESOLVED]&description=[ALERT_DESCRIPTION]", + URL: "http://example.com/[SERVICE_NAME]?event=[ALERT_TRIGGERED_OR_RESOLVED]&description=[ALERT_DESCRIPTION]", Body: "[SERVICE_NAME],[ALERT_DESCRIPTION],[ALERT_TRIGGERED_OR_RESOLVED]", Headers: map[string]string{"Authorization": "Basic hunter2"}, } request := customAlertProvider.buildRequest("service-name", "alert-description", false) - if request.URL.String() != ExpectedUrl { - t.Error("expected URL to be", ExpectedUrl, "was", request.URL.String()) + if request.URL.String() != ExpectedURL { + t.Error("expected URL to be", ExpectedURL, "was", request.URL.String()) } body, _ := ioutil.ReadAll(request.Body) if string(body) != ExpectedBody { @@ -58,7 +58,7 @@ func TestAlertProvider_buildRequestWhenTriggered(t *testing.T) { } func TestAlertProvider_ToCustomAlertProvider(t *testing.T) { - provider := AlertProvider{Url: "http://example.com"} + provider := AlertProvider{URL: "http://example.com"} customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, true) if customAlertProvider == nil { t.Error("customAlertProvider shouldn't have been nil") diff --git a/alerting/provider/pagerduty/pagerduty.go b/alerting/provider/pagerduty/pagerduty.go index 9780ccd7..50abc31c 100644 --- a/alerting/provider/pagerduty/pagerduty.go +++ b/alerting/provider/pagerduty/pagerduty.go @@ -31,7 +31,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler resolveKey = "" } return &custom.AlertProvider{ - Url: "https://events.pagerduty.com/v2/enqueue", + URL: "https://events.pagerduty.com/v2/enqueue", Method: "POST", Body: fmt.Sprintf(`{ "routing_key": "%s", diff --git a/alerting/provider/slack/slack.go b/alerting/provider/slack/slack.go index 621145da..c2c818f5 100644 --- a/alerting/provider/slack/slack.go +++ b/alerting/provider/slack/slack.go @@ -8,12 +8,12 @@ import ( // AlertProvider is the configuration necessary for sending an alert using Slack type AlertProvider struct { - WebhookUrl string `yaml:"webhook-url"` + WebhookURL string `yaml:"webhook-url"` } // IsValid returns whether the provider's configuration is valid func (provider *AlertProvider) IsValid() bool { - return len(provider.WebhookUrl) > 0 + return len(provider.WebhookURL) > 0 } // ToCustomAlertProvider converts the provider into a custom.AlertProvider @@ -38,7 +38,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler results += fmt.Sprintf("%s - `%s`\n", prefix, conditionResult.Condition) } return &custom.AlertProvider{ - Url: provider.WebhookUrl, + URL: provider.WebhookURL, Method: "POST", Body: fmt.Sprintf(`{ "text": "", diff --git a/alerting/provider/slack/slack_test.go b/alerting/provider/slack/slack_test.go index 6ba8b3db..9b853d5b 100644 --- a/alerting/provider/slack/slack_test.go +++ b/alerting/provider/slack/slack_test.go @@ -7,18 +7,18 @@ import ( ) func TestAlertProvider_IsValid(t *testing.T) { - invalidProvider := AlertProvider{WebhookUrl: ""} + invalidProvider := AlertProvider{WebhookURL: ""} if invalidProvider.IsValid() { t.Error("provider shouldn't have been valid") } - validProvider := AlertProvider{WebhookUrl: "http://example.com"} + validProvider := AlertProvider{WebhookURL: "http://example.com"} if !validProvider.IsValid() { t.Error("provider should've been valid") } } func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) { - provider := AlertProvider{WebhookUrl: "http://example.com"} + provider := AlertProvider{WebhookURL: "http://example.com"} customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true) if customAlertProvider == nil { t.Error("customAlertProvider shouldn't have been nil") @@ -29,7 +29,7 @@ func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) { } func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) { - provider := AlertProvider{WebhookUrl: "http://example.com"} + provider := AlertProvider{WebhookURL: "http://example.com"} customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "UNSUCCESSFUL_CONDITION", Success: false}}}, false) if customAlertProvider == nil { t.Error("customAlertProvider shouldn't have been nil") diff --git a/alerting/provider/twilio/twilio.go b/alerting/provider/twilio/twilio.go index 011e5487..94772739 100644 --- a/alerting/provider/twilio/twilio.go +++ b/alerting/provider/twilio/twilio.go @@ -30,7 +30,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler message = fmt.Sprintf("TRIGGERED: %s - %s", service.Name, alert.Description) } return &custom.AlertProvider{ - Url: fmt.Sprintf("https://api.twilio.com/2010-04-01/Accounts/%s/Messages.json", provider.SID), + URL: fmt.Sprintf("https://api.twilio.com/2010-04-01/Accounts/%s/Messages.json", provider.SID), Method: "POST", Body: url.Values{ "To": {provider.To}, diff --git a/client/client.go b/client/client.go index c081dc4b..1dad7832 100644 --- a/client/client.go +++ b/client/client.go @@ -8,15 +8,15 @@ import ( ) var ( - secureHttpClient *http.Client - insecureHttpClient *http.Client + secureHTTPClient *http.Client + insecureHTTPClient *http.Client ) -// GetHttpClient returns the shared HTTP client -func GetHttpClient(insecure bool) *http.Client { +// GetHTTPClient returns the shared HTTP client +func GetHTTPClient(insecure bool) *http.Client { if insecure { - if insecureHttpClient == nil { - insecureHttpClient = &http.Client{ + if insecureHTTPClient == nil { + insecureHTTPClient = &http.Client{ Timeout: time.Second * 10, Transport: &http.Transport{ TLSClientConfig: &tls.Config{ @@ -25,19 +25,18 @@ func GetHttpClient(insecure bool) *http.Client { }, } } - return insecureHttpClient - } else { - if secureHttpClient == nil { - secureHttpClient = &http.Client{ - Timeout: time.Second * 10, - } - } - return secureHttpClient + return insecureHTTPClient } + if secureHTTPClient == nil { + secureHTTPClient = &http.Client{ + Timeout: time.Second * 10, + } + } + return secureHTTPClient } -// CanCreateConnectionToTcpService checks whether a connection can be established with a TCP service -func CanCreateConnectionToTcpService(address string) bool { +// CanCreateConnectionToTCPService checks whether a connection can be established with a TCP service +func CanCreateConnectionToTCPService(address string) bool { conn, err := net.DialTimeout("tcp", address, 5*time.Second) if err != nil { return false diff --git a/client/client_test.go b/client/client_test.go index 539ccc55..cea1ea12 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -5,24 +5,24 @@ import ( ) func TestGetHttpClient(t *testing.T) { - if secureHttpClient != nil { - t.Error("secureHttpClient should've been nil since it hasn't been called a single time yet") + if secureHTTPClient != nil { + t.Error("secureHTTPClient should've been nil since it hasn't been called a single time yet") } - if insecureHttpClient != nil { - t.Error("insecureHttpClient should've been nil since it hasn't been called a single time yet") + if insecureHTTPClient != nil { + t.Error("insecureHTTPClient should've been nil since it hasn't been called a single time yet") } - _ = GetHttpClient(false) - if secureHttpClient == nil { - t.Error("secureHttpClient shouldn't have been nil, since it has been called once") + _ = GetHTTPClient(false) + if secureHTTPClient == nil { + t.Error("secureHTTPClient shouldn't have been nil, since it has been called once") } - if insecureHttpClient != nil { - t.Error("insecureHttpClient should've been nil since it hasn't been called a single time yet") + if insecureHTTPClient != nil { + t.Error("insecureHTTPClient should've been nil since it hasn't been called a single time yet") } - _ = GetHttpClient(true) - if secureHttpClient == nil { - t.Error("secureHttpClient shouldn't have been nil, since it has been called once") + _ = GetHTTPClient(true) + if secureHTTPClient == nil { + t.Error("secureHTTPClient shouldn't have been nil, since it has been called once") } - if insecureHttpClient == nil { - t.Error("insecureHttpClient shouldn't have been nil, since it has been called once") + if insecureHTTPClient == nil { + t.Error("insecureHTTPClient shouldn't have been nil, since it has been called once") } } diff --git a/config/config_test.go b/config/config_test.go index 54c2fa89..6262efef 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -50,10 +50,10 @@ services: if len(config.Services) != 2 { t.Error("Should have returned two services") } - if config.Services[0].Url != "https://twinnation.org/actuator/health" { + if config.Services[0].URL != "https://twinnation.org/actuator/health" { t.Errorf("URL should have been %s", "https://twinnation.org/actuator/health") } - if config.Services[1].Url != "https://api.github.com/healthz" { + if config.Services[1].URL != "https://api.github.com/healthz" { t.Errorf("URL should have been %s", "https://api.github.com/healthz") } if config.Services[0].Method != "GET" { @@ -93,7 +93,7 @@ services: if config.Metrics { t.Error("Metrics should've been false by default") } - if config.Services[0].Url != "https://twinnation.org/actuator/health" { + if config.Services[0].URL != "https://twinnation.org/actuator/health" { t.Errorf("URL should have been %s", "https://twinnation.org/actuator/health") } if config.Services[0].Interval != 60*time.Second { @@ -119,7 +119,7 @@ services: if !config.Metrics { t.Error("Metrics should have been true") } - if config.Services[0].Url != "https://twinnation.org/actuator/health" { + if config.Services[0].URL != "https://twinnation.org/actuator/health" { t.Errorf("URL should have been %s", "https://twinnation.org/actuator/health") } if config.Services[0].Interval != 60*time.Second { @@ -179,8 +179,8 @@ services: if config.Alerting.Slack == nil || !config.Alerting.Slack.IsValid() { t.Fatal("Slack alerting config should've been valid") } - if config.Alerting.Slack.WebhookUrl != "http://example.com" { - t.Errorf("Slack webhook should've been %s, but was %s", "http://example.com", config.Alerting.Slack.WebhookUrl) + if config.Alerting.Slack.WebhookURL != "http://example.com" { + t.Errorf("Slack webhook should've been %s, but was %s", "http://example.com", config.Alerting.Slack.WebhookURL) } if config.Alerting.PagerDuty == nil || !config.Alerting.PagerDuty.IsValid() { t.Fatal("PagerDuty alerting config should've been valid") @@ -191,7 +191,7 @@ services: if len(config.Services) != 1 { t.Error("There should've been 1 service") } - if config.Services[0].Url != "https://twinnation.org/actuator/health" { + if config.Services[0].URL != "https://twinnation.org/actuator/health" { t.Errorf("URL should have been %s", "https://twinnation.org/actuator/health") } if config.Services[0].Interval != 60*time.Second { diff --git a/core/condition.go b/core/condition.go index 27e11caf..a225372a 100644 --- a/core/condition.go +++ b/core/condition.go @@ -127,9 +127,9 @@ func sanitizeAndResolve(list []string, result *Result) []string { element = strings.TrimSpace(element) switch strings.ToUpper(element) { case StatusPlaceholder: - element = strconv.Itoa(result.HttpStatus) + element = strconv.Itoa(result.HTTPStatus) case IPPlaceHolder: - element = result.Ip + element = result.IP case ResponseTimePlaceHolder: element = strconv.Itoa(int(result.Duration.Milliseconds())) case BodyPlaceHolder: diff --git a/core/condition_test.go b/core/condition_test.go index 2a6ea8b9..45be961a 100644 --- a/core/condition_test.go +++ b/core/condition_test.go @@ -5,9 +5,9 @@ import ( "time" ) -func TestCondition_evaluateWithIp(t *testing.T) { +func TestCondition_evaluateWithIP(t *testing.T) { condition := Condition("[IP] == 127.0.0.1") - result := &Result{Ip: "127.0.0.1"} + result := &Result{IP: "127.0.0.1"} condition.evaluate(result) if !result.ConditionResults[0].Success { t.Errorf("Condition '%s' should have been a success", condition) @@ -16,7 +16,7 @@ func TestCondition_evaluateWithIp(t *testing.T) { func TestCondition_evaluateWithStatus(t *testing.T) { condition := Condition("[STATUS] == 201") - result := &Result{HttpStatus: 201} + result := &Result{HTTPStatus: 201} condition.evaluate(result) if !result.ConditionResults[0].Success { t.Errorf("Condition '%s' should have been a success", condition) @@ -25,7 +25,7 @@ func TestCondition_evaluateWithStatus(t *testing.T) { func TestCondition_evaluateWithStatusFailure(t *testing.T) { condition := Condition("[STATUS] == 200") - result := &Result{HttpStatus: 500} + result := &Result{HTTPStatus: 500} condition.evaluate(result) if result.ConditionResults[0].Success { t.Errorf("Condition '%s' should have been a failure", condition) @@ -34,7 +34,7 @@ func TestCondition_evaluateWithStatusFailure(t *testing.T) { func TestCondition_evaluateWithStatusUsingLessThan(t *testing.T) { condition := Condition("[STATUS] < 300") - result := &Result{HttpStatus: 201} + result := &Result{HTTPStatus: 201} condition.evaluate(result) if !result.ConditionResults[0].Success { t.Errorf("Condition '%s' should have been a success", condition) @@ -43,7 +43,7 @@ func TestCondition_evaluateWithStatusUsingLessThan(t *testing.T) { func TestCondition_evaluateWithStatusFailureUsingLessThan(t *testing.T) { condition := Condition("[STATUS] < 300") - result := &Result{HttpStatus: 404} + result := &Result{HTTPStatus: 404} condition.evaluate(result) if result.ConditionResults[0].Success { t.Errorf("Condition '%s' should have been a failure", condition) @@ -95,7 +95,7 @@ func TestCondition_evaluateWithBody(t *testing.T) { } } -func TestCondition_evaluateWithBodyJsonPath(t *testing.T) { +func TestCondition_evaluateWithBodyJSONPath(t *testing.T) { condition := Condition("[BODY].status == UP") result := &Result{Body: []byte("{\"status\":\"UP\"}")} condition.evaluate(result) @@ -104,7 +104,7 @@ func TestCondition_evaluateWithBodyJsonPath(t *testing.T) { } } -func TestCondition_evaluateWithBodyJsonPathComplex(t *testing.T) { +func TestCondition_evaluateWithBodyJSONPathComplex(t *testing.T) { condition := Condition("[BODY].data.name == john") result := &Result{Body: []byte("{\"data\": {\"id\": 1, \"name\": \"john\"}}")} condition.evaluate(result) @@ -113,7 +113,7 @@ func TestCondition_evaluateWithBodyJsonPathComplex(t *testing.T) { } } -func TestCondition_evaluateWithInvalidBodyJsonPathComplex(t *testing.T) { +func TestCondition_evaluateWithInvalidBodyJSONPathComplex(t *testing.T) { expectedResolvedCondition := "[BODY].data.name (INVALID) == john" condition := Condition("[BODY].data.name == john") result := &Result{Body: []byte("{\"data\": {\"id\": 1}}")} @@ -126,7 +126,7 @@ func TestCondition_evaluateWithInvalidBodyJsonPathComplex(t *testing.T) { } } -func TestCondition_evaluateWithBodyJsonPathDoublePlaceholders(t *testing.T) { +func TestCondition_evaluateWithBodyJSONPathDoublePlaceholders(t *testing.T) { condition := Condition("[BODY].user.firstName != [BODY].user.lastName") result := &Result{Body: []byte("{\"user\": {\"firstName\": \"john\", \"lastName\": \"doe\"}}")} condition.evaluate(result) @@ -135,7 +135,7 @@ func TestCondition_evaluateWithBodyJsonPathDoublePlaceholders(t *testing.T) { } } -func TestCondition_evaluateWithBodyJsonPathDoublePlaceholdersFailure(t *testing.T) { +func TestCondition_evaluateWithBodyJSONPathDoublePlaceholdersFailure(t *testing.T) { condition := Condition("[BODY].user.firstName == [BODY].user.lastName") result := &Result{Body: []byte("{\"user\": {\"firstName\": \"john\", \"lastName\": \"doe\"}}")} condition.evaluate(result) @@ -144,7 +144,7 @@ func TestCondition_evaluateWithBodyJsonPathDoublePlaceholdersFailure(t *testing. } } -func TestCondition_evaluateWithBodyJsonPathLongInt(t *testing.T) { +func TestCondition_evaluateWithBodyJSONPathLongInt(t *testing.T) { condition := Condition("[BODY].data.id == 1") result := &Result{Body: []byte("{\"data\": {\"id\": 1}}")} condition.evaluate(result) @@ -153,7 +153,7 @@ func TestCondition_evaluateWithBodyJsonPathLongInt(t *testing.T) { } } -func TestCondition_evaluateWithBodyJsonPathComplexInt(t *testing.T) { +func TestCondition_evaluateWithBodyJSONPathComplexInt(t *testing.T) { condition := Condition("[BODY].data[1].id == 2") result := &Result{Body: []byte("{\"data\": [{\"id\": 1}, {\"id\": 2}, {\"id\": 3}]}")} condition.evaluate(result) @@ -162,7 +162,7 @@ func TestCondition_evaluateWithBodyJsonPathComplexInt(t *testing.T) { } } -func TestCondition_evaluateWithBodyJsonPathComplexIntUsingGreaterThan(t *testing.T) { +func TestCondition_evaluateWithBodyJSONPathComplexIntUsingGreaterThan(t *testing.T) { condition := Condition("[BODY].data.id > 0") result := &Result{Body: []byte("{\"data\": {\"id\": 1}}")} condition.evaluate(result) @@ -171,7 +171,7 @@ func TestCondition_evaluateWithBodyJsonPathComplexIntUsingGreaterThan(t *testing } } -func TestCondition_evaluateWithBodyJsonPathComplexIntFailureUsingGreaterThan(t *testing.T) { +func TestCondition_evaluateWithBodyJSONPathComplexIntFailureUsingGreaterThan(t *testing.T) { condition := Condition("[BODY].data.id > 5") result := &Result{Body: []byte("{\"data\": {\"id\": 1}}")} condition.evaluate(result) @@ -180,7 +180,7 @@ func TestCondition_evaluateWithBodyJsonPathComplexIntFailureUsingGreaterThan(t * } } -func TestCondition_evaluateWithBodyJsonPathComplexIntUsingLessThan(t *testing.T) { +func TestCondition_evaluateWithBodyJSONPathComplexIntUsingLessThan(t *testing.T) { condition := Condition("[BODY].data.id < 5") result := &Result{Body: []byte("{\"data\": {\"id\": 2}}")} condition.evaluate(result) @@ -189,7 +189,7 @@ func TestCondition_evaluateWithBodyJsonPathComplexIntUsingLessThan(t *testing.T) } } -func TestCondition_evaluateWithBodyJsonPathComplexIntFailureUsingLessThan(t *testing.T) { +func TestCondition_evaluateWithBodyJSONPathComplexIntFailureUsingLessThan(t *testing.T) { condition := Condition("[BODY].data.id < 5") result := &Result{Body: []byte("{\"data\": {\"id\": 10}}")} condition.evaluate(result) @@ -245,7 +245,7 @@ func TestCondition_evaluateWithBodyPatternFailure(t *testing.T) { func TestCondition_evaluateWithIPPattern(t *testing.T) { condition := Condition("[IP] == pat(10.*)") - result := &Result{Ip: "10.0.0.0"} + result := &Result{IP: "10.0.0.0"} condition.evaluate(result) if !result.ConditionResults[0].Success { t.Errorf("Condition '%s' should have been a success", condition) @@ -254,7 +254,7 @@ func TestCondition_evaluateWithIPPattern(t *testing.T) { func TestCondition_evaluateWithIPPatternFailure(t *testing.T) { condition := Condition("[IP] == pat(10.*)") - result := &Result{Ip: "255.255.255.255"} + result := &Result{IP: "255.255.255.255"} condition.evaluate(result) if result.ConditionResults[0].Success { t.Errorf("Condition '%s' should have been a failure", condition) @@ -263,7 +263,7 @@ func TestCondition_evaluateWithIPPatternFailure(t *testing.T) { func TestCondition_evaluateWithStatusPattern(t *testing.T) { condition := Condition("[STATUS] == pat(4*)") - result := &Result{HttpStatus: 404} + result := &Result{HTTPStatus: 404} condition.evaluate(result) if !result.ConditionResults[0].Success { t.Errorf("Condition '%s' should have been a success", condition) @@ -272,7 +272,7 @@ func TestCondition_evaluateWithStatusPattern(t *testing.T) { func TestCondition_evaluateWithStatusPatternFailure(t *testing.T) { condition := Condition("[STATUS] != pat(4*)") - result := &Result{HttpStatus: 404} + result := &Result{HTTPStatus: 404} condition.evaluate(result) if result.ConditionResults[0].Success { t.Errorf("Condition '%s' should have been a failure", condition) diff --git a/core/service.go b/core/service.go index 91af94cb..d6a7997e 100644 --- a/core/service.go +++ b/core/service.go @@ -17,8 +17,8 @@ var ( // ErrServiceWithNoCondition is the error with which gatus will panic if a service is configured with no conditions ErrServiceWithNoCondition = errors.New("you must specify at least one condition per service") - // ErrServiceWithNoUrl is the error with which gatus will panic if a service is configured with no url - ErrServiceWithNoUrl = errors.New("you must specify an url for each service") + // ErrServiceWithNoURL is the error with which gatus will panic if a service is configured with no url + ErrServiceWithNoURL = errors.New("you must specify an url for each service") // ErrServiceWithNoName is the error with which gatus will panic if a service is configured with no name ErrServiceWithNoName = errors.New("you must specify a name for each service") @@ -30,7 +30,7 @@ type Service struct { Name string `yaml:"name"` // URL to send the request to - Url string `yaml:"url"` + URL string `yaml:"url"` // Method of the request made to the url of the service Method string `yaml:"method,omitempty"` @@ -86,15 +86,15 @@ func (service *Service) ValidateAndSetDefaults() { if len(service.Name) == 0 { panic(ErrServiceWithNoName) } - if len(service.Url) == 0 { - panic(ErrServiceWithNoUrl) + if len(service.URL) == 0 { + panic(ErrServiceWithNoURL) } if len(service.Conditions) == 0 { panic(ErrServiceWithNoCondition) } // Make sure that the request can be created - _, err := http.NewRequest(service.Method, service.Url, bytes.NewBuffer([]byte(service.Body))) + _, err := http.NewRequest(service.Method, service.URL, bytes.NewBuffer([]byte(service.Body))) if err != nil { panic(err) } @@ -103,7 +103,7 @@ func (service *Service) ValidateAndSetDefaults() { // EvaluateHealth sends a request to the service's URL and evaluates the conditions of the service. func (service *Service) EvaluateHealth() *Result { result := &Result{Success: true, Errors: []string{}} - service.getIp(result) + service.getIP(result) if len(result.Errors) == 0 { service.call(result) } else { @@ -134,8 +134,8 @@ func (service *Service) GetAlertsTriggered() []Alert { return alerts } -func (service *Service) getIp(result *Result) { - urlObject, err := url.Parse(service.Url) +func (service *Service) getIP(result *Result) { + urlObject, err := url.Parse(service.URL) if err != nil { result.Errors = append(result.Errors, err.Error()) return @@ -146,29 +146,29 @@ func (service *Service) getIp(result *Result) { result.Errors = append(result.Errors, err.Error()) return } - result.Ip = ips[0].String() + result.IP = ips[0].String() } func (service *Service) call(result *Result) { - isServiceTcp := strings.HasPrefix(service.Url, "tcp://") + isServiceTCP := strings.HasPrefix(service.URL, "tcp://") var request *http.Request var response *http.Response var err error - if !isServiceTcp { + if !isServiceTCP { request = service.buildRequest() } startTime := time.Now() - if isServiceTcp { - result.Connected = client.CanCreateConnectionToTcpService(strings.TrimPrefix(service.Url, "tcp://")) + if isServiceTCP { + result.Connected = client.CanCreateConnectionToTCPService(strings.TrimPrefix(service.URL, "tcp://")) result.Duration = time.Since(startTime) } else { - response, err = client.GetHttpClient(service.Insecure).Do(request) + response, err = client.GetHTTPClient(service.Insecure).Do(request) result.Duration = time.Since(startTime) if err != nil { result.Errors = append(result.Errors, err.Error()) return } - result.HttpStatus = response.StatusCode + result.HTTPStatus = response.StatusCode result.Connected = response.StatusCode > 0 result.Body, err = ioutil.ReadAll(response.Body) if err != nil { @@ -188,7 +188,7 @@ func (service *Service) buildRequest() *http.Request { } else { bodyBuffer = bytes.NewBuffer([]byte(service.Body)) } - request, _ := http.NewRequest(service.Method, service.Url, bodyBuffer) + request, _ := http.NewRequest(service.Method, service.URL, bodyBuffer) for k, v := range service.Headers { request.Header.Set(k, v) } diff --git a/core/service_test.go b/core/service_test.go index 25a9b9f5..99460661 100644 --- a/core/service_test.go +++ b/core/service_test.go @@ -9,7 +9,7 @@ func TestService_ValidateAndSetDefaults(t *testing.T) { condition := Condition("[STATUS] == 200") service := Service{ Name: "TwiNNatioN", - Url: "https://twinnation.org/health", + URL: "https://twinnation.org/health", Conditions: []*Condition{&condition}, Alerts: []*Alert{{Type: PagerDutyAlert}}, } @@ -42,7 +42,7 @@ func TestService_ValidateAndSetDefaultsWithNoName(t *testing.T) { condition := Condition("[STATUS] == 200") service := &Service{ Name: "", - Url: "http://example.com", + URL: "http://example.com", Conditions: []*Condition{&condition}, } service.ValidateAndSetDefaults() @@ -54,7 +54,7 @@ func TestService_ValidateAndSetDefaultsWithNoUrl(t *testing.T) { condition := Condition("[STATUS] == 200") service := &Service{ Name: "example", - Url: "", + URL: "", Conditions: []*Condition{&condition}, } service.ValidateAndSetDefaults() @@ -65,7 +65,7 @@ func TestService_ValidateAndSetDefaultsWithNoConditions(t *testing.T) { defer func() { recover() }() service := &Service{ Name: "example", - Url: "http://example.com", + URL: "http://example.com", Conditions: nil, } service.ValidateAndSetDefaults() @@ -76,7 +76,7 @@ func TestService_GetAlertsTriggered(t *testing.T) { condition := Condition("[STATUS] == 200") service := Service{ Name: "TwiNNatioN", - Url: "https://twinnation.org/health", + URL: "https://twinnation.org/health", Conditions: []*Condition{&condition}, Alerts: []*Alert{{Type: PagerDutyAlert, Enabled: true}}, } @@ -100,7 +100,7 @@ func TestIntegrationEvaluateHealth(t *testing.T) { condition := Condition("[STATUS] == 200") service := Service{ Name: "TwiNNatioN", - Url: "https://twinnation.org/health", + URL: "https://twinnation.org/health", Conditions: []*Condition{&condition}, } result := service.EvaluateHealth() @@ -119,7 +119,7 @@ func TestIntegrationEvaluateHealthWithFailure(t *testing.T) { condition := Condition("[STATUS] == 500") service := Service{ Name: "TwiNNatioN", - Url: "https://twinnation.org/health", + URL: "https://twinnation.org/health", Conditions: []*Condition{&condition}, } result := service.EvaluateHealth() diff --git a/core/types.go b/core/types.go index 86874e8c..f17dbf3e 100644 --- a/core/types.go +++ b/core/types.go @@ -16,17 +16,17 @@ type HealthStatus struct { // Result of the evaluation of a Service type Result struct { - // HttpStatus is the HTTP response status code - HttpStatus int `json:"status"` + // HTTPStatus is the HTTP response status code + HTTPStatus int `json:"status"` // Body is the response body Body []byte `json:"-"` - // Hostname extracted from the Service Url + // Hostname extracted from the Service URL Hostname string `json:"hostname"` - // Ip resolved from the Service Url - Ip string `json:"-"` + // IP resolved from the Service URL + IP string `json:"-"` // Connected whether a connection to the host was established successfully Connected bool `json:"-"` diff --git a/go.mod b/go.mod index 6dc538a7..3e63c5ef 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,8 @@ go 1.15 require ( github.com/prometheus/client_golang v1.7.1 github.com/prometheus/common v0.13.0 // indirect - golang.org/x/sys v0.0.0-20200916084744-dbad9cb7cb7a // indirect + golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/protobuf v1.25.0 // indirect gopkg.in/yaml.v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 497328d7..b3ae1922 100644 --- a/go.sum +++ b/go.sum @@ -284,6 +284,7 @@ golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= @@ -331,8 +332,8 @@ golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200916084744-dbad9cb7cb7a h1:chkwkn8HYWVtTE5DCQNKYlkyptadXYY0+PuyaVdyMo4= -golang.org/x/sys v0.0.0-20200916084744-dbad9cb7cb7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -349,11 +350,14 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200103221440-774c71fcf114 h1:DnSr2mCsxyCE6ZgIkmcWUQY2R5cH/6wL7eIxEmQOMSE= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= diff --git a/gzip.go b/gzip.go index b2768c43..891b8d42 100644 --- a/gzip.go +++ b/gzip.go @@ -29,6 +29,8 @@ func (w *gzipResponseWriter) Write(b []byte) (int, error) { return w.Writer.Write(b) } +// GzipHandler compresses the response of a given handler if the request's headers specify that the client +// supports gzip encoding func GzipHandler(next http.Handler) http.Handler { return http.HandlerFunc(func(writer http.ResponseWriter, r *http.Request) { // If the request doesn't specify that it supports gzip, then don't compress it diff --git a/main.go b/main.go index 86c6d726..b4febe04 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ import ( "time" ) -const CacheTTL = 10 * time.Second +const cacheTTL = 10 * time.Second var ( cachedServiceResults []byte @@ -54,10 +54,10 @@ func loadConfiguration() *config.Config { } func serviceResultsHandler(writer http.ResponseWriter, r *http.Request) { - if isExpired := cachedServiceResultsTimestamp.IsZero() || time.Now().Sub(cachedServiceResultsTimestamp) > CacheTTL; isExpired { + if isExpired := cachedServiceResultsTimestamp.IsZero() || time.Now().Sub(cachedServiceResultsTimestamp) > cacheTTL; isExpired { buffer := &bytes.Buffer{} gzipWriter := gzip.NewWriter(buffer) - data, err := watchdog.GetJsonEncodedServiceResults() + data, err := watchdog.GetJSONEncodedServiceResults() if err != nil { log.Printf("[main][serviceResultsHandler] Unable to marshal object to JSON: %s", err.Error()) writer.WriteHeader(http.StatusInternalServerError) diff --git a/metric/metric.go b/metric/metric.go index db1e90bf..e8408a0e 100644 --- a/metric/metric.go +++ b/metric/metric.go @@ -20,16 +20,16 @@ var ( func PublishMetricsForService(service *core.Service, result *core.Result) { if config.Get().Metrics { rwLock.Lock() - gauge, exists := gauges[fmt.Sprintf("%s_%s", service.Name, service.Url)] + gauge, exists := gauges[fmt.Sprintf("%s_%s", service.Name, service.URL)] if !exists { gauge = promauto.NewGaugeVec(prometheus.GaugeOpts{ Subsystem: "gatus", Name: "tasks", - ConstLabels: prometheus.Labels{"service": service.Name, "url": service.Url}, + ConstLabels: prometheus.Labels{"service": service.Name, "url": service.URL}, }, []string{"status", "success"}) - gauges[fmt.Sprintf("%s_%s", service.Name, service.Url)] = gauge + gauges[fmt.Sprintf("%s_%s", service.Name, service.URL)] = gauge } rwLock.Unlock() - gauge.WithLabelValues(strconv.Itoa(result.HttpStatus), strconv.FormatBool(result.Success)).Inc() + gauge.WithLabelValues(strconv.Itoa(result.HTTPStatus), strconv.FormatBool(result.Success)).Inc() } } diff --git a/vendor/golang.org/x/sys/unix/fcntl_darwin.go b/vendor/golang.org/x/sys/unix/fcntl_darwin.go index 5868a4a4..a9911c7c 100644 --- a/vendor/golang.org/x/sys/unix/fcntl_darwin.go +++ b/vendor/golang.org/x/sys/unix/fcntl_darwin.go @@ -16,3 +16,9 @@ func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error { _, err := fcntl(int(fd), cmd, int(uintptr(unsafe.Pointer(lk)))) return err } + +// FcntlFstore performs a fcntl syscall for the F_PREALLOCATE command. +func FcntlFstore(fd uintptr, cmd int, fstore *Fstore_t) error { + _, err := fcntl(int(fd), cmd, int(uintptr(unsafe.Pointer(fstore)))) + return err +} diff --git a/vendor/golang.org/x/sys/unix/gccgo.go b/vendor/golang.org/x/sys/unix/gccgo.go index cd6f5a61..86032c11 100644 --- a/vendor/golang.org/x/sys/unix/gccgo.go +++ b/vendor/golang.org/x/sys/unix/gccgo.go @@ -12,10 +12,8 @@ import "syscall" // We can't use the gc-syntax .s files for gccgo. On the plus side // much of the functionality can be written directly in Go. -//extern gccgoRealSyscallNoError func realSyscallNoError(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r uintptr) -//extern gccgoRealSyscall func realSyscall(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r, errno uintptr) func SyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr) { diff --git a/vendor/golang.org/x/sys/unix/gccgo_c.c b/vendor/golang.org/x/sys/unix/gccgo_c.c index c44730c5..2cb1fefa 100644 --- a/vendor/golang.org/x/sys/unix/gccgo_c.c +++ b/vendor/golang.org/x/sys/unix/gccgo_c.c @@ -21,6 +21,9 @@ struct ret { uintptr_t err; }; +struct ret gccgoRealSyscall(uintptr_t trap, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7, uintptr_t a8, uintptr_t a9) + __asm__(GOSYM_PREFIX GOPKGPATH ".realSyscall"); + struct ret gccgoRealSyscall(uintptr_t trap, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7, uintptr_t a8, uintptr_t a9) { @@ -32,6 +35,9 @@ gccgoRealSyscall(uintptr_t trap, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintp return r; } +uintptr_t gccgoRealSyscallNoError(uintptr_t trap, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7, uintptr_t a8, uintptr_t a9) + __asm__(GOSYM_PREFIX GOPKGPATH ".realSyscallNoError"); + uintptr_t gccgoRealSyscallNoError(uintptr_t trap, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7, uintptr_t a8, uintptr_t a9) { diff --git a/vendor/golang.org/x/sys/unix/mkerrors.sh b/vendor/golang.org/x/sys/unix/mkerrors.sh index cab45604..1bef7148 100644 --- a/vendor/golang.org/x/sys/unix/mkerrors.sh +++ b/vendor/golang.org/x/sys/unix/mkerrors.sh @@ -58,6 +58,7 @@ includes_Darwin=' #define _DARWIN_USE_64_BIT_INODE #include #include +#include #include #include #include @@ -516,6 +517,7 @@ ccflags="$@" $2 ~ /^CP_/ || $2 ~ /^CPUSTATES$/ || $2 ~ /^ALG_/ || + $2 ~ /^FI(CLONE|DEDUPERANGE)/ || $2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE)/ || $2 ~ /^FS_IOC_.*(ENCRYPTION|VERITY|[GS]ETFLAGS)/ || $2 ~ /^FS_VERITY_/ || diff --git a/vendor/golang.org/x/sys/unix/sockcmsg_unix_other.go b/vendor/golang.org/x/sys/unix/sockcmsg_unix_other.go index 7d08dae5..57a0021d 100644 --- a/vendor/golang.org/x/sys/unix/sockcmsg_unix_other.go +++ b/vendor/golang.org/x/sys/unix/sockcmsg_unix_other.go @@ -20,7 +20,7 @@ func cmsgAlignOf(salen int) int { case "aix": // There is no alignment on AIX. salign = 1 - case "darwin", "illumos", "solaris": + case "darwin", "ios", "illumos", "solaris": // NOTE: It seems like 64-bit Darwin, Illumos and Solaris // kernels still require 32-bit aligned access to network // subsystem. @@ -32,6 +32,10 @@ func cmsgAlignOf(salen int) int { if runtime.GOARCH == "arm" { salign = 8 } + // NetBSD aarch64 requires 128-bit alignment. + if runtime.GOOS == "netbsd" && runtime.GOARCH == "arm64" { + salign = 16 + } } return (salen + salign - 1) & ^(salign - 1) diff --git a/vendor/golang.org/x/sys/unix/syscall_bsd.go b/vendor/golang.org/x/sys/unix/syscall_bsd.go index 60bbe10a..123536a0 100644 --- a/vendor/golang.org/x/sys/unix/syscall_bsd.go +++ b/vendor/golang.org/x/sys/unix/syscall_bsd.go @@ -18,6 +18,21 @@ import ( "unsafe" ) +const ImplementsGetwd = true + +func Getwd() (string, error) { + var buf [PathMax]byte + _, err := Getcwd(buf[0:]) + if err != nil { + return "", err + } + n := clen(buf[:]) + if n < 1 { + return "", EINVAL + } + return string(buf[:n]), nil +} + /* * Wrapped */ @@ -272,7 +287,7 @@ func Accept(fd int) (nfd int, sa Sockaddr, err error) { if err != nil { return } - if runtime.GOOS == "darwin" && len == 0 { + if (runtime.GOOS == "darwin" || runtime.GOOS == "ios") && len == 0 { // Accepted socket has no address. // This is likely due to a bug in xnu kernels, // where instead of ECONNABORTED error socket diff --git a/vendor/golang.org/x/sys/unix/syscall_darwin.go b/vendor/golang.org/x/sys/unix/syscall_darwin.go index eddcf3a9..21b8092c 100644 --- a/vendor/golang.org/x/sys/unix/syscall_darwin.go +++ b/vendor/golang.org/x/sys/unix/syscall_darwin.go @@ -13,29 +13,10 @@ package unix import ( - "errors" "syscall" "unsafe" ) -const ImplementsGetwd = true - -func Getwd() (string, error) { - buf := make([]byte, 2048) - attrs, err := getAttrList(".", attrList{CommonAttr: attrCmnFullpath}, buf, 0) - if err == nil && len(attrs) == 1 && len(attrs[0]) >= 2 { - wd := string(attrs[0]) - // Sanity check that it's an absolute path and ends - // in a null byte, which we then strip. - if wd[0] == '/' && wd[len(wd)-1] == 0 { - return wd[:len(wd)-1], nil - } - } - // If pkg/os/getwd.go gets ENOTSUP, it will fall back to the - // slow algorithm. - return "", ENOTSUP -} - // SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets. type SockaddrDatalink struct { Len uint8 @@ -97,11 +78,6 @@ func direntNamlen(buf []byte) (uint64, bool) { func PtraceAttach(pid int) (err error) { return ptrace(PT_ATTACH, pid, 0, 0) } func PtraceDetach(pid int) (err error) { return ptrace(PT_DETACH, pid, 0, 0) } -const ( - attrBitMapCount = 5 - attrCmnFullpath = 0x08000000 -) - type attrList struct { bitmapCount uint16 _ uint16 @@ -112,54 +88,6 @@ type attrList struct { Forkattr uint32 } -func getAttrList(path string, attrList attrList, attrBuf []byte, options uint) (attrs [][]byte, err error) { - if len(attrBuf) < 4 { - return nil, errors.New("attrBuf too small") - } - attrList.bitmapCount = attrBitMapCount - - var _p0 *byte - _p0, err = BytePtrFromString(path) - if err != nil { - return nil, err - } - - if err := getattrlist(_p0, unsafe.Pointer(&attrList), unsafe.Pointer(&attrBuf[0]), uintptr(len(attrBuf)), int(options)); err != nil { - return nil, err - } - size := *(*uint32)(unsafe.Pointer(&attrBuf[0])) - - // dat is the section of attrBuf that contains valid data, - // without the 4 byte length header. All attribute offsets - // are relative to dat. - dat := attrBuf - if int(size) < len(attrBuf) { - dat = dat[:size] - } - dat = dat[4:] // remove length prefix - - for i := uint32(0); int(i) < len(dat); { - header := dat[i:] - if len(header) < 8 { - return attrs, errors.New("truncated attribute header") - } - datOff := *(*int32)(unsafe.Pointer(&header[0])) - attrLen := *(*uint32)(unsafe.Pointer(&header[4])) - if datOff < 0 || uint32(datOff)+attrLen > uint32(len(dat)) { - return attrs, errors.New("truncated results; attrBuf too small") - } - end := uint32(datOff) + attrLen - attrs = append(attrs, dat[datOff:end]) - i = end - if r := i % 4; r != 0 { - i += (4 - r) - } - } - return -} - -//sys getattrlist(path *byte, list unsafe.Pointer, buf unsafe.Pointer, size uintptr, options int) (err error) - //sysnb pipe() (r int, w int, err error) func Pipe(p []int) (err error) { @@ -419,6 +347,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e //sys Fpathconf(fd int, name int) (val int, err error) //sys Fsync(fd int) (err error) //sys Ftruncate(fd int, length int64) (err error) +//sys Getcwd(buf []byte) (n int, err error) //sys Getdtablesize() (size int) //sysnb Getegid() (egid int) //sysnb Geteuid() (uid int) diff --git a/vendor/golang.org/x/sys/unix/syscall_dragonfly.go b/vendor/golang.org/x/sys/unix/syscall_dragonfly.go index 8a195ae5..bed7dcfe 100644 --- a/vendor/golang.org/x/sys/unix/syscall_dragonfly.go +++ b/vendor/golang.org/x/sys/unix/syscall_dragonfly.go @@ -129,23 +129,8 @@ func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) { return } -const ImplementsGetwd = true - //sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD -func Getwd() (string, error) { - var buf [PathMax]byte - _, err := Getcwd(buf[0:]) - if err != nil { - return "", err - } - n := clen(buf[:]) - if n < 1 { - return "", EINVAL - } - return string(buf[:n]), nil -} - func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { var _p0 unsafe.Pointer var bufsize uintptr diff --git a/vendor/golang.org/x/sys/unix/syscall_freebsd.go b/vendor/golang.org/x/sys/unix/syscall_freebsd.go index 6932e7c2..f6db02af 100644 --- a/vendor/golang.org/x/sys/unix/syscall_freebsd.go +++ b/vendor/golang.org/x/sys/unix/syscall_freebsd.go @@ -140,23 +140,8 @@ func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) { return } -const ImplementsGetwd = true - //sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD -func Getwd() (string, error) { - var buf [PathMax]byte - _, err := Getcwd(buf[0:]) - if err != nil { - return "", err - } - n := clen(buf[:]) - if n < 1 { - return "", EINVAL - } - return string(buf[:n]), nil -} - func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { var ( _p0 unsafe.Pointer diff --git a/vendor/golang.org/x/sys/unix/syscall_illumos.go b/vendor/golang.org/x/sys/unix/syscall_illumos.go index 16e40091..bbc4f3ea 100644 --- a/vendor/golang.org/x/sys/unix/syscall_illumos.go +++ b/vendor/golang.org/x/sys/unix/syscall_illumos.go @@ -56,7 +56,7 @@ func Pwritev(fd int, iovs [][]byte, off int64) (n int, err error) { return n, err } -//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) +//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) = libsocket.accept4 func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error) { var rsa RawSockaddrAny diff --git a/vendor/golang.org/x/sys/unix/syscall_linux.go b/vendor/golang.org/x/sys/unix/syscall_linux.go index ec7e4c4d..94dafa4e 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux.go @@ -112,6 +112,31 @@ func IoctlGetRTCWkAlrm(fd int) (*RTCWkAlrm, error) { return &value, err } +// IoctlFileClone performs an FICLONERANGE ioctl operation to clone the range of +// data conveyed in value to the file associated with the file descriptor +// destFd. See the ioctl_ficlonerange(2) man page for details. +func IoctlFileCloneRange(destFd int, value *FileCloneRange) error { + err := ioctl(destFd, FICLONERANGE, uintptr(unsafe.Pointer(value))) + runtime.KeepAlive(value) + return err +} + +// IoctlFileClone performs an FICLONE ioctl operation to clone the entire file +// associated with the file description srcFd to the file associated with the +// file descriptor destFd. See the ioctl_ficlone(2) man page for details. +func IoctlFileClone(destFd, srcFd int) error { + return ioctl(destFd, FICLONE, uintptr(srcFd)) +} + +// IoctlFileClone performs an FIDEDUPERANGE ioctl operation to share the range of +// data conveyed in value with the file associated with the file descriptor +// destFd. See the ioctl_fideduperange(2) man page for details. +func IoctlFileDedupeRange(destFd int, value *FileDedupeRange) error { + err := ioctl(destFd, FIDEDUPERANGE, uintptr(unsafe.Pointer(value))) + runtime.KeepAlive(value) + return err +} + //sys Linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error) func Link(oldpath string, newpath string) (err error) { diff --git a/vendor/golang.org/x/sys/unix/syscall_netbsd.go b/vendor/golang.org/x/sys/unix/syscall_netbsd.go index 45b50a61..dbd5e03b 100644 --- a/vendor/golang.org/x/sys/unix/syscall_netbsd.go +++ b/vendor/golang.org/x/sys/unix/syscall_netbsd.go @@ -141,23 +141,8 @@ func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { return } -const ImplementsGetwd = true - //sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD -func Getwd() (string, error) { - var buf [PathMax]byte - _, err := Getcwd(buf[0:]) - if err != nil { - return "", err - } - n := clen(buf[:]) - if n < 1 { - return "", EINVAL - } - return string(buf[:n]), nil -} - // TODO func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { return -1, ENOSYS diff --git a/vendor/golang.org/x/sys/unix/syscall_openbsd.go b/vendor/golang.org/x/sys/unix/syscall_openbsd.go index a266e92a..2c1f46ea 100644 --- a/vendor/golang.org/x/sys/unix/syscall_openbsd.go +++ b/vendor/golang.org/x/sys/unix/syscall_openbsd.go @@ -114,23 +114,8 @@ func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { return } -const ImplementsGetwd = true - //sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD -func Getwd() (string, error) { - var buf [PathMax]byte - _, err := Getcwd(buf[0:]) - if err != nil { - return "", err - } - n := clen(buf[:]) - if n < 1 { - return "", EINVAL - } - return string(buf[:n]), nil -} - func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { if raceenabled { raceReleaseMerge(unsafe.Pointer(&ioSync)) diff --git a/vendor/golang.org/x/sys/unix/zerrors_darwin_386.go b/vendor/golang.org/x/sys/unix/zerrors_darwin_386.go index 6217cdba..6f333594 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_darwin_386.go +++ b/vendor/golang.org/x/sys/unix/zerrors_darwin_386.go @@ -232,6 +232,8 @@ const ( CLOCK_THREAD_CPUTIME_ID = 0x10 CLOCK_UPTIME_RAW = 0x8 CLOCK_UPTIME_RAW_APPROX = 0x9 + CLONE_NOFOLLOW = 0x1 + CLONE_NOOWNERCOPY = 0x2 CR0 = 0x0 CR1 = 0x1000 CR2 = 0x2000 diff --git a/vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go b/vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go index e3ff2ee3..db767eb2 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go @@ -232,6 +232,8 @@ const ( CLOCK_THREAD_CPUTIME_ID = 0x10 CLOCK_UPTIME_RAW = 0x8 CLOCK_UPTIME_RAW_APPROX = 0x9 + CLONE_NOFOLLOW = 0x1 + CLONE_NOOWNERCOPY = 0x2 CR0 = 0x0 CR1 = 0x1000 CR2 = 0x2000 diff --git a/vendor/golang.org/x/sys/unix/zerrors_darwin_arm.go b/vendor/golang.org/x/sys/unix/zerrors_darwin_arm.go index 3e417571..ddc5d001 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_darwin_arm.go +++ b/vendor/golang.org/x/sys/unix/zerrors_darwin_arm.go @@ -232,6 +232,8 @@ const ( CLOCK_THREAD_CPUTIME_ID = 0x10 CLOCK_UPTIME_RAW = 0x8 CLOCK_UPTIME_RAW_APPROX = 0x9 + CLONE_NOFOLLOW = 0x1 + CLONE_NOOWNERCOPY = 0x2 CR0 = 0x0 CR1 = 0x1000 CR2 = 0x2000 diff --git a/vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go b/vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go index cbd8ed18..0614d26d 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go @@ -232,6 +232,8 @@ const ( CLOCK_THREAD_CPUTIME_ID = 0x10 CLOCK_UPTIME_RAW = 0x8 CLOCK_UPTIME_RAW_APPROX = 0x9 + CLONE_NOFOLLOW = 0x1 + CLONE_NOOWNERCOPY = 0x2 CR0 = 0x0 CR1 = 0x1000 CR2 = 0x2000 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux.go b/vendor/golang.org/x/sys/unix/zerrors_linux.go index 388050a0..79e032f4 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux.go @@ -686,6 +686,7 @@ const ( FD_CLOEXEC = 0x1 FD_SETSIZE = 0x400 FF0 = 0x0 + FIDEDUPERANGE = 0xc0189436 FSCRYPT_KEY_DESCRIPTOR_SIZE = 0x8 FSCRYPT_KEY_DESC_PREFIX = "fscrypt:" FSCRYPT_KEY_DESC_PREFIX_SIZE = 0x8 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_386.go b/vendor/golang.org/x/sys/unix/zerrors_linux_386.go index 11b25f68..dd282c08 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_386.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_386.go @@ -71,6 +71,8 @@ const ( EXTPROC = 0x10000 FF1 = 0x8000 FFDLY = 0x8000 + FICLONE = 0x40049409 + FICLONERANGE = 0x4020940d FLUSHO = 0x1000 FP_XSTATE_MAGIC2 = 0x46505845 FS_IOC_ENABLE_VERITY = 0x40806685 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go b/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go index f92cff6e..82fc93c7 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go @@ -71,6 +71,8 @@ const ( EXTPROC = 0x10000 FF1 = 0x8000 FFDLY = 0x8000 + FICLONE = 0x40049409 + FICLONERANGE = 0x4020940d FLUSHO = 0x1000 FP_XSTATE_MAGIC2 = 0x46505845 FS_IOC_ENABLE_VERITY = 0x40806685 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go b/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go index 12bcbf88..fe7094f2 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go @@ -71,6 +71,8 @@ const ( EXTPROC = 0x10000 FF1 = 0x8000 FFDLY = 0x8000 + FICLONE = 0x40049409 + FICLONERANGE = 0x4020940d FLUSHO = 0x1000 FS_IOC_ENABLE_VERITY = 0x40806685 FS_IOC_GETFLAGS = 0x80046601 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go b/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go index 84f71e99..3b6cc588 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go @@ -73,6 +73,8 @@ const ( EXTRA_MAGIC = 0x45585401 FF1 = 0x8000 FFDLY = 0x8000 + FICLONE = 0x40049409 + FICLONERANGE = 0x4020940d FLUSHO = 0x1000 FPSIMD_MAGIC = 0x46508001 FS_IOC_ENABLE_VERITY = 0x40806685 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go b/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go index eeadea94..ce3d9ae1 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go @@ -71,6 +71,8 @@ const ( EXTPROC = 0x10000 FF1 = 0x8000 FFDLY = 0x8000 + FICLONE = 0x80049409 + FICLONERANGE = 0x8020940d FLUSHO = 0x2000 FS_IOC_ENABLE_VERITY = 0x80806685 FS_IOC_GETFLAGS = 0x40046601 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go b/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go index 0be6c4cc..7a85215c 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go @@ -71,6 +71,8 @@ const ( EXTPROC = 0x10000 FF1 = 0x8000 FFDLY = 0x8000 + FICLONE = 0x80049409 + FICLONERANGE = 0x8020940d FLUSHO = 0x2000 FS_IOC_ENABLE_VERITY = 0x80806685 FS_IOC_GETFLAGS = 0x40086601 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go b/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go index 0880b745..07d4cc1b 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go @@ -71,6 +71,8 @@ const ( EXTPROC = 0x10000 FF1 = 0x8000 FFDLY = 0x8000 + FICLONE = 0x80049409 + FICLONERANGE = 0x8020940d FLUSHO = 0x2000 FS_IOC_ENABLE_VERITY = 0x80806685 FS_IOC_GETFLAGS = 0x40086601 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go b/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go index c8a66627..d4842ba1 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go @@ -71,6 +71,8 @@ const ( EXTPROC = 0x10000 FF1 = 0x8000 FFDLY = 0x8000 + FICLONE = 0x80049409 + FICLONERANGE = 0x8020940d FLUSHO = 0x2000 FS_IOC_ENABLE_VERITY = 0x80806685 FS_IOC_GETFLAGS = 0x40046601 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go b/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go index 97aae63f..941e20da 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go @@ -71,6 +71,8 @@ const ( EXTPROC = 0x10000000 FF1 = 0x4000 FFDLY = 0x4000 + FICLONE = 0x80049409 + FICLONERANGE = 0x8020940d FLUSHO = 0x800000 FS_IOC_ENABLE_VERITY = 0x80806685 FS_IOC_GETFLAGS = 0x40086601 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go b/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go index b0c3b066..63d3bc56 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go @@ -71,6 +71,8 @@ const ( EXTPROC = 0x10000000 FF1 = 0x4000 FFDLY = 0x4000 + FICLONE = 0x80049409 + FICLONERANGE = 0x8020940d FLUSHO = 0x800000 FS_IOC_ENABLE_VERITY = 0x80806685 FS_IOC_GETFLAGS = 0x40086601 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go b/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go index 0c051819..490bee1a 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go @@ -71,6 +71,8 @@ const ( EXTPROC = 0x10000 FF1 = 0x8000 FFDLY = 0x8000 + FICLONE = 0x40049409 + FICLONERANGE = 0x4020940d FLUSHO = 0x1000 FS_IOC_ENABLE_VERITY = 0x40806685 FS_IOC_GETFLAGS = 0x80086601 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go b/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go index 0b96bd46..467b8218 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go @@ -71,6 +71,8 @@ const ( EXTPROC = 0x10000 FF1 = 0x8000 FFDLY = 0x8000 + FICLONE = 0x40049409 + FICLONERANGE = 0x4020940d FLUSHO = 0x1000 FS_IOC_ENABLE_VERITY = 0x40806685 FS_IOC_GETFLAGS = 0x80086601 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go b/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go index bd5c3057..79fbafbc 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go @@ -75,6 +75,8 @@ const ( EXTPROC = 0x10000 FF1 = 0x8000 FFDLY = 0x8000 + FICLONE = 0x80049409 + FICLONERANGE = 0x8020940d FLUSHO = 0x1000 FS_IOC_ENABLE_VERITY = 0x80806685 FS_IOC_GETFLAGS = 0x40086601 diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.go b/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.go index 39761472..bd13b385 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.go @@ -490,21 +490,6 @@ func libc_munlockall_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func getattrlist(path *byte, list unsafe.Pointer, buf unsafe.Pointer, size uintptr, options int) (err error) { - _, _, e1 := syscall_syscall6(funcPC(libc_getattrlist_trampoline), uintptr(unsafe.Pointer(path)), uintptr(list), uintptr(buf), uintptr(size), uintptr(options), 0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -func libc_getattrlist_trampoline() - -//go:linkname libc_getattrlist libc_getattrlist -//go:cgo_import_dynamic libc_getattrlist getattrlist "/usr/lib/libSystem.B.dylib" - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func pipe() (r int, w int, err error) { r0, r1, e1 := syscall_rawSyscall(funcPC(libc_pipe_trampoline), 0, 0, 0) r = int(r0) @@ -1277,6 +1262,28 @@ func libc_ftruncate_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := syscall_syscall(funcPC(libc_getcwd_trampoline), uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +func libc_getcwd_trampoline() + +//go:linkname libc_getcwd libc_getcwd +//go:cgo_import_dynamic libc_getcwd getcwd "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getdtablesize() (size int) { r0, _, _ := syscall_syscall(funcPC(libc_getdtablesize_trampoline), 0, 0, 0) size = int(r0) diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.s b/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.s index 961058db..d5fb53fd 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.s +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_386.s @@ -60,8 +60,6 @@ TEXT ·libc_munlock_trampoline(SB),NOSPLIT,$0-0 JMP libc_munlock(SB) TEXT ·libc_munlockall_trampoline(SB),NOSPLIT,$0-0 JMP libc_munlockall(SB) -TEXT ·libc_getattrlist_trampoline(SB),NOSPLIT,$0-0 - JMP libc_getattrlist(SB) TEXT ·libc_pipe_trampoline(SB),NOSPLIT,$0-0 JMP libc_pipe(SB) TEXT ·libc_getxattr_trampoline(SB),NOSPLIT,$0-0 @@ -146,6 +144,8 @@ TEXT ·libc_fsync_trampoline(SB),NOSPLIT,$0-0 JMP libc_fsync(SB) TEXT ·libc_ftruncate_trampoline(SB),NOSPLIT,$0-0 JMP libc_ftruncate(SB) +TEXT ·libc_getcwd_trampoline(SB),NOSPLIT,$0-0 + JMP libc_getcwd(SB) TEXT ·libc_getdtablesize_trampoline(SB),NOSPLIT,$0-0 JMP libc_getdtablesize(SB) TEXT ·libc_getegid_trampoline(SB),NOSPLIT,$0-0 diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go b/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go index e253f438..d81696f9 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go @@ -490,21 +490,6 @@ func libc_munlockall_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func getattrlist(path *byte, list unsafe.Pointer, buf unsafe.Pointer, size uintptr, options int) (err error) { - _, _, e1 := syscall_syscall6(funcPC(libc_getattrlist_trampoline), uintptr(unsafe.Pointer(path)), uintptr(list), uintptr(buf), uintptr(size), uintptr(options), 0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -func libc_getattrlist_trampoline() - -//go:linkname libc_getattrlist libc_getattrlist -//go:cgo_import_dynamic libc_getattrlist getattrlist "/usr/lib/libSystem.B.dylib" - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func pipe() (r int, w int, err error) { r0, r1, e1 := syscall_rawSyscall(funcPC(libc_pipe_trampoline), 0, 0, 0) r = int(r0) @@ -1277,6 +1262,28 @@ func libc_ftruncate_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := syscall_syscall(funcPC(libc_getcwd_trampoline), uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +func libc_getcwd_trampoline() + +//go:linkname libc_getcwd libc_getcwd +//go:cgo_import_dynamic libc_getcwd getcwd "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getdtablesize() (size int) { r0, _, _ := syscall_syscall(funcPC(libc_getdtablesize_trampoline), 0, 0, 0) size = int(r0) diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s b/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s index b8be24c6..887fd5f4 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s @@ -60,8 +60,6 @@ TEXT ·libc_munlock_trampoline(SB),NOSPLIT,$0-0 JMP libc_munlock(SB) TEXT ·libc_munlockall_trampoline(SB),NOSPLIT,$0-0 JMP libc_munlockall(SB) -TEXT ·libc_getattrlist_trampoline(SB),NOSPLIT,$0-0 - JMP libc_getattrlist(SB) TEXT ·libc_pipe_trampoline(SB),NOSPLIT,$0-0 JMP libc_pipe(SB) TEXT ·libc_getxattr_trampoline(SB),NOSPLIT,$0-0 @@ -146,6 +144,8 @@ TEXT ·libc_fsync_trampoline(SB),NOSPLIT,$0-0 JMP libc_fsync(SB) TEXT ·libc_ftruncate_trampoline(SB),NOSPLIT,$0-0 JMP libc_ftruncate(SB) +TEXT ·libc_getcwd_trampoline(SB),NOSPLIT,$0-0 + JMP libc_getcwd(SB) TEXT ·libc_getdtablesize_trampoline(SB),NOSPLIT,$0-0 JMP libc_getdtablesize(SB) TEXT ·libc_getegid_trampoline(SB),NOSPLIT,$0-0 diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.go b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.go index be2e2831..d6b5249c 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.go @@ -490,21 +490,6 @@ func libc_munlockall_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func getattrlist(path *byte, list unsafe.Pointer, buf unsafe.Pointer, size uintptr, options int) (err error) { - _, _, e1 := syscall_syscall6(funcPC(libc_getattrlist_trampoline), uintptr(unsafe.Pointer(path)), uintptr(list), uintptr(buf), uintptr(size), uintptr(options), 0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -func libc_getattrlist_trampoline() - -//go:linkname libc_getattrlist libc_getattrlist -//go:cgo_import_dynamic libc_getattrlist getattrlist "/usr/lib/libSystem.B.dylib" - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func pipe() (r int, w int, err error) { r0, r1, e1 := syscall_rawSyscall(funcPC(libc_pipe_trampoline), 0, 0, 0) r = int(r0) @@ -1277,6 +1262,28 @@ func libc_ftruncate_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := syscall_syscall(funcPC(libc_getcwd_trampoline), uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +func libc_getcwd_trampoline() + +//go:linkname libc_getcwd libc_getcwd +//go:cgo_import_dynamic libc_getcwd getcwd "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getdtablesize() (size int) { r0, _, _ := syscall_syscall(funcPC(libc_getdtablesize_trampoline), 0, 0, 0) size = int(r0) diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.s b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.s index 403c21f0..5eec5f1d 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.s +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm.s @@ -60,8 +60,6 @@ TEXT ·libc_munlock_trampoline(SB),NOSPLIT,$0-0 JMP libc_munlock(SB) TEXT ·libc_munlockall_trampoline(SB),NOSPLIT,$0-0 JMP libc_munlockall(SB) -TEXT ·libc_getattrlist_trampoline(SB),NOSPLIT,$0-0 - JMP libc_getattrlist(SB) TEXT ·libc_pipe_trampoline(SB),NOSPLIT,$0-0 JMP libc_pipe(SB) TEXT ·libc_getxattr_trampoline(SB),NOSPLIT,$0-0 @@ -146,6 +144,8 @@ TEXT ·libc_fsync_trampoline(SB),NOSPLIT,$0-0 JMP libc_fsync(SB) TEXT ·libc_ftruncate_trampoline(SB),NOSPLIT,$0-0 JMP libc_ftruncate(SB) +TEXT ·libc_getcwd_trampoline(SB),NOSPLIT,$0-0 + JMP libc_getcwd(SB) TEXT ·libc_getdtablesize_trampoline(SB),NOSPLIT,$0-0 JMP libc_getdtablesize(SB) TEXT ·libc_getegid_trampoline(SB),NOSPLIT,$0-0 diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go index 34976a4c..08638436 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go @@ -490,21 +490,6 @@ func libc_munlockall_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func getattrlist(path *byte, list unsafe.Pointer, buf unsafe.Pointer, size uintptr, options int) (err error) { - _, _, e1 := syscall_syscall6(funcPC(libc_getattrlist_trampoline), uintptr(unsafe.Pointer(path)), uintptr(list), uintptr(buf), uintptr(size), uintptr(options), 0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -func libc_getattrlist_trampoline() - -//go:linkname libc_getattrlist libc_getattrlist -//go:cgo_import_dynamic libc_getattrlist getattrlist "/usr/lib/libSystem.B.dylib" - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func pipe() (r int, w int, err error) { r0, r1, e1 := syscall_rawSyscall(funcPC(libc_pipe_trampoline), 0, 0, 0) r = int(r0) @@ -1277,6 +1262,28 @@ func libc_ftruncate_trampoline() // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getcwd(buf []byte) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := syscall_syscall(funcPC(libc_getcwd_trampoline), uintptr(_p0), uintptr(len(buf)), 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +func libc_getcwd_trampoline() + +//go:linkname libc_getcwd libc_getcwd +//go:cgo_import_dynamic libc_getcwd getcwd "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getdtablesize() (size int) { r0, _, _ := syscall_syscall(funcPC(libc_getdtablesize_trampoline), 0, 0, 0) size = int(r0) diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s index abe7b6ed..16aebee2 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s @@ -60,8 +60,6 @@ TEXT ·libc_munlock_trampoline(SB),NOSPLIT,$0-0 JMP libc_munlock(SB) TEXT ·libc_munlockall_trampoline(SB),NOSPLIT,$0-0 JMP libc_munlockall(SB) -TEXT ·libc_getattrlist_trampoline(SB),NOSPLIT,$0-0 - JMP libc_getattrlist(SB) TEXT ·libc_pipe_trampoline(SB),NOSPLIT,$0-0 JMP libc_pipe(SB) TEXT ·libc_getxattr_trampoline(SB),NOSPLIT,$0-0 @@ -146,6 +144,8 @@ TEXT ·libc_fsync_trampoline(SB),NOSPLIT,$0-0 JMP libc_fsync(SB) TEXT ·libc_ftruncate_trampoline(SB),NOSPLIT,$0-0 JMP libc_ftruncate(SB) +TEXT ·libc_getcwd_trampoline(SB),NOSPLIT,$0-0 + JMP libc_getcwd(SB) TEXT ·libc_getdtablesize_trampoline(SB),NOSPLIT,$0-0 JMP libc_getdtablesize(SB) TEXT ·libc_getegid_trampoline(SB),NOSPLIT,$0-0 diff --git a/vendor/golang.org/x/sys/unix/zsyscall_illumos_amd64.go b/vendor/golang.org/x/sys/unix/zsyscall_illumos_amd64.go index 8b329c45..d3af083f 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_illumos_amd64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_illumos_amd64.go @@ -13,7 +13,7 @@ import ( //go:cgo_import_dynamic libc_preadv preadv "libc.so" //go:cgo_import_dynamic libc_writev writev "libc.so" //go:cgo_import_dynamic libc_pwritev pwritev "libc.so" -//go:cgo_import_dynamic libc_accept4 accept4 "libc.so" +//go:cgo_import_dynamic libc_accept4 accept4 "libsocket.so" //go:cgo_import_dynamic libc_pipe2 pipe2 "libc.so" //go:linkname procreadv libc_readv diff --git a/vendor/golang.org/x/sys/unix/ztypes_darwin_386.go b/vendor/golang.org/x/sys/unix/ztypes_darwin_386.go index 9f47b87c..6103f215 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_darwin_386.go +++ b/vendor/golang.org/x/sys/unix/ztypes_darwin_386.go @@ -145,6 +145,10 @@ type Dirent struct { _ [3]byte } +const ( + PathMax = 0x400 +) + type RawSockaddrInet4 struct { Len uint8 Family uint8 diff --git a/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go b/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go index 966798a8..e6576d1c 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go +++ b/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go @@ -151,6 +151,10 @@ type Dirent struct { _ [3]byte } +const ( + PathMax = 0x400 +) + type RawSockaddrInet4 struct { Len uint8 Family uint8 diff --git a/vendor/golang.org/x/sys/unix/ztypes_darwin_arm.go b/vendor/golang.org/x/sys/unix/ztypes_darwin_arm.go index 4fe4c9cd..af9560fa 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_darwin_arm.go +++ b/vendor/golang.org/x/sys/unix/ztypes_darwin_arm.go @@ -146,6 +146,10 @@ type Dirent struct { _ [3]byte } +const ( + PathMax = 0x400 +) + type RawSockaddrInet4 struct { Len uint8 Family uint8 diff --git a/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go b/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go index 21999e4b..a09c0f94 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go +++ b/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go @@ -151,6 +151,10 @@ type Dirent struct { _ [3]byte } +const ( + PathMax = 0x400 +) + type RawSockaddrInet4 struct { Len uint8 Family uint8 diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux.go b/vendor/golang.org/x/sys/unix/ztypes_linux.go index 68e4974a..a92a5019 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux.go @@ -76,6 +76,21 @@ type Fsid struct { Val [2]int32 } +type FileCloneRange struct { + Src_fd int64 + Src_offset uint64 + Src_length uint64 + Dest_offset uint64 +} + +type FileDedupeRange struct { + Src_offset uint64 + Src_length uint64 + Dest_count uint16 + Reserved1 uint16 + Reserved2 uint32 +} + type FscryptPolicy struct { Version uint8 Contents_encryption_mode uint8 diff --git a/vendor/modules.txt b/vendor/modules.txt index 2f844bba..3f1b8efd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -27,11 +27,13 @@ github.com/prometheus/common/model github.com/prometheus/procfs github.com/prometheus/procfs/internal/fs github.com/prometheus/procfs/internal/util -# golang.org/x/sys v0.0.0-20200916084744-dbad9cb7cb7a +# golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f ## explicit golang.org/x/sys/internal/unsafeheader golang.org/x/sys/unix golang.org/x/sys/windows +# golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 +## explicit # google.golang.org/protobuf v1.25.0 ## explicit google.golang.org/protobuf/encoding/prototext diff --git a/watchdog/watchdog.go b/watchdog/watchdog.go index fa40d19d..b1214319 100644 --- a/watchdog/watchdog.go +++ b/watchdog/watchdog.go @@ -22,9 +22,9 @@ var ( monitoringMutex sync.Mutex ) -// GetJsonEncodedServiceResults returns a list of the last 20 results for each services encoded using json.Marshal. +// GetJSONEncodedServiceResults returns a list of the last 20 results for each services encoded using json.Marshal. // The reason why the encoding is done here is because we use a mutex to prevent concurrent map access. -func GetJsonEncodedServiceResults() ([]byte, error) { +func GetJSONEncodedServiceResults() ([]byte, error) { serviceResultsMutex.RLock() data, err := json.Marshal(serviceResults) serviceResultsMutex.RUnlock()