Skip to content

Commit

Permalink
add event id to metric events (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollins-axway authored Jan 26, 2024
1 parent 29a36a6 commit ff094a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions pkg/transaction/metric/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type APIMetric struct {
Count int64 `json:"count"`
Response ResponseMetrics `json:"response"`
Observation ObservationDetails `json:"observation"`
EventID string `json:"eventID"`
StartTime time.Time `json:"-"`
}

Expand All @@ -74,6 +75,11 @@ func (a *APIMetric) GetType() string {
return "APIMetric"
}

// GetType - Returns APIMetric
func (a *APIMetric) GetEventID() string {
return a.EventID
}

// cachedMetric - struct to hold metric specific that gets cached and used for agent recovery
type cachedMetric struct {
Subscription models.Subscription `json:"subscription,omitempty"`
Expand Down Expand Up @@ -104,6 +110,7 @@ type V4Session struct {
type V4Data interface {
GetStartTime() time.Time
GetType() string
GetEventID() string
}

// V4Event - represents V7 event
Expand Down
11 changes: 7 additions & 4 deletions pkg/transaction/metric/metricscollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ func (c *collector) AddMetricDetail(metricDetail Detail) {

// AddAPIMetric - add api metric for API transaction
func (c *collector) AddAPIMetric(metric *APIMetric) {
if metric.EventID == "" {
metric.EventID = uuid.NewString()
}
metric.Status = c.getStatusText(metric.StatusCode)

v4Event := c.createV4Event(metric.Observation.Start, metric)
Expand Down Expand Up @@ -354,6 +357,7 @@ func (c *collector) updateMetric(detail Detail) *APIMetric {
StatusCode: statusCode,
Status: c.getStatusText(statusCode),
StartTime: now(),
EventID: uuid.NewString(),
}
}
histogram.Update(detail.Duration)
Expand Down Expand Up @@ -702,7 +706,7 @@ func (c *collector) processMetric(metricName string, metric interface{}) {
if statusMap, ok := apiMap[apiID]; ok {
if statusDetail, ok := statusMap[statusCode]; ok {
statusMetric := (metric.(metrics.Histogram))
c.settMetricsFromHistogram(statusDetail, statusMetric)
c.setMetricsFromHistogram(statusDetail, statusMetric)
c.generateMetricEvent(statusMetric, statusDetail, appID)
}
}
Expand All @@ -711,7 +715,7 @@ func (c *collector) processMetric(metricName string, metric interface{}) {
}
}

func (c *collector) settMetricsFromHistogram(metrics *APIMetric, histogram metrics.Histogram) {
func (c *collector) setMetricsFromHistogram(metrics *APIMetric, histogram metrics.Histogram) {
metrics.Count = histogram.Count()
metrics.Response.Max = histogram.Max()
metrics.Response.Min = histogram.Min()
Expand All @@ -730,9 +734,8 @@ func (c *collector) generateMetricEvent(histogram metrics.Histogram, metric *API
}

func (c *collector) createV4Event(startTime int64, v4data V4Data) V4Event {
eventID, _ := uuid.NewRandom()
return V4Event{
ID: eventID.String(),
ID: v4data.GetEventID(),
Timestamp: startTime,
Event: metricEvent,
App: c.orgGUID,
Expand Down

0 comments on commit ff094a4

Please sign in to comment.