Skip to content

Commit 29e9450

Browse files
javrudskyHarness
authored andcommitted
feat: [fme-8233]: Added List CCM Recomendations, List CCM Recommendations by resource type and Get CCM Recommendations Stats (#81)
* [fme-8233] Applying review changes * [fme-8233] - Merge with master * [fme-8233] Improving description * [fme-8233] Added List CCM Recomendations, List CCM Recommendations by resource type and Get CCM Recommendations Stats * [fme-7210] Fixing type issues and removing unused data in ccm recommendations list * Merge branch 'fme-7210_ccm_create_persp_flow_mer' into fme-8233_ccm_recomm_list * [fme-7210] Fixing several minor issues suggested by AI * [fme-7210] Using standard view rules format * [fme-8233] Added recommendations list * [fme-7210] Removed commented code * [fme-7210] Fixing filter constant * [fme-7210] Removed default values used for testing * fme-7210] Merge with master * [fme-7210] - Merge with master * [fme-7210] - Removing debug logs * [fme-7210] - Fixing issues in Perspective Rules adapter * [fme-7210] Fixing issue in CCM Graphql Filter values filter * [fme-7210] Adding filter by values graphql functions and functions to improve create perspective flow
1 parent 8343053 commit 29e9450

File tree

7 files changed

+437
-3
lines changed

7 files changed

+437
-3
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Toolset Name: `dashboards`
9999

100100
#### Cloud Cost Management Toolset
101101

102-
Toolset Name: `cloudcostmanagement`
102+
Toolset Name: `ccm`
103103

104104
- `get_ccm_overview`: Retrieves the cost overview for a specific account.
105105
- `list_ccm_cost_categories`: List all cost categories names for a specified account.
@@ -115,8 +115,11 @@ Toolset Name: `cloudcostmanagement`
115115
- `ccm_perspective_summary_with_budget`: Query a summary of cost perspectives with budget information in Harness Cloud Cost Management, including detailed cost and budget data grouped by time.
116116
- `ccm_perspective_budget`: Query the budget information for a perspective in Harness Cloud Cost Management.
117117
- `get_ccm_metadata`: Retrieves metadata about available cloud connectors, cost data sources, default perspectives, and currency preferences in Harness Cloud Cost Management.
118-
- `ccm_perspective_recommendations`: PerspectiveRecommendations: Returns monthly cost, savings, and a list of open recommendations for a perspective in Harness Cloud Cost Management.
118+
- `ccm_perspective_recommendations`: Returns monthly cost, savings, and a list of open recommendations for a perspective in Harness Cloud Cost Management.
119119
- `ccm_perspective_filter_values`: Returns available filter values for a cost perspective, enabling dynamic discovery of valid options for advanced queries in Harness Cloud Cost Management.
120+
- `list_ccm_recommendations`: Returns a filterable list of cost-optimization recommendations in Harness Cloud Cost Management.
121+
- `list_ccm_recommendations_by_resource_type`: Returns a aggregated statistics of cloud cost optimization recommendations grouped by resource type within a given account in Harness Cloud Cost Management.
122+
- `get_ccm_recommendations_stats`: Returns overall statistics for cloud cost optimization recommendations within a given account in Harness Cloud Cost Management.
120123
- `get_ccm_commitment_coverage`: Get commitment coverage information for an account in Harness Cloud Cost Management
121124
- `get_ccm_commitment_savings`: Get commitment savings information for an account in Harness Cloud Cost Management
122125

client/ccmrecommendations.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"github.com/harness/harness-mcp/client/dto"
7+
)
8+
const (
9+
ccmRecommendationsListPath = ccmBasePath + "/recommendation/overview/list?accountIdentifier=%s"
10+
ccmRecommendationsByResourceTypeListPath = ccmBasePath + "/recommendation/overview/resource-type/stats?accountIdentifier=%s"
11+
ccmRecommendationsStatsPath = ccmBasePath + "/recommendation/overview/stats?accountIdentifier=%s"
12+
)
13+
14+
15+
func (r *CloudCostManagementService) ListRecommendations(ctx context.Context, scope dto.Scope, accountId string, options map[string]any) (*map[string]any, error) {
16+
17+
return r.getRecommendations(ctx, scope, accountId, options, ccmRecommendationsListPath)
18+
}
19+
20+
func (r *CloudCostManagementService) ListRecommendationsByResourceType(ctx context.Context, scope dto.Scope, accountId string, options map[string]any) (*map[string]any, error) {
21+
22+
return r.getRecommendations(ctx, scope, accountId, options, ccmRecommendationsByResourceTypeListPath)
23+
}
24+
25+
func (r *CloudCostManagementService) GetRecommendationsStats(ctx context.Context, scope dto.Scope, accountId string, options map[string]any) (*map[string]any, error) {
26+
27+
return r.getRecommendations(ctx, scope, accountId, options, ccmRecommendationsStatsPath)
28+
}
29+
30+
func (r *CloudCostManagementService) getRecommendations(
31+
ctx context.Context,
32+
scope dto.Scope,
33+
accountId string,
34+
options map[string]any,
35+
url string,
36+
) (*map[string]any, error) {
37+
38+
path := fmt.Sprintf(url, accountId)
39+
params := make(map[string]string)
40+
addScope(scope, params)
41+
42+
items := new(map[string]any)
43+
44+
err := r.Client.Post(ctx, path, params, options, &items)
45+
if err != nil {
46+
return nil, fmt.Errorf("Failed to list cloud cost management recommendations: %w", err)
47+
}
48+
49+
return items, nil
50+
}

client/dto/ccmcosts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
type CCMBaseResponse struct {
2626
Status string `json:"state,omitempty"`
2727
Message string `json:"message,omitempty"`
28+
MetaData map[string]any `json:"metaData,omitempty"`
2829
CorrelationID string `json:"correlation_id,omitempty"`
2930
Error []CCMError `json:"error,omitempty"`
3031
}

pkg/ccmcommons/ccmconstants.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,16 @@ var ConditionFieldDescriptions = []map[string]string{
227227
"description": "Use this field to create a view filter rule to filter by Labels",
228228
},
229229
}
230+
231+
var ListRecommendationsDescription = `
232+
Lists recommendation items with metadata such as resource identifiers, potential savings, current vs. recommended size, severity/status, and recommendation type.
233+
Supports rich filtering (for example by cloud account, Kubernetes attributes, resource type) so teams only fetch what’s relevant to them or their Perspective/RBAC scope in Harness Cloud Cost Management.
234+
`
235+
236+
var ListRecommendationsByResourceTypeDescription = `
237+
Retrieves aggregated statistics of cloud cost optimization recommendations grouped by resource type within a given account. This includes counts and potential savings information for each resource type, helping to understand which resource categories offer the most cost optimization opportunities. Ideal for monitoring and prioritizing cloud resource cost-saving actions.
238+
`
239+
240+
var GetRecommendationsStatsDescription = `
241+
Retrieves overall statistics for cloud cost optimization recommendations within a given account. The response provides aggregated metrics such as the total number of recommendations, total estimated cost savings, and the count of open and applied recommendations. This helps track the overall state and impact of cost optimization efforts across all resources.
242+
`

pkg/ccmcommons/ccmhelpers.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ func GetSupportedOperators() []string {
6565
}
6666
}
6767

68-
6968
// AdaptViewRulesMap converts an array of rule maps (each with conditions) to []*CCMViewRule.
7069
// Uses OutputFields and OutputKeyValueFields for field metadata.
7170
func AdaptViewRulesMap(input []any) ([]dto.CCMViewRule, error) {

pkg/harness/tools.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,9 @@ func RegisterCloudCostManagement(config *config.Config, tsg *toolsets.ToolsetGro
584584
toolsets.NewServerTool(tools.CcmMetadataTool(config, ccmClient)),
585585
toolsets.NewServerTool(tools.CcmPerspectiveRecommendationsTool(config, ccmClient)),
586586
toolsets.NewServerTool(tools.CcmPerspectiveFilterValuesTool(config, ccmClient)),
587+
toolsets.NewServerTool(tools.ListCcmRecommendationsTool(config, ccmClient)),
588+
toolsets.NewServerTool(tools.ListCcmRecommendationsByResourceTypeTool(config, ccmClient)),
589+
toolsets.NewServerTool(tools.GetCcmRecommendationsStatsTool(config, ccmClient)),
587590
toolsets.NewServerTool(tools.FetchCommitmentCoverageTool(config, ccmClient)),
588591
toolsets.NewServerTool(tools.FetchCommitmentSavingsTool(config, ccmClient)),
589592
)

0 commit comments

Comments
 (0)