Skip to content

Commit

Permalink
use slices package to check object's presence
Browse files Browse the repository at this point in the history
Signed-off-by: adarsh0728 <[email protected]>
  • Loading branch information
adarsh0728 committed Feb 3, 2025
1 parent 18e8273 commit d9a1550
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions server/apis/v1/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"math"
"net/http"
"reflect"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -1297,16 +1298,6 @@ func (h *handler) GetMetricData(c *gin.Context) {
c.JSON(http.StatusOK, NewNumaflowAPIResponse(nil, result))
}

// Helper function to check if an object is in the list
func isObjectInList(objects []string, object string) bool {
for _, o := range objects {
if o == object {
return true
}
}
return false
}

// DiscoverMetrics is used to provide a metrics list for each
// dimension along with necessary params and filters for a given object
func (h *handler) DiscoverMetrics(c *gin.Context) {
Expand All @@ -1323,7 +1314,7 @@ func (h *handler) DiscoverMetrics(c *gin.Context) {
var discoveredMetrics MetricsDiscoveryResponse

for _, pattern := range configData.Patterns {
if isObjectInList(pattern.Objects, object) {
if slices.Contains(pattern.Objects, object) {
for _, metric := range pattern.Metrics {
var requiredFilters []Filter
// Populate the required filters
Expand Down

0 comments on commit d9a1550

Please sign in to comment.