Skip to content

Commit

Permalink
APIGOV-28984 Add CustomUnit client code - Init checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
Deepak Kasu committed Oct 31, 2024
1 parent e49886c commit 17370ec
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 109 deletions.
8 changes: 4 additions & 4 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ func InitializeWithAgentFeatures(centralCfg config.CentralConfig, agentFeaturesC
metricServicesConfigs := agentFeaturesCfg.GetMetricServicesConfigs()
// iterate over each metric service config
for _, config := range metricServicesConfigs {
ctx := context.WithValue(context.Background(), ctxLogger, logger)
ctx, ctxCancel := context.WithCancel(context.Background())
// Initialize custom units client
c := customunit.NewCustomUnitMetricReportingClient(ctx, config.URL)

c.MetricReporting()
factory := customunit.NewCustomMetricReportingClientFactory(config.URL, agent.cacheManager)
client, _ := factory(ctx, ctxCancel)

client.MetricReporting()
}
if !agent.isInitialized {
err = handleInitialization()
Expand Down
15 changes: 14 additions & 1 deletion pkg/agent/handler/accessrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,20 @@ func (h *accessRequestHandler) onPending(ctx context.Context, ar *management.Acc
h.onError(ctx, ar, err)
return ar
}
errMessage := customunit.QuotaEnforcementInfo(metricServicesConfigs, ctx, quotaInfo)
errMessage := ""
for _, config := range metricServicesConfigs {
if config.MetricServiceEnabled() {
factory := customunit.NewQuotaEnforcementClientFactory(config.URL, quotaInfo)
client, _ := factory(ctx)
response, err := client.QuotaEnforcementInfo()
if err == nil {
// if error from QE and reject on fail, we return the error back to the central
if response.Error != "" && config.RejectOnFailEnabled() {
errMessage = errMessage + fmt.Sprintf("TODO: message: %s", err.Error())
}
}
}
}

if errMessage != "" {
status = prov.NewRequestStatusBuilder().
Expand Down
Loading

0 comments on commit 17370ec

Please sign in to comment.