Repository: GoogleCloudPlatform/kubectl-ai
File: gollm/factory.go (Go)

Code before:
	if errors.As(err, &apiErr) {
		switch apiErr.StatusCode {
		case http.StatusConflict, http.StatusTooManyRequests,
			http.StatusInternalServerError, http.StatusBadGateway,
			http.StatusServiceUnavailable, http.StatusGatewayTimeout:
			return true
		default:
			return false
		}
	}

	var netErr net.Error
	if errors.As(err, &netErr) && netErr.Timeout() {
		return true
	}

	// Add other error checks specific to LLM clients if needed
	// e.g., if errors.Is(err, specificLLMRateLimitError) { return true }

	return false
}

// createCustomHTTPClient returns an *http.Client that optionally skips SSL certificate verification.
// This is shared by all providers that need custom HTTP transport.
func createCustomHTTPClient(skipVerify bool) *http.Client {
	transport := http.DefaultTransport.(*http.Transport).Clone()
	transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: skipVerify}

	return &http.Client{
		Transport: transport,
		Timeout:   180 * time.Second,
	}
}

// RetryConfig holds the configuration for the retry mechanism (same as before)
type RetryConfig struct {
	MaxAttempts    int
	InitialBackoff time.Duration
	MaxBackoff     time.Duration
	BackoffFactor  float64
	Jitter         bool
}

// DefaultRetryConfig provides sensible defaults (same as before)
var DefaultRetryConfig = RetryConfig{
	MaxAttempts:    5,
	InitialBackoff: 200 * time.Millisecond, // Slightly increased default
	MaxBackoff:     10 * time.Second,
	BackoffFactor:  2.0,
	Jitter:         true,
}

Review comment (bug):
Not sure if you want to get this http client related changes in with the `list-*` task changes. Looks like this is related to http tracing.

The change skips setting `Proxy: http.ProxyFromEnvironment` which will disable honoring the http proxy environment variables (a bug). 

Code after:
	if errors.As(err, &apiErr) {
		switch apiErr.StatusCode {
		case http.StatusConflict, http.StatusTooManyRequests,
			http.StatusInternalServerError, http.StatusBadGateway,
			http.StatusServiceUnavailable, http.StatusGatewayTimeout:
			return true
		default:
			return false
		}
	}

	var netErr net.Error
	if errors.As(err, &netErr) && netErr.Timeout() {
		return true
	}

	// Add other error checks specific to LLM clients if needed
	// e.g., if errors.Is(err, specificLLMRateLimitError) { return true }

	return false
}

// createCustomHTTPClient returns an *http.Client that optionally skips SSL certificate verification.
// This is shared by all providers that need custom HTTP transport.
func createCustomHTTPClient(skipVerify bool) *http.Client {
	if !skipVerify {
		httpClient := http.DefaultClient
		httpClient.Timeout = 60 * time.Second
		return httpClient
	}
	return &http.Client{
		Transport: &http.Transport{
			Proxy: http.ProxyFromEnvironment,
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: true,
			},
		},
		Timeout: 60 * time.Second,
	}
}

// RetryConfig holds the configuration for the retry mechanism (same as before)
type RetryConfig struct {
	MaxAttempts    int
	InitialBackoff time.Duration
	MaxBackoff     time.Duration
	BackoffFactor  float64
	Jitter         bool
}

// DefaultRetryConfig provides sensible defaults (same as before)