Skip to content

Commit

Permalink
[v2] update endpoints to separate intake from assets (elastic#1360)
Browse files Browse the repository at this point in the history
Closes elastic#1336.
  • Loading branch information
roncohen authored and Ron cohen committed Oct 16, 2018
1 parent 757182c commit 79f9eb5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 32 deletions.
53 changes: 30 additions & 23 deletions beater/route_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,26 @@ import (
)

var (
rootURL = "/"
BackendTransactionsURL = "/v1/transactions"
ClientSideTransactionsURL = "/v1/client-side/transactions"
RumTransactionsURL = "/v1/rum/transactions"
BackendErrorsURL = "/v1/errors"
ClientSideErrorsURL = "/v1/client-side/errors"
RumErrorsURL = "/v1/rum/errors"
MetricsURL = "/v1/metrics"
SourcemapsClientSideURL = "/v1/client-side/sourcemaps"
SourcemapsURL = "/v1/rum/sourcemaps"
V2BackendURL = "/v2/intake"
V2RumURL = "/v2/rum/intake"

HealthCheckURL = "/healthcheck"
rootURL = "/"

// intake v2
V2BackendURL = "/intake/v2/events"
V2RumURL = "/intake/v2/rum/events"

// assets
SourcemapsURL = "/assets/v1/sourcemaps"

// deprecated
SourcemapsClientSideURLDeprecated = "/v1/client-side/sourcemaps"
SourcemapsURLDeprecated = "/v1/rum/sourcemaps"
BackendTransactionsURL = "/v1/transactions"
ClientSideTransactionsURL = "/v1/client-side/transactions"
RumTransactionsURL = "/v1/rum/transactions"
BackendErrorsURL = "/v1/errors"
ClientSideErrorsURL = "/v1/client-side/errors"
RumErrorsURL = "/v1/rum/errors"
MetricsURL = "/v1/metrics"
HealthCheckURL = "/healthcheck"
)

type routeType struct {
Expand All @@ -59,15 +65,16 @@ type routeType struct {
}

var V1Routes = map[string]v1Route{
BackendTransactionsURL: {backendRouteType, transaction.Processor, v1RequestDecoder},
ClientSideTransactionsURL: {rumRouteType, transaction.Processor, v1RequestDecoder},
RumTransactionsURL: {rumRouteType, transaction.Processor, v1RequestDecoder},
BackendErrorsURL: {backendRouteType, perr.Processor, v1RequestDecoder},
ClientSideErrorsURL: {rumRouteType, perr.Processor, v1RequestDecoder},
RumErrorsURL: {rumRouteType, perr.Processor, v1RequestDecoder},
MetricsURL: {metricsRouteType, metric.Processor, v1RequestDecoder},
SourcemapsClientSideURL: {sourcemapRouteType, sourcemap.Processor, sourcemapUploadDecoder},
SourcemapsURL: {sourcemapRouteType, sourcemap.Processor, sourcemapUploadDecoder},
BackendTransactionsURL: {backendRouteType, transaction.Processor, v1RequestDecoder},
ClientSideTransactionsURL: {rumRouteType, transaction.Processor, v1RequestDecoder},
RumTransactionsURL: {rumRouteType, transaction.Processor, v1RequestDecoder},
BackendErrorsURL: {backendRouteType, perr.Processor, v1RequestDecoder},
ClientSideErrorsURL: {rumRouteType, perr.Processor, v1RequestDecoder},
RumErrorsURL: {rumRouteType, perr.Processor, v1RequestDecoder},
MetricsURL: {metricsRouteType, metric.Processor, v1RequestDecoder},
SourcemapsURL: {sourcemapRouteType, sourcemap.Processor, sourcemapUploadDecoder},
SourcemapsClientSideURLDeprecated: {sourcemapRouteType, sourcemap.Processor, sourcemapUploadDecoder},
SourcemapsURLDeprecated: {sourcemapRouteType, sourcemap.Processor, sourcemapUploadDecoder},
}

var V2Routes = map[string]v2Route{
Expand Down
8 changes: 4 additions & 4 deletions beater/v2_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

func TestInvalidContentType(t *testing.T) {
req := httptest.NewRequest("POST", "/v2/intake", nil)
req := httptest.NewRequest("POST", V2BackendURL, nil)
w := httptest.NewRecorder()

c := defaultConfig("7.0.0")
Expand All @@ -49,7 +49,7 @@ func TestInvalidContentType(t *testing.T) {
}

func TestEmptyRequest(t *testing.T) {
req := httptest.NewRequest("POST", "/v2/intake", nil)
req := httptest.NewRequest("POST", V2BackendURL, nil)
req.Header.Add("Content-Type", "application/x-ndjson")

w := httptest.NewRecorder()
Expand All @@ -63,7 +63,7 @@ func TestEmptyRequest(t *testing.T) {
}

func TestRequestDecoderError(t *testing.T) {
req := httptest.NewRequest("POST", "/v2/intake", bytes.NewBufferString(`asdasd`))
req := httptest.NewRequest("POST", V2BackendURL, bytes.NewBufferString(`asdasd`))
req.Header.Add("Content-Type", "application/x-ndjson")

w := httptest.NewRecorder()
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestRequestIntegration(t *testing.T) {
require.NoError(t, err)
bodyReader := bytes.NewBuffer(b)

req := httptest.NewRequest("POST", "/v2/intake", bodyReader)
req := httptest.NewRequest("POST", V2BackendURL, bodyReader)
req.Header.Add("Content-Type", "application/x-ndjson")

w := httptest.NewRecorder()
Expand Down
6 changes: 4 additions & 2 deletions docs/sourcemap-api.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ Send a `HTTP POST` request with the `Content-Type` header set to `multipart/form

[source,bash]
------------------------------------------------------------
http(s)://{hostname}:{port}/v1/rum/sourcemaps
http(s)://{hostname}:{port}/assets/v1/sourcemaps
------------------------------------------------------------

NOTE: The URL for uploading sourcemaps was previously `/v1/sourcemaps`. It still works, but is being deprecated in favor of `/assets/v1/sourcemaps`.

[[sourcemap-request-fields]]
[float]
==== Request Fields
Expand All @@ -35,7 +37,7 @@ Example source map request including an optional <<secret-token, secret token>>

["source","sh",subs="attributes"]
---------------------------------------------------------------------------
curl -X POST http://127.0.0.1:8200/v1/rum/sourcemaps \
curl -X POST http://127.0.0.1:8200/assets/v1/sourcemaps \
-H "Authorization: Bearer mysecret" \
-F service_name="test-service" \
-F service_version="1.0" \
Expand Down
2 changes: 1 addition & 1 deletion tests/system/apmserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def check_for_no_smap(self, doc):
class ClientSideBaseTest(ServerBaseTest):
transactions_url = 'http://localhost:8200/v1/rum/transactions'
errors_url = 'http://localhost:8200/v1/rum/errors'
sourcemap_url = 'http://localhost:8200/v1/rum/sourcemaps'
sourcemap_url = 'http://localhost:8200/assets/v1/sourcemaps'

@classmethod
def setUpClass(cls):
Expand Down
2 changes: 1 addition & 1 deletion tests/system/test_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_with_token_v2(self):
Test that access works with token
"""

url = 'http://localhost:8200/v2/intake'
url = 'http://localhost:8200/intake/v2/events'
transactions = self.get_transaction_v2_payload()
headers = {'content-type': 'application/x-ndjson'}

Expand Down
2 changes: 1 addition & 1 deletion tests/system/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_rum_default_disabled(self):
'http://localhost:8200/v1/client-side/transactions', json=transactions)
assert r.status_code == 403, r.status_code

def test_rum_default_disabled(self):
def test_rum_default_disabled_2(self):
transactions = self.get_transaction_payload()
r = requests.post(
'http://localhost:8200/v1/rum/transactions', json=transactions)
Expand Down

0 comments on commit 79f9eb5

Please sign in to comment.