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

POA-2390 Exclude certain Cloud API endpoints from Repro Mode #50

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion trace/backend_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package trace
import (
"encoding/base64"
"net"
"regexp"
"sync"
"time"

Expand All @@ -11,6 +12,7 @@ import (
"github.com/akitasoftware/akita-libs/akinet"
kgxapi "github.com/akitasoftware/akita-libs/api_schema"
"github.com/akitasoftware/akita-libs/batcher"
"github.com/akitasoftware/akita-libs/http_rest_methods"
"github.com/akitasoftware/akita-libs/spec_util"
"github.com/akitasoftware/akita-libs/spec_util/ir_hash"
"github.com/akitasoftware/go-utils/optionals"
Expand Down Expand Up @@ -280,6 +282,45 @@ func (c *BackendCollector) processTLSHandshake(tls akinet.TLSHandshakeMetadata)
return nil
}

var cloudAPIEnvironmentsPathRE = regexp.MustCompile(`^/environments/[^/]+$`)

// Returns true if the witness should be excluded from Repro Mode.
//
// XXX This is a stop-gap hack to exclude certain endpoints for Cloud API from
// Repro Mode.
func excludeWitnessFromReproMode(w *pb.Witness) bool {

httpMeta := w.GetMethod().GetMeta().GetHttp()
if httpMeta == nil {
return false
}

switch httpMeta.Host {
case "api.getpostman-stage.com", "api.getpostman.com":
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that unfortunately there are several more domain names that are possible than this.

I tried and api.postman.com worked, while api.postman.co got a 301 (but maybe we need to match it anyway?)

I will communicate some possible sources of truth offline.

switch httpMeta.Method {
case http_rest_methods.GET.String():
// Exclude GET /environments/{environment}.
if cloudAPIEnvironmentsPathRE.MatchString(httpMeta.PathTemplate) {
return true
}

case http_rest_methods.POST.String():
// Exclude POST /environments.
if httpMeta.PathTemplate == "/environments" {
return true
}

case http_rest_methods.PUT.String():
// Exclude PUT /environments/{environment}.
// Exclude GET /environments/{environment}.
if cloudAPIEnvironmentsPathRE.MatchString(httpMeta.PathTemplate) {
return true
}
}
}
return false
}

func (c *BackendCollector) queueUpload(w *witnessWithInfo) {
// Mark the method as not obfuscated.
w.witness.GetMethod().GetMeta().GetHttp().Obfuscation = pb.HTTPMethodMeta_NONE
Expand All @@ -292,7 +333,9 @@ func (c *BackendCollector) queueUpload(w *witnessWithInfo) {
}
}

if !c.sendWitnessPayloads || !hasOnlyErrorResponses(w.witness.GetMethod()) {
if !c.sendWitnessPayloads ||
!hasOnlyErrorResponses(w.witness.GetMethod()) ||
excludeWitnessFromReproMode(w.witness) {
// Obfuscate the original value so type inference engine can use it on the
// backend without revealing the actual value.
c.obfuscator.ZeroAllPrimitivesInMethod(w.witness.GetMethod())
Expand Down