Skip to content

Commit

Permalink
APIGOV-000000 - Updates to setup consumer details in metric event (#117)
Browse files Browse the repository at this point in the history
* APIGOV-000000 - Updates to setup consumer subscription details in metric event

* APIGOV-000000 - unit test fix
  • Loading branch information
vivekschauhan authored Nov 23, 2022
1 parent e2dcd4f commit 4ba70d5
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions pkg/anypoint/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/anypoint/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/traceability/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/traceability/eventmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
5 changes: 1 addition & 4 deletions pkg/traceability/eventmapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/traceability/eventprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pkg/traceability/muleemitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4ba70d5

Please sign in to comment.