Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Edge service retries #55

Merged
merged 10 commits into from
Jul 7, 2023
Merged

Edge service retries #55

merged 10 commits into from
Jul 7, 2023

Conversation

BrooksCunningham
Copy link
Contributor

@BrooksCunningham BrooksCunningham commented Jun 26, 2023

The intention of this PR is to make the function CreateOrUpdateEdgeDeploymentService() more resilient by adding a limited number of retries. This way if the edge service is not ready yet, requests will continue to be made until successful or the maximum number of statically defined number of retries is exceeded.

The function doRequestDetailed() was also added to provide access to the entire response object, which includes the response status, headers, and body. The response status is useful to various case switches to break out of the retry logic.

I have done 2 tests which both involve attempting to create and link and NGWAF edge service to a VCL service.

package main

import (
	"log"
	"os"
	"time"

	sigsci "github.com/signalsciences/go-sigsci"
)

func main() {
	corp := os.Getenv("NGWAF_CORP")
	site := os.Getenv("NGWAF_SITE")
	email := os.Getenv("NGWAF_EMAIL")
	token := os.Getenv("NGWAF_TOKEN")

	fastly_sid := "" //your sid here
	fastly_api_key := os.Getenv("FASTLY_API_KEY")
	ActivateVersion := true
	PercentEnabled := 100

	const sleep_time = 2 * time.Second

	sc := sigsci.NewTokenClient(email, token)

	sc.SetFastlyKey(fastly_api_key)

	log.Println("Creating edge deployment with updated API")

	log.Println(sc.CreateOrUpdateEdgeDeployment(corp, site))

	CreateOrUpdateEdgeDeploymentServiceBody := sigsci.CreateOrUpdateEdgeDeploymentServiceBody{
		ActivateVersion: &ActivateVersion,
		PercentEnabled:  PercentEnabled,
	}
	log.Println(sc.CreateOrUpdateEdgeDeploymentService(corp, site, fastly_sid, CreateOrUpdateEdgeDeploymentServiceBody))

}

  1. For the first test, which was designed to fail, I tried calling on a SID that did not exist by leaving fastly_sid blank. Below is that result.
2023/06/26 12:58:59 Creating edge deployment with updated API
2023/06/26 12:59:41 <nil>
2023/06/26 13:08:07 <nil>

No modificaitons were made to the VCL as expected.

  1. For my second test, I create a VCL service and used a valid Fastly SID in the above script. Below is that output.
2023/06/26 13:10:15 Creating edge deployment with updated API
2023/06/26 13:11:10 <nil>
2023/06/26 13:11:39 <nil>

The expected modificaitons were made to the VCL with the edge inspector linked.

Please let me know if there are other tests that would provide better coverage.

api.go Show resolved Hide resolved
api.go Outdated Show resolved Hide resolved
@BrooksCunningham
Copy link
Contributor Author

@mattg-sigsci @shawnps Please let me know what I can do to help move this PR forward. Thank you for the help on this.

mattg-sigsci
mattg-sigsci previously approved these changes Jul 6, 2023
Copy link
Contributor

@mattg-sigsci mattg-sigsci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending resolution of the conversation in Slack.

api.go Outdated Show resolved Hide resolved
…Look for Retry-After response header on 404 responses before restarting
@shawnps shawnps merged commit 973b55a into main Jul 7, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants