Skip to content

Commit

Permalink
Move Sourcemap from model to sourcemap handler (#5720) (#5725)
Browse files Browse the repository at this point in the history
Reserve model for event types, not auxiliary documents like this.

(cherry picked from commit a63733b)

Co-authored-by: Andrew Wilkins <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mergify[bot] and axw authored Jul 15, 2021
1 parent 8108873 commit c35dd1b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
9 changes: 4 additions & 5 deletions beater/api/asset/sourcemap/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

"github.com/elastic/apm-server/beater/auth"
"github.com/elastic/apm-server/beater/request"
"github.com/elastic/apm-server/model"
"github.com/elastic/apm-server/publish"
"github.com/elastic/apm-server/utility"
)
Expand Down Expand Up @@ -75,7 +74,7 @@ func Handler(report publish.Reporter, notifier AddedNotifier) request.Handler {
return
}

var smap model.Sourcemap
var smap sourcemapDoc
decodingCount.Inc()
if err := decode(c.Request, &smap); err != nil {
decodingError.Inc()
Expand All @@ -88,7 +87,7 @@ func Handler(report publish.Reporter, notifier AddedNotifier) request.Handler {
return
}
validateCount.Inc()
if err := validate(smap); err != nil {
if err := validate(&smap); err != nil {
validateError.Inc()
c.Result.SetWithError(request.IDResponseErrorsValidate, err)
c.Write()
Expand All @@ -114,7 +113,7 @@ func Handler(report publish.Reporter, notifier AddedNotifier) request.Handler {
}
}

func decode(req *http.Request, smap *model.Sourcemap) error {
func decode(req *http.Request, smap *sourcemapDoc) error {
if !strings.Contains(req.Header.Get("Content-Type"), "multipart/form-data") {
return fmt.Errorf("invalid content type: %s", req.Header.Get("Content-Type"))
}
Expand All @@ -134,7 +133,7 @@ func decode(req *http.Request, smap *model.Sourcemap) error {
return nil
}

func validate(smap model.Sourcemap) error {
func validate(smap *sourcemapDoc) error {
// ensure all information is given
if smap.BundleFilepath == "" || smap.ServiceName == "" || smap.ServiceVersion == "" {
return errors.New("error validating sourcemap: bundle_filepath, service_name and service_version must be sent")
Expand Down
10 changes: 5 additions & 5 deletions model/sourcemap.go → beater/api/asset/sourcemap/sourcemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package model
package sourcemap

import (
"context"
Expand All @@ -35,19 +35,19 @@ const (
)

var (
registry = monitoring.Default.NewRegistry("apm-server.processor.sourcemap")
sourcemapCounter = monitoring.NewInt(registry, "counter")
processorRegistry = monitoring.Default.NewRegistry("apm-server.processor.sourcemap")
sourcemapCounter = monitoring.NewInt(processorRegistry, "counter")
sourcemapProcessorEntry = common.MapStr{"name": sourcemapProcessorName, "event": sourcemapDocType}
)

type Sourcemap struct {
type sourcemapDoc struct {
ServiceName string
ServiceVersion string
Sourcemap string
BundleFilepath string
}

func (pa *Sourcemap) Transform(ctx context.Context, cfg *transform.Config) []beat.Event {
func (pa *sourcemapDoc) Transform(ctx context.Context, cfg *transform.Config) []beat.Event {
sourcemapCounter.Inc()
if pa == nil {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package model_test
package sourcemap

import (
"context"
Expand All @@ -28,7 +28,6 @@ import (

"github.com/elastic/beats/v7/libbeat/common"

"github.com/elastic/apm-server/model"
"github.com/elastic/apm-server/transform"
)

Expand All @@ -38,7 +37,7 @@ func getStr(data common.MapStr, key string) string {
}

func TestTransform(t *testing.T) {
p := model.Sourcemap{
p := sourcemapDoc{
ServiceName: "myService",
ServiceVersion: "1.0",
BundleFilepath: "/my/path",
Expand All @@ -59,7 +58,7 @@ func TestTransform(t *testing.T) {
}

func TestParseSourcemaps(t *testing.T) {
fileBytes, err := ioutil.ReadFile("../testdata/sourcemap/bundle.js.map")
fileBytes, err := ioutil.ReadFile("../../../../testdata/sourcemap/bundle.js.map")
assert.NoError(t, err)
parser, err := s.Parse("", fileBytes)
assert.NoError(t, err)
Expand Down

0 comments on commit c35dd1b

Please sign in to comment.