Skip to content

Commit

Permalink
api service id lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollins-axway committed Oct 28, 2024
1 parent 86c7e98 commit 7147226
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkg/transaction/metric/cachestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (c *cacheStorage) loadMetrics(storageCache cache.Cache) {
apiDetails.Name = cm.API.Name
}
appDetails := models.AppDetails{}
if cm.API != nil {
if cm.App != nil {
appDetails.ID = cm.App.ID
appDetails.ConsumerOrgID = cm.App.ConsumerOrgID
}
Expand Down
41 changes: 23 additions & 18 deletions pkg/transaction/metric/metricscollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,14 @@ func (c *collector) AddMetricDetail(metricDetail Detail) {
c.AddMetric(metricDetail.APIDetails, metricDetail.StatusCode, metricDetail.Duration, metricDetail.Bytes, metricDetail.APIDetails.Name)
c.createOrUpdateHistogram(metricDetail)
// TODO remove this after testing
// c.AddCustomMetricDetail(CustomMetricDetail{
// APIDetails: metricDetail.APIDetails,
// AppDetails: metricDetail.AppDetails,
// UnitDetails: models.Unit{
// Name: "x-custom-token",
// },
// Count: 30,
// })
c.AddCustomMetricDetail(CustomMetricDetail{
APIDetails: metricDetail.APIDetails,
AppDetails: metricDetail.AppDetails,
UnitDetails: models.Unit{
Name: "x-ai-tokens",
},
Count: 30,
})
}

// AddAPIMetricDetail - add metric details for several response codes and transactions
Expand Down Expand Up @@ -610,9 +610,9 @@ func (c *collector) createAPIDetail(api models.APIDetails) *models.APIResourceRe
},
Name: api.Name,
}
svc, err := agent.GetAPICache().GetBySecondaryKey(strings.TrimPrefix(api.ID, transutil.SummaryEventProxyIDPrefix))
if err == nil {
ref.APIServiceID = svc.(v1.ResourceInstance).Metadata.ID
svc := agent.GetCacheManager().GetAPIServiceWithAPIID(strings.TrimPrefix(api.ID, transutil.SummaryEventProxyIDPrefix))
if svc != nil {
ref.APIServiceID = svc.Metadata.ID
}
return ref
}
Expand Down Expand Up @@ -681,28 +681,33 @@ func (c *collector) getQuota(accessRequest *management.AccessRequest, unitName s
if unitName == "" && accessRequest.Spec.Quota != nil {
// get transactions quota
for _, r := range accessRequest.References {
rMap := r.(map[string]string)
if rMap["kind"] != catalog.QuotaGVK().Kind {
rMap := r.(map[string]interface{})
if rMap["kind"].(string) != catalog.QuotaGVK().Kind {
continue
}
if _, ok := rMap["unit"]; !ok {
// no unit is transactions
quotaName = strings.Split(rMap["name"], "/")[2]
quotaName = strings.Split(rMap["name"].(string), "/")[2]
break
}
}
} else {
// get custom unit quota
for _, r := range accessRequest.References {
rMap := r.(map[string]string)
if rMap["kind"] != catalog.QuotaGVK().Kind {
rMap := r.(map[string]interface{})
if rMap["kind"].(string) != catalog.QuotaGVK().Kind {
continue
}
if unit, ok := rMap["unit"]; ok && unitName == unit {
if unit, ok := rMap["unit"]; ok && unitName == unit.(string) {
// no unit is transactions
quotaName = strings.Split(rMap["name"], "/")[2]
quotaName = strings.Split(rMap["name"].(string), "/")[2]
break
}
}
}
if quotaName == "" {
return nil
}

quotaRef := accessRequest.GetReferenceByNameAndGVK(quotaName, catalog.QuotaGVK())
if quotaRef.ID == "" {
Expand Down
7 changes: 3 additions & 4 deletions pkg/transaction/metric/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"strings"

"github.com/Axway/agent-sdk/pkg/agent"
v1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1"
"github.com/Axway/agent-sdk/pkg/transaction/models"
transutil "github.com/Axway/agent-sdk/pkg/transaction/util"
)
Expand Down Expand Up @@ -65,9 +64,9 @@ func centralMetricFromAPIMetric(in *APIMetric) *centralMetric {
},
Name: in.API.Name,
}
svc, err := agent.GetAPICache().GetBySecondaryKey(strings.TrimPrefix(in.API.ID, transutil.SummaryEventProxyIDPrefix))
if err == nil {
out.API.APIServiceID = svc.(v1.ResourceInstance).Metadata.ID
svc := agent.GetCacheManager().GetAPIServiceWithAPIID(strings.TrimPrefix(in.API.ID, transutil.SummaryEventProxyIDPrefix))
if svc != nil {
out.API.APIServiceID = svc.Metadata.ID
}
}

Expand Down

0 comments on commit 7147226

Please sign in to comment.