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

chore: Merge inline context work into main branch for release #341

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ require (
github.com/launchdarkly/go-configtypes v1.1.0
github.com/launchdarkly/go-jsonstream/v3 v3.0.0
github.com/launchdarkly/go-sdk-common/v3 v3.1.0
github.com/launchdarkly/go-sdk-events/v3 v3.1.0
github.com/launchdarkly/go-sdk-events/v3 v3.2.0
github.com/launchdarkly/go-server-sdk-consul/v3 v3.0.0
github.com/launchdarkly/go-server-sdk-dynamodb/v4 v4.0.0
github.com/launchdarkly/go-server-sdk-evaluation/v3 v3.0.0
github.com/launchdarkly/go-server-sdk-redis-redigo/v3 v3.0.0
github.com/launchdarkly/go-server-sdk/v7 v7.0.0
github.com/launchdarkly/go-server-sdk/v7 v7.1.0
github.com/launchdarkly/go-test-helpers/v3 v3.0.2
github.com/launchdarkly/opencensus-go-exporter-stackdriver v0.14.2
github.com/pborman/uuid v1.2.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ github.com/launchdarkly/go-ntlmssp v1.0.1 h1:snB77118TQvf9tfHrkSyrIop/UX5e5VD2D2
github.com/launchdarkly/go-ntlmssp v1.0.1/go.mod h1:/cq3t2JyALD7GdVF5BEWcEuGlIGa44FZ4v4CVk7vuCY=
github.com/launchdarkly/go-sdk-common/v3 v3.1.0 h1:KNCP5rfkOt/25oxGLAVgaU1BgrZnzH9Y/3Z6I8bMwDg=
github.com/launchdarkly/go-sdk-common/v3 v3.1.0/go.mod h1:mXFmDGEh4ydK3QilRhrAyKuf9v44VZQWnINyhqbbOd0=
github.com/launchdarkly/go-sdk-events/v3 v3.1.0 h1:UbiksMwJOrE2VxBZ85bjfiFnLOYFfzaaddqBQJeTe/s=
github.com/launchdarkly/go-sdk-events/v3 v3.1.0/go.mod h1:oepYWQ2RvvjfL2WxkE1uJJIuRsIMOP4WIVgUpXRPcNI=
github.com/launchdarkly/go-sdk-events/v3 v3.2.0 h1:FUby/4cUSVDghCkFDpvy+7vZlIW4+CK95HjQnuqGXVs=
github.com/launchdarkly/go-sdk-events/v3 v3.2.0/go.mod h1:oepYWQ2RvvjfL2WxkE1uJJIuRsIMOP4WIVgUpXRPcNI=
github.com/launchdarkly/go-semver v1.0.2 h1:sYVRnuKyvxlmQCnCUyDkAhtmzSFRoX6rG2Xa21Mhg+w=
github.com/launchdarkly/go-semver v1.0.2/go.mod h1:xFmMwXba5Mb+3h72Z+VeSs9ahCvKo2QFUTHRNHVqR28=
github.com/launchdarkly/go-server-sdk-consul/v3 v3.0.0 h1:AXmmU4rsMxdA75o4a9p+7Pl3SzdfUCLIw7CM7pBRifE=
Expand All @@ -340,8 +340,8 @@ github.com/launchdarkly/go-server-sdk-evaluation/v3 v3.0.0 h1:nQbR1xCpkdU9Z71FI2
github.com/launchdarkly/go-server-sdk-evaluation/v3 v3.0.0/go.mod h1:cwk7/7SzNB2wZbCZS7w2K66klMLBe3NFM3/qd3xnsRc=
github.com/launchdarkly/go-server-sdk-redis-redigo/v3 v3.0.0 h1:ItkPbTEzz0ObNzIpA3DfPqgEgeNyqno/Lnfd7BjC0Ns=
github.com/launchdarkly/go-server-sdk-redis-redigo/v3 v3.0.0/go.mod h1:ho3n0ML1YbV0QRnidDNF9ooFIC66FiVzZGW0u4behG0=
github.com/launchdarkly/go-server-sdk/v7 v7.0.0 h1:HnMk6wZkciLVf3lHtwS5VdaMa8iXchfkJY0IF+nA4WE=
github.com/launchdarkly/go-server-sdk/v7 v7.0.0/go.mod h1:gMpJ/YVz5PAhg3YvwaTF3vkZPZeA0bIhIzSQSWsM59s=
github.com/launchdarkly/go-server-sdk/v7 v7.1.0 h1:gv7LXMuP0v4/iCcYE4F/4FFHHHo+K1OftJTxgm9WXQE=
github.com/launchdarkly/go-server-sdk/v7 v7.1.0/go.mod h1:+VdDZzCw8eyhuakZAJciiB6NjfltApenvIRTuTiqtFE=
github.com/launchdarkly/go-test-helpers/v2 v2.2.0/go.mod h1:L7+th5govYp5oKU9iN7To5PgznBuIjBPn+ejqKR0avw=
github.com/launchdarkly/go-test-helpers/v2 v2.3.2 h1:WX6qSzt7v8xz6d94nVcoil9ljuLTC/6OzQt0MhWYxsQ=
github.com/launchdarkly/go-test-helpers/v3 v3.0.2 h1:rh0085g1rVJM5qIukdaQ8z1XTWZztbJ49vRZuveqiuU=
Expand Down
13 changes: 9 additions & 4 deletions internal/events/event-relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,17 @@ func (r *analyticsEventEndpointDispatcher) dispatch(w http.ResponseWriter, req *
metadata := GetEventPayloadMetadata(req)

r.loggers.Debugf("Received %d events (v%d) to be proxied to %s", len(evts), metadata.SchemaVersion, r.remotePath)
if metadata.SchemaVersion >= SummaryEventsSchemaVersion {
// New-style events that have already gone through summarization - deliver them as-is
r.getVerbatimRelay().enqueue(metadata, evts)
} else {
if metadata.SchemaVersion < SummaryEventsSchemaVersion {
r.getSummarizingRelay().enqueue(metadata, evts)
return
}

if _, ok := req.Header[http.CanonicalHeaderKey(EventUnsummarizedHeader)]; ok {
r.getSummarizingRelay().enqueue(metadata, evts)
return
}

r.getVerbatimRelay().enqueue(metadata, evts)
})
}

Expand Down
4 changes: 4 additions & 0 deletions internal/events/event_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const (
// EventSchemaHeader is an HTTP header that describes the schema version for event requests.
EventSchemaHeader = "X-LaunchDarkly-Event-Schema"

// EventUnsummarizedHeader is an HTTP header that denotes events being received have not gone
// through the standard event summarization process.
EventUnsummarizedHeader = "X-LaunchDarkly-Unsummarized"

// TagsHeader is an HTTP header that may be sent by SDKs that support application metadata.
// We copy the value of this header when proxying events.
TagsHeader = "X-LaunchDarkly-Tags"
Expand Down
28 changes: 25 additions & 3 deletions internal/events/summarizing-relay-testdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ func makeAllSummarizeEventsParams() []summarizeEventsParams {
}
]`,
},
{
name: "php feature event using schema 4 will be summarized",
schemaVersion: 4,
inputEventsJSON: `
[
{ "kind": "feature", "creationDate": 1000, "key": "flagkey", "user": {"key": "userkey"},
"value": "b", "default": "c", "version": 11, "variation": 1, "trackEvents": false, "samplingRatio": 1, "excludeFromSummaries": false }
]`,
expectedEventsJSON: `
[
{ "kind": "index", "creationDate": 1000, "context": {"key": "userkey"} },
{
"kind": "summary", "startDate": 1000, "endDate": 1000,
"features": {
"flagkey": {
"default": "c", "contextKinds": ["user"],
"counters": [{"variation": 1, "version": 11, "value": "b", "count": 1}]
}
}
}
]`,
},
{
name: "feature event has non-standard defaults for ratio and exclusion fields",
inputEventsJSON: `
Expand All @@ -106,13 +128,13 @@ func makeAllSummarizeEventsParams() []summarizeEventsParams {
name: "feature event includes the provided sampling ratio",
inputEventsJSON: `
[
{ "kind": "feature", "creationDate": 1000, "key": "flagkey", "user": {"key": "userkey"},
{ "kind": "feature", "creationDate": 1000, "key": "flagkey", "context": {"key": "userkey"},
"value": "b", "default": "c", "version": 11, "variation": 1, "trackEvents": true, "samplingRatio": 0 }
]`,
expectedEventsJSON: `
[
{"kind":"index","creationDate":1000,"context":{"key": "userkey"}},
{"kind":"feature","creationDate":1000,"key":"flagkey","version":11,"contextKeys":{"user":"userkey"},"variation":1,"value":"b","default":"c","samplingRatio":0},
{"kind":"feature","creationDate":1000,"key":"flagkey","version":11,"context":{"key":"userkey"},"variation":1,"value":"b","default":"c","samplingRatio":0},
{"kind":"summary","startDate":1000,"endDate":1000,"features":{"flagkey":{"default":"c","counters":[{"variation":1,"version":11,"value":"b","count":1}],"contextKinds":["user"]}}}
]`,
},
Expand All @@ -126,7 +148,7 @@ func makeAllSummarizeEventsParams() []summarizeEventsParams {
expectedEventsJSON: `
[
{"kind":"index","creationDate":1000,"context":{"key": "userkey"}},
{"kind":"feature","creationDate":1000,"key":"flagkey","version":11,"contextKeys":{"user":"userkey"},"variation":1,"value":"b","default":"c"}
{"kind":"feature","creationDate":1000,"key":"flagkey","version":11,"context":{"key":"userkey"},"variation":1,"value":"b","default":"c"}
]`,
},
{
Expand Down
5 changes: 4 additions & 1 deletion internal/events/summarizing-relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ func TestSummarizeEvents(t *testing.T) {
_, _ = st.UpsertFlag(p.dataStore, ep.storedFlag)
}

req := st.BuildRequest("POST", "/", []byte(ep.inputEventsJSON), headersWithEventSchema(ep.schemaVersion))
headers := headersWithEventSchema(ep.schemaVersion)
headers.Set(EventUnsummarizedHeader, "true")

req := st.BuildRequest("POST", "/", []byte(ep.inputEventsJSON), headers)
p.dispatcher.GetHandler(basictypes.ServerSDK, ldevents.AnalyticsEventDataKind)(httptest.NewRecorder(), req)
p.dispatcher.flush()

Expand Down
Loading