From 4ba70d57110f6ff7f4fbf8b176133e7887529201 Mon Sep 17 00:00:00 2001 From: Vivek Singh Chauhan Date: Tue, 22 Nov 2022 19:39:49 -0700 Subject: [PATCH] APIGOV-000000 - Updates to setup consumer details in metric event (#117) * APIGOV-000000 - Updates to setup consumer subscription details in metric event * APIGOV-000000 - unit test fix --- go.mod | 2 +- go.sum | 4 ++-- pkg/anypoint/client.go | 1 + pkg/anypoint/types.go | 1 + pkg/traceability/agent_test.go | 4 ++++ pkg/traceability/eventmapper.go | 5 ++--- pkg/traceability/eventmapper_test.go | 5 +---- pkg/traceability/eventprocessor_test.go | 2 +- pkg/traceability/muleemitter.go | 4 ++++ 9 files changed, 17 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index f1c748e..4b6a09f 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 //replace github.com/Axway/agent-sdk => /home/ubuntu/go/src/github.com/Axway/agent-sdk require ( - github.com/Axway/agent-sdk v1.1.37 + github.com/Axway/agent-sdk v1.1.42-0.20221118150152-f2a1d8f05a9d github.com/elastic/beats/v7 v7.17.5 github.com/getkin/kin-openapi v0.76.0 github.com/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index bfb441f..e88ea54 100644 --- a/go.sum +++ b/go.sum @@ -36,8 +36,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/Axway/agent-sdk v1.1.37 h1:AJOoe9OrSBhAKo+Pb4aSnD9Arveg3EXFIIH23RKYPF8= -github.com/Axway/agent-sdk v1.1.37/go.mod h1:mlBFz3iU3OfesHNxTqa/uOYOoSKR4lE1YnU8k0rgx2k= +github.com/Axway/agent-sdk v1.1.42-0.20221118150152-f2a1d8f05a9d h1:b2jMNPN739h/PAwS6z6MV14esHSL2py/8sD0Td0Ixqs= +github.com/Axway/agent-sdk v1.1.42-0.20221118150152-f2a1d8f05a9d/go.mod h1:Ktgg4H7Y8FigvURTmHNhDdPFJgsITJ5XzB9++sMiOqw= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-autorest v12.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= github.com/Azure/go-autorest/autorest v0.11.12/go.mod h1:eipySxLmqSyC5s5k1CLupqet0PSENBEDP93LQ9a8QYw= diff --git a/pkg/anypoint/client.go b/pkg/anypoint/client.go index 4adaef7..a1b3a59 100644 --- a/pkg/anypoint/client.go +++ b/pkg/anypoint/client.go @@ -52,6 +52,7 @@ type AnalyticsClient interface { GetAnalyticsWindow(string, string) ([]AnalyticsEvent, error) OnConfigChange(mulesoftConfig *config.MulesoftConfig) GetClientApplication(appId string) (*Application, error) + GetAPI(id string) (*API, error) } type AuthClient interface { diff --git a/pkg/anypoint/types.go b/pkg/anypoint/types.go index bb0ae57..73e6dc6 100644 --- a/pkg/anypoint/types.go +++ b/pkg/anypoint/types.go @@ -227,6 +227,7 @@ type AnalyticsEvent struct { UserAgentVersion string `json:"User Agent Version"` Verb string `json:"Verb"` ViolatedPolicyName string `json:"Violated Policy Name"` + AssetVersion string `json:"AssetVersion"` } type Application struct { diff --git a/pkg/traceability/agent_test.go b/pkg/traceability/agent_test.go index 7dcdc5e..a5f8f16 100644 --- a/pkg/traceability/agent_test.go +++ b/pkg/traceability/agent_test.go @@ -99,6 +99,10 @@ func (m mockAnalyticsClient) GetClientApplication(string) (*anypoint.Application func (m mockAnalyticsClient) OnConfigChange(_ *config.MulesoftConfig) { } +func (m mockAnalyticsClient) GetAPI(_ string) (*anypoint.API, error) { + return nil, nil +} + type mockProcessor struct { channel chan bool } diff --git a/pkg/traceability/eventmapper.go b/pkg/traceability/eventmapper.go index 7fe7595..bf361b7 100644 --- a/pkg/traceability/eventmapper.go +++ b/pkg/traceability/eventmapper.go @@ -130,12 +130,11 @@ func (em *EventMapper) createSummaryEvent( uri := event.ResourcePath // must be the same as the the 'externalAPIID' attribute set on the APIService. - apiVersionID := event.APIVersionID - + // apiVersionID := event.APIVersionID builder := transaction.NewTransactionSummaryBuilder(). SetDuration(event.ResponseTime). SetEntryPoint("http", method, uri, host). - SetProxy(transutil.FormatProxyID(apiVersionID), name, 1). + SetProxyWithStage(transutil.FormatProxyID(event.APIID), name, event.AssetVersion, 1). SetStatus(getTransactionSummaryStatus(statusCode), strconv.Itoa(statusCode)). SetTeam(teamID). SetTransactionID(txID). diff --git a/pkg/traceability/eventmapper_test.go b/pkg/traceability/eventmapper_test.go index 9c959ad..22e9165 100644 --- a/pkg/traceability/eventmapper_test.go +++ b/pkg/traceability/eventmapper_test.go @@ -5,9 +5,6 @@ import ( "testing" "time" - "github.com/Axway/agent-sdk/pkg/util" - "github.com/Axway/agents-mulesoft/pkg/common" - "github.com/Axway/agents-mulesoft/pkg/discovery" "github.com/Axway/agent-sdk/pkg/transaction" @@ -187,7 +184,7 @@ func Test_APIServiceNameAndTransactionProxyNameAreEqual(t *testing.T) { transactionProxyID := le.TransactionSummary.Proxy.ID assert.Contains(t, transactionProxyName, apiServiceName) - assert.True(t, strings.Contains(transactionProxyID, util.ToString(body.ServiceAgentDetails[common.AttrAPIID]))) + assert.True(t, strings.Contains(transactionProxyID, event.APIID)) assert.Equal(t, event.ApplicationName, le.TransactionSummary.Application.Name) assert.Equal(t, transutil.FormatApplicationID(event.Application), le.TransactionSummary.Application.ID) } diff --git a/pkg/traceability/eventprocessor_test.go b/pkg/traceability/eventprocessor_test.go index ddea1fb..8765395 100644 --- a/pkg/traceability/eventprocessor_test.go +++ b/pkg/traceability/eventprocessor_test.go @@ -58,7 +58,7 @@ func TestEventProcessor_ProcessRaw(t *testing.T) { assert.Equal(t, "200", summaryEvent.TransactionSummary.StatusDetail) assert.Equal(t, 60, summaryEvent.TransactionSummary.Duration) assert.Equal(t, TeamID, summaryEvent.TransactionSummary.Team.ID) - assert.Equal(t, transutil.FormatProxyID(event.APIVersionID), summaryEvent.TransactionSummary.Proxy.ID) + assert.Equal(t, transutil.FormatProxyID(event.APIID), summaryEvent.TransactionSummary.Proxy.ID) assert.Equal(t, 1, summaryEvent.TransactionSummary.Proxy.Revision) assert.Equal(t, FormatAPIName(event.APIName, event.APIVersionName), summaryEvent.TransactionSummary.Proxy.Name) assert.Nil(t, summaryEvent.TransactionSummary.Runtime) diff --git a/pkg/traceability/muleemitter.go b/pkg/traceability/muleemitter.go index 492ba9b..0be79c4 100644 --- a/pkg/traceability/muleemitter.go +++ b/pkg/traceability/muleemitter.go @@ -82,6 +82,10 @@ func (me *MuleEventEmitter) Start() error { logrus.WithFields(logrus.Fields{"strStartTime": strStartTime}).Warn("Unable to Parse Last Time") } for _, event := range events { + api, _ := me.client.GetAPI(event.APIVersionID) + if api != nil { + event.AssetVersion = api.AssetVersion + } // Results are not sorted. We want the most recent time to bubble up if event.Timestamp.After(lastTime) { lastTime = event.Timestamp