@@ -346,8 +346,13 @@ func (o *OCIDatasource) GetNamespaceWithMetricNames(
346346 // fetching from cache, if present
347347 cacheKey := strings .Join ([]string {tenancyOCID , compartmentOCID , region , "nss" }, "-" )
348348 if cachedMetricNamesWithNamespaces , found := o .cache .Get (cacheKey ); found {
349- backend .Logger .Warn ("client" , "GetNamespaceWithMetricNames" , "getting the data from cache" )
350- return cachedMetricNamesWithNamespaces .([]models.OCIMetricNamesWithNamespace )
349+ // This check avoids the type assertion and potential panic
350+ if _ , ok := cachedMetricNamesWithNamespaces .([]models.OCIMetricNamesWithNamespace ); ok {
351+ backend .Logger .Warn ("client" , "GetNamespaceWithMetricNames" , "getting the data from cache" )
352+ return cachedMetricNamesWithNamespaces .([]models.OCIMetricNamesWithNamespace )
353+ } else {
354+ backend .Logger .Warn ("client.utils" , "GetNamespaceWithMetricNames" , "cannot use cached data -> " + cacheKey )
355+ }
351356 }
352357
353358 // calling the api if not present in cache
@@ -499,17 +504,18 @@ func (o *OCIDatasource) GetMetricDataPoints(ctx context.Context, requestParams m
499504 // fetching the resource labels
500505 var rl map [string ]map [string ]string
501506
502- cachedResourceLabels := o .fetchFromCache (
503- ctx ,
504- requestParams .TenancyOCID ,
505- requestParams .CompartmentOCID ,
506- requestParams .CompartmentName ,
507- sRegion ,
508- requestParams .Namespace ,
509- "resource_labels" ,
510- )
507+ // Tags will be used in future releases
508+ // cachedResourceLabels := o.fetchFromCache(
509+ // ctx,
510+ // requestParams.TenancyOCID,
511+ // requestParams.CompartmentOCID,
512+ // requestParams.CompartmentName,
513+ // sRegion,
514+ // requestParams.Namespace,
515+ // "resource_labels",
516+ // )
511517
512- rl = cachedResourceLabels .(map [string ]map [string ]string )
518+ // rl = cachedResourceLabels.(map[string]map[string]string)
513519
514520 // storing the data to calculate later
515521 allRegionsMetricsDataPoint .Store (sRegion , metricDataBank {
@@ -536,27 +542,28 @@ func (o *OCIDatasource) GetMetricDataPoints(ctx context.Context, requestParams m
536542
537543 backend .Logger .Info ("client" , "GetMetricDataPoints" , "Metric datapoints got for region-" + regionInUse )
538544
545+ // Tags will be used in future releases
539546 // get the selected tags
540- if len (selectedTags ) != 0 {
541- cachedResourceNamesPerTag := o .fetchFromCache (
542- ctx ,
543- requestParams .TenancyOCID ,
544- requestParams .CompartmentOCID ,
545- requestParams .CompartmentName ,
546- regionInUse ,
547- requestParams .Namespace ,
548- constants .CACHE_KEY_RESOURCE_IDS_PER_TAG ,
549- )
550-
551- resourceIDsPerTag = cachedResourceNamesPerTag .(map [string ]map [string ]struct {})
552- }
547+ // if len(selectedTags) != 0 {
548+ // cachedResourceNamesPerTag := o.fetchFromCache(
549+ // ctx,
550+ // requestParams.TenancyOCID,
551+ // requestParams.CompartmentOCID,
552+ // requestParams.CompartmentName,
553+ // regionInUse,
554+ // requestParams.Namespace,
555+ // constants.CACHE_KEY_RESOURCE_IDS_PER_TAG,
556+ // )
557+
558+ // resourceIDsPerTag = cachedResourceNamesPerTag.(map[string]map[string]struct{})
559+ // }
553560
554561 metricData := value .(metricDataBank )
555562
556563 for _ , metricDataItem := range metricData .dataPoints {
557564 found := false
558565
559- uniqueDataID , resourceDisplayName , extraUniqueID , rIDPresent := getUniqueIdsForLabels (requestParams .Namespace , metricDataItem .Dimensions , requestParams .QueryText )
566+ uniqueDataID , dimensionKey , resourceDisplayName , extraUniqueID , rIDPresent := getUniqueIdsForLabels (requestParams .Namespace , metricDataItem .Dimensions , requestParams .QueryText )
560567
561568 if rIDPresent {
562569 for _ , selectedTag := range selectedTags {
@@ -610,10 +617,6 @@ func (o *OCIDatasource) GetMetricDataPoints(ctx context.Context, requestParams m
610617 // for base tenancy
611618 splits := strings .Split (tenancyOCID , "/" )
612619 tenancyName := splits [0 ]
613- // tenancyName := oc.tenanciesMap[requestParams.TenancyOCID]
614- // if tenancyName == constants.DEFAULT_PROFILE {
615- // tenancyName = oc.baseTenancyName
616- // }
617620
618621 // to get the resource labels
619622 labelKey := uniqueDataID + extraUniqueID
@@ -640,6 +643,7 @@ func (o *OCIDatasource) GetMetricDataPoints(ctx context.Context, requestParams m
640643 MetricName : * metricDataItem .Name ,
641644 ResourceName : resourceDisplayName ,
642645 UniqueDataID : uniqueDataID ,
646+ DimensionKey : dimensionKey ,
643647 Labels : labelsToAdd ,
644648 }
645649 }
@@ -657,10 +661,6 @@ func (o *OCIDatasource) GetMetricDataPoints(ctx context.Context, requestParams m
657661 continue
658662 }
659663
660- // for i := 0; i < resourcesFetched-len(dvs); i++ {
661- // dataValuesWithTime[t] = append(dataValuesWithTime[t], 0.0)
662- // }
663-
664664 lastValue := dataValuesWithTime [t ][len (dataValuesWithTime [t ])- 1 ]
665665 for i := 0 ; i < resourcesFetched - len (dvs ); i ++ {
666666 dataValuesWithTime [t ] = append (dataValuesWithTime [t ], lastValue )
@@ -702,7 +702,6 @@ func (o *OCIDatasource) fetchFromCache(ctx context.Context, tenancyOCID string,
702702 backend .Logger .Error ("client" , "fetchFromCache" , "fetching from cache" )
703703
704704 labelCacheKey := strings .Join ([]string {tenancyOCID , compartmentOCID , region , namespace , suffix }, "-" )
705-
706705 if _ , found := o .cache .Get (labelCacheKey ); ! found {
707706 o .GetTags (ctx , tenancyOCID , compartmentOCID , compartmentName , region , namespace )
708707 }
@@ -1010,27 +1009,9 @@ func (o *OCIDatasource) GetResourceGroups(
10101009 )
10111010 }
10121011
1013- reqDetails := monitoring.ListMetricsDetails {}
1014- reqDetails .Namespace = common .String (namespace )
1015- reqDetails .GroupBy = []string {"resourceGroup" , "name" }
1016-
1017- // retrieve metric list for template var
1018- items , err := o .getListMetrics (ctx , region , compartmentOCID , reqDetails , takey )
1019- if err != nil {
1020- backend .Logger .Error ("client" , "GetResourceGroups" , "Error retrieving metric list under compartment '" + compartmentOCID + "'" )
1021- return nil
1022- }
1023-
10241012 if len (metricResourceGroups ) == 0 {
1025- var arca []string
1026- for _ , item := range items {
1027- alfa := * (item .Name )
1028- arca = append (arca , alfa )
1029- }
1030- metricResourceGroupsList = append (metricResourceGroupsList , models.OCIMetricNamesWithResourceGroup {
1031- ResourceGroup : constants .DEFAULT_RESOURCE_GROUP ,
1032- MetricNames : arca ,
1033- })
1013+ backend .Logger .Error ("client" , "GetResourceGroups" , "resource groups under compartment '" + compartmentOCID + "' for namespace '" + namespace + "' is empty" )
1014+ return nil
10341015 } else {
10351016 for k , v := range metricResourceGroups {
10361017 metricResourceGroupsList = append (metricResourceGroupsList , models.OCIMetricNamesWithResourceGroup {
@@ -1078,8 +1059,13 @@ func (o *OCIDatasource) GetDimensions(
10781059 // fetching from cache, if present
10791060 cacheKey := strings .Join ([]string {tenancyOCID , compartmentOCID , region , namespace , metricName , cacheSubKey }, "-" )
10801061 if cachedDimensions , found := o .cache .Get (cacheKey ); found {
1081- backend .Logger .Warn ("client" , "GetDimensions" , "getting the data from cache" )
1082- return cachedDimensions .([]models.OCIMetricDimensions )
1062+ // This check avoids the type assertion and potential panic
1063+ if _ , ok := cachedDimensions .([]models.OCIMetricDimensions ); ok {
1064+ backend .Logger .Warn ("client" , "GetDimensions" , "getting the data from cache" )
1065+ return cachedDimensions .([]models.OCIMetricDimensions )
1066+ } else {
1067+ backend .Logger .Warn ("client.utils" , "GetDimensions" , "cannot use cached data -> " + cacheKey )
1068+ }
10831069 }
10841070
10851071 var metricDimensions map [string ][]string
@@ -1143,32 +1129,3 @@ func (o *OCIDatasource) GetDimensions(
11431129
11441130 return metricDimensionsList
11451131}
1146-
1147- func (o * OCIDatasource ) getListMetrics (ctx context.Context , region , compartment string , metricDetails monitoring.ListMetricsDetails , takey string ) ([]monitoring.Metric , error ) {
1148- var items []monitoring.Metric
1149- var page * string
1150-
1151- pageNumber := 0
1152- for {
1153- reg := common .StringToRegion (region )
1154- o .tenancyAccess [takey ].monitoringClient .SetRegion (string (reg ))
1155- res , err := o .tenancyAccess [takey ].monitoringClient .ListMetrics (ctx , monitoring.ListMetricsRequest {
1156- CompartmentId : common .String (compartment ),
1157- ListMetricsDetails : metricDetails ,
1158- Page : page ,
1159- })
1160-
1161- if err != nil {
1162- return nil , errors .Wrap (err , "list metrics failed" )
1163- }
1164- items = append (items , res .Items ... )
1165- // Only 0 - n-1 pages are to be fetched, as indexing starts from 0 (for page number
1166- if res .OpcNextPage == nil || pageNumber >= MaxPagesToFetch {
1167- break
1168- }
1169-
1170- page = res .OpcNextPage
1171- pageNumber ++
1172- }
1173- return items , nil
1174- }
0 commit comments