Skip to content

Commit

Permalink
clear logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tharsanan1 committed Sep 17, 2024
1 parent cb55f8f commit af63478
Show file tree
Hide file tree
Showing 16 changed files with 18 additions and 93 deletions.
1 change: 0 additions & 1 deletion adapter/internal/discovery/xds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ func PopulateInternalMaps(adapterInternalAPI *model.AdapterInternalAPI, labels,
}

err := UpdateOrgAPIMap(vHosts, labels, listenerName, sectionName, adapterInternalAPI)
logger.LoggerAPI.Infof("vhosts::: %+v", vHosts)
for vhost, _ := range vHosts {
logger.LoggerAPI.Infof("vhost::: %+v, %+v, %+v", vhost, adapterInternalAPI.AIProvider.Enabled, adapterInternalAPI.GetSubscriptionValidation())
if adapterInternalAPI.AIProvider.Enabled && adapterInternalAPI.GetSubscriptionValidation() {
Expand Down
1 change: 0 additions & 1 deletion adapter/internal/oasparser/envoyconf/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ func CreateVirtualHosts(vhostToRouteArrayMap map[string][]*routev3.Route, custom
}

for vhost, routes := range vhostToRouteArrayMap {
loggers.LoggerAPI.Infof("vhosttosubairl: %+v, \n vhoststosubrl: %+v", vhostToSubscriptionAIRL, vhostToSubscriptionRL)
if flag, exists := vhostToSubscriptionAIRL[vhost]; exists && flag {
rateLimits = append(rateLimits, generateSubscriptionBasedAIRatelimits()...)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,6 @@ func createRoutes(params *routeCreateParams) (routes []*routev3.Route, err error
}
routeConfig := resource.GetEndpoints().Config
metaData := &corev3.Metadata{}
logger.LoggerAPI.Infof("Is backend based rl enabled: %+v", resource.GetEnableBackendBasedAIRatelimit())
if params.isAiAPI {
metaData = &corev3.Metadata{
FilterMetadata: map[string]*structpb.Struct{
Expand Down
4 changes: 2 additions & 2 deletions adapter/internal/oasparser/model/adapter_internal_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,11 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoHTTPRouteCR(httpRoute *gwap
enableBackendBasedAIRatelimit := false
descriptorValue := ""
if aiRatelimitPolicy, exists := ruleIdxToAiRatelimitPolicyMapping[ruleID]; exists {
loggers.LoggerAPI.Infof("Found AI ratelimit mapping for ruleId: %d, related api: %s", ruleID, adapterInternalAPI.UUID)
loggers.LoggerAPI.Debugf("Found AI ratelimit mapping for ruleId: %d, related api: %s", ruleID, adapterInternalAPI.UUID)
enableBackendBasedAIRatelimit = true
descriptorValue = prepareAIRatelimitIdentifier(adapterInternalAPI.OrganizationID, utils.NamespacedName(aiRatelimitPolicy), &aiRatelimitPolicy.Spec)
} else {
loggers.LoggerAPI.Infof("Could not find AIratelimit for ruleId: %d, len of map: %d, related api: %s", ruleID, len(ruleIdxToAiRatelimitPolicyMapping), adapterInternalAPI.UUID)
loggers.LoggerAPI.Debugf("Could not find AIratelimit for ruleId: %d, len of map: %d, related api: %s", ruleID, len(ruleIdxToAiRatelimitPolicyMapping), adapterInternalAPI.UUID)
}

backendBasePath := ""
Expand Down
19 changes: 2 additions & 17 deletions adapter/internal/operator/controllers/dp/api_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,10 +877,10 @@ func (apiReconciler *APIReconciler) getResolvedBackendsMapping(ctx context.Conte
if err := apiReconciler.client.List(ctx, aiRLPolicyList, &k8client.ListOptions{
FieldSelector: fields.OneTermEqualSelector(aiRatelimitPolicyToBackendIndex, backendNamespacedName.String()),
}); err != nil {
loggers.LoggerAPKOperator.Infof("No associated AI ratelimit policy found for : %s", backendNamespacedName.String())
loggers.LoggerAPKOperator.Debugf("No associated AI ratelimit policy found for : %s", backendNamespacedName.String())
} else {
for _, aiRLPolicy := range aiRLPolicyList.Items {
loggers.LoggerAPKOperator.Infof("Adding mapping for ruleid: %d to aiRLPolicy: %s", id, utils.NamespacedName(&aiRLPolicy))
loggers.LoggerAPKOperator.Debugf("Adding mapping for ruleid: %d to aiRLPolicy: %s", id, utils.NamespacedName(&aiRLPolicy))
ruleIdxToAiRatelimitPolicyMapping[id] = &aiRLPolicy
}
}
Expand Down Expand Up @@ -2017,21 +2017,6 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error {
return err
}

// // AIRatelimitPolicy to Subscription indexer
// if err := mgr.GetFieldIndexer().IndexField(ctx, &dpv1alpha3.AIRateLimitPolicy{}, aiRatelimitPolicyToSubscriptionIndex,
// func(rawObj k8client.Object) []string {
// aiRatelimitPolicy := rawObj.(*dpv1alpha3.AIRateLimitPolicy)
// var subscriptions []string
// namespace := utils.GetNamespace(aiRatelimitPolicy.Spec.TargetRef.Namespace, aiRatelimitPolicy.GetNamespace())
// subscriptions = append(subscriptions, types.NamespacedName{
// Name: string(aiRatelimitPolicy.Spec.TargetRef.Name),
// Namespace: namespace,
// }.String())
// return subscriptions
// }); err != nil {
// return err
// }

// API to Subscription indexer
if err := mgr.GetFieldIndexer().IndexField(ctx, &dpv1alpha2.API{}, apiToSubscriptionIndex,
func(rawObj k8client.Object) []string {
Expand Down
6 changes: 0 additions & 6 deletions adapter/internal/operator/synchronizer/data_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,15 @@ func (ods *OperatorDataStore) processAPIState(apiNamespacedName types.Namespaced
for key, aiRl := range apiState.ProdHTTPRoute.RuleIdxToAiRatelimitPolicyMapping {
if cachedAIRl, exists := cachedAPI.ProdHTTPRoute.RuleIdxToAiRatelimitPolicyMapping[key]; exists {
if utils.NamespacedName(cachedAIRl).String() != utils.NamespacedName(aiRl).String() || cachedAIRl.Generation != aiRl.Generation {
loggers.LoggerAPI.Infof("Returning true * %s %s %d %d", utils.NamespacedName(cachedAIRl).String(), utils.NamespacedName(aiRl).String(), cachedAIRl.Generation, aiRl.Generation)
updated = true
break
}
} else {
loggers.LoggerAPI.Info("Returning true&&")
updated = true
break
}
}
if len(cachedAPI.ProdHTTPRoute.RuleIdxToAiRatelimitPolicyMapping) != len(apiState.ProdHTTPRoute.RuleIdxToAiRatelimitPolicyMapping) {
loggers.LoggerAPI.Info("Returning true ***")
updated = true
}
}
Expand Down Expand Up @@ -164,18 +161,15 @@ func (ods *OperatorDataStore) processAPIState(apiNamespacedName types.Namespaced
for key, aiRl := range apiState.SandHTTPRoute.RuleIdxToAiRatelimitPolicyMapping {
if cachedAIRl, exists := cachedAPI.SandHTTPRoute.RuleIdxToAiRatelimitPolicyMapping[key]; exists {
if utils.NamespacedName(cachedAIRl).String() != utils.NamespacedName(aiRl).String() || cachedAIRl.Generation != aiRl.Generation {
loggers.LoggerAPI.Info("Returning true")
updated = true
break
}
} else {
loggers.LoggerAPI.Info("Returning true")
updated = true
break
}
}
if len(cachedAPI.ProdHTTPRoute.RuleIdxToAiRatelimitPolicyMapping) != len(apiState.ProdHTTPRoute.RuleIdxToAiRatelimitPolicyMapping) {
loggers.LoggerAPI.Info("Returning true")
updated = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,18 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"

dpv1alpha3 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha3"
// "context"
// "fmt"
// "time"

// logger "github.com/sirupsen/logrus"
// k8error "k8s.io/apimachinery/pkg/api/errors"
// "k8s.io/apimachinery/pkg/fields"
// "k8s.io/apimachinery/pkg/runtime"
// "k8s.io/apimachinery/pkg/types"
// ctrl "sigs.k8s.io/controller-runtime"
// "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
// "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
// "sigs.k8s.io/controller-runtime/pkg/reconcile"

// k8client "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/source"
// gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

"github.com/wso2/apk/adapter/pkg/logging"
cache "github.com/wso2/apk/common-controller/internal/cache"
"github.com/wso2/apk/common-controller/internal/config"
loggers "github.com/wso2/apk/common-controller/internal/loggers"
"github.com/wso2/apk/common-controller/internal/utils"
xds "github.com/wso2/apk/common-controller/internal/xds"
// dpv1alpha1 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha1"
// dpv1alpha2 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha2"
"github.com/wso2/apk/common-go-libs/constants"
)

Expand All @@ -73,12 +55,6 @@ func NewAIRatelimitController(mgr manager.Manager, ratelimitStore *cache.Ratelim
ods: ratelimitStore,
}

// ctx := context.Background()
// if err := addIndexes(ctx, mgr); err != nil {
// loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2612, logging.BLOCKER, "Error adding indexes: %v", err))
// return err
// }

c, err := controller.New(constants.AIRatelimitController, mgr, controller.Options{Reconciler: aiRateLimitPolicyReconciler})
if err != nil {
loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2663, logging.BLOCKER,
Expand All @@ -89,20 +65,6 @@ func NewAIRatelimitController(mgr manager.Manager, ratelimitStore *cache.Ratelim
conf := config.ReadConfigs()
predicates := []predicate.Predicate{predicate.NewPredicateFuncs(utils.FilterByNamespaces(conf.CommonController.Operator.Namespaces))}

// if err := c.Watch(source.Kind(mgr.GetCache(), &dpv1alpha2.API{}),
// handler.EnqueueRequestsFromMapFunc(aiRateLimitPolicyReconciler.getRatelimitForAPI), predicates...); err != nil {
// loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2611, logging.BLOCKER,
// "Error watching API resources: %v", err))
// return err
// }

// if err := c.Watch(source.Kind(mgr.GetCache(), &gwapiv1.HTTPRoute{}),
// handler.EnqueueRequestsFromMapFunc(aiRateLimitPolicyReconciler.getRatelimitForHTTPRoute), predicates...); err != nil {
// loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2613, logging.BLOCKER,
// "Error watching HTTPRoute resources: %v", err))
// return err
// }

if err := c.Watch(source.Kind(mgr.GetCache(), &dpv1alpha3.AIRateLimitPolicy{}), &handler.EnqueueRequestForObject{}, predicates...); err != nil {
loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2639, logging.BLOCKER,
"Error watching Ratelimit resources: %v", err.Error()))
Expand Down Expand Up @@ -153,7 +115,6 @@ func (r *AIRateLimitPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Re
xds.UpdateRateLimiterPolicies(conf.CommonController.Server.Label)
}
}
loggers.LoggerAPKOperator.Infof("AIRatelimit reconcile..*****.")
return ctrl.Result{}, nil
}

Expand Down
5 changes: 0 additions & 5 deletions common-controller/internal/xds/ratelimiter_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,8 @@ func (r *rateLimitPolicyCache) AddCustomRateLimitPolicies(customRateLimitPolicy
// ProcessSubscriptionBasedAIRatelimitPolicySpecsAndUpdateCache process the specs and update the cache
func (r *rateLimitPolicyCache) ProcessSubscriptionBasedAIRatelimitPolicySpecsAndUpdateCache(subscriptionEnabledAIRatelimitPolicies map[types.NamespacedName]struct{}, aiRatelimitPolicySpecs map[types.NamespacedName]*dpv1alpha3.AIRateLimitPolicySpec) {
aiRlDescriptors := make([]*rls_config.RateLimitDescriptor, 0)
loggers.LoggerAPKOperator.Infof("222222")
for namespacedNameRl := range subscriptionEnabledAIRatelimitPolicies {
if airl, exists := aiRatelimitPolicySpecs[namespacedNameRl]; exists {
loggers.LoggerAPKOperator.Infof("----- %s %s %s", DescriptorKeyForSubscriptionBasedAIRequestTokenCount, prepareSubscriptionBasedAIRatelimitIdentifier(airl.Override.Organization, namespacedNameRl), DescriptorKeyForSubscription)
// Add descriptor for RequestTokenCount
aiRlDescriptors = append(aiRlDescriptors, &rls_config.RateLimitDescriptor{
Key: DescriptorKeyForSubscriptionBasedAIRequestTokenCount,
Expand Down Expand Up @@ -403,10 +401,7 @@ func (r *rateLimitPolicyCache) ProcessSubscriptionBasedAIRatelimitPolicySpecsAnd
// ProcessAIratelimitPolicySpecsAndUpdateCache process the specs and update the cache
func (r *rateLimitPolicyCache) ProcessAIRatelimitPolicySpecsAndUpdateCache(aiRateLimitPolicySpecs map[types.NamespacedName]*dpv1alpha3.AIRateLimitPolicySpec) {
aiRlDescriptors := make([]*rls_config.RateLimitDescriptor, 0)
loggers.LoggerAPKOperator.Infof("222222")
for namespacedName, spec := range aiRateLimitPolicySpecs {
logger.Infof("Adding : %s, %s", DescriptorKeyForAIRequestCount, prepareAIRatelimitIdentifier(spec.Override.Organization, namespacedName, spec))
logger.Infof("For airl: %s", namespacedName)
// Add descriptor for RequestTokenCount
aiRlDescriptors = append(aiRlDescriptors, &rls_config.RateLimitDescriptor{
Key: DescriptorKeyForAIRequestTokenCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ private String constructQueryParamString(boolean removeAllQueryParams, String re
* @param value
*/
private void addMetadata(Struct.Builder structBuilder, String key, String value) {
System.out.println("Key: " + key + " value: " + value);
structBuilder.putFields(key, Value.newBuilder().setStringValue(value).build());
}

Expand Down Expand Up @@ -309,6 +308,4 @@ private CheckResponse buildReadyCheckResponse(CheckResponse.Builder responseBuil
.setDeniedResponse(deniedResponsePreparer.build())
.build();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public class ExternalProcessorService extends ExternalProcessorGrpc.ExternalProc
public StreamObserver<ProcessingRequest> process(
final StreamObserver<ProcessingResponse> responseObserver) {
FilterMetadata filterMetadata = new FilterMetadata();
System.out.println("process ....");
return new StreamObserver<ProcessingRequest>() {

@Override
Expand Down Expand Up @@ -131,7 +130,6 @@ public void onNext(ProcessingRequest request) {
filterMetadata.backendBasedAIRatelimitDescriptorValue = metadata.backendBasedAIRatelimitDescriptorValue;
filterMetadata.enableBackendBasedAIRatelimit = metadata.enableBackendBasedAIRatelimit;
}
System.out.println("In the response flow metadata descirtor:" + filterMetadata.backendBasedAIRatelimitDescriptorValue);
if (request.hasResponseBody()) {
final byte[] bodyFromResponse = request.getResponseBody().getBody().toByteArray();
executorService.submit(() -> {
Expand Down Expand Up @@ -177,7 +175,6 @@ public void onNext(ProcessingRequest request) {
});
responseObserver.onCompleted();
} else {
System.out.println("Request does not have response body");
responseObserver.onCompleted();
}

Expand All @@ -186,7 +183,7 @@ public void onNext(ProcessingRequest request) {

@Override
public void onError(Throwable err) {
System.out.println("on error ...."+ err.getLocalizedMessage() + " " + err.getMessage() + " " + err.toString()+ " ****");
logger.error("Error initiated from envoy in the external processing session. Error: " + err);
}

@Override
Expand Down Expand Up @@ -277,7 +274,7 @@ private static Usage extractUsageFromHeaders(HttpHeaders headers, String complet
}
return usage;
} catch (Exception e) {
System.out.println("Error occured while getting yusage info from headers"+e);
logger.error("Error occured while getting yusage info from headers" + e);
return null;
}
}
Expand Down Expand Up @@ -342,7 +339,7 @@ private static Usage extractUsageFromBody(String body, String completionTokenPat
return usage;

} catch (Exception e) {
System.out.println(String.format("Unexpected error while extracting usage from the body: %s", body) + " \n" + e);
logger.error(String.format("Unexpected error while extracting usage from the body: %s", body) + " \n" + e);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.wso2.apk.enforcer.config.ConfigHolder;
import org.wso2.apk.enforcer.grpc.ExternalProcessorService;

import java.io.File;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.net.ssl.SSLException;

public class RatelimitClient {
private static final Logger logger = LogManager.getLogger(RatelimitClient.class);
RateLimitServiceGrpc.RateLimitServiceBlockingStub stub;

public RatelimitClient(){
File certFile = Paths.get(ConfigHolder.getInstance().getEnvVarConfig().getEnforcerPublicKeyPath()).toFile();
File keyFile = Paths.get(ConfigHolder.getInstance().getEnvVarConfig().getEnforcerPrivateKeyPath()).toFile();
Expand All @@ -30,7 +33,7 @@ public RatelimitClient(){
.keyManager(certFile, keyFile)
.build();
} catch (SSLException e) {
System.out.println("Error while generating SSL Context."+ e);
logger.error("Error while generating SSL Context."+ e);
}
String rlHost = ConfigHolder.getInstance().getEnvVarConfig().getRatelimiterHost();
int port = ConfigHolder.getInstance().getEnvVarConfig().getRatelimiterPort();
Expand Down Expand Up @@ -59,7 +62,6 @@ public void shouldRatelimit(List<KeyValueHitsAddend> configs) {
.setHitsAddend(hitsAddend)
.build();
RateLimitResponse rateLimitResponse = stub.shouldRateLimit(rateLimitRequest);
System.out.println(rateLimitResponse.getOverallCode());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ public static APIKeyValidationInfoDTO validateSubscription(String apiUuid, Strin
return infoDTO;
}



private static void validate(APIKeyValidationInfoDTO infoDTO, Application app, Subscription sub) {

// Validate subscription status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ private AuthenticationContext processAPIKey(RequestContext requestContext, Strin
.getMandateSubscriptionValidation();
if (!requestContext.getMatchedAPI().isSystemAPI() && (isGatewayLevelSubscriptionValidationEnabled || requestContext.getMatchedAPI()
.isSubscriptionValidation())) {
validationInfoDto = KeyValidator.validateSubscription(apiUuid, apiContext,
requestContext.getMatchedAPI(), payload);
// validationInfoDto = KeyValidator.validateSubscription(apiUuid, apiContext,
// requestContext.getMatchedAPI(), payload);
log.debug("Validating subscription for API Key using JWT claims against invoked API info."
+ " context: {} version: {}", apiContext, apiVersion);
validationInfoDto = getAPIKeyValidationDTO(requestContext, payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ private static Server initServer() throws SSLException {
EnforcerWorkerPool enforcerWorkerPool = new EnforcerWorkerPool(threadPoolConfig.getCoreSize(),
threadPoolConfig.getMaxSize(), threadPoolConfig.getKeepAliveTime(), threadPoolConfig.getQueueSize(),
Constants.EXTERNAL_AUTHZ_THREAD_GROUP, Constants.EXTERNAL_AUTHZ_THREAD_ID);
System.out.println("test");
return NettyServerBuilder.forPort(authServerConfig.getPort())
.keepAliveTime(authServerConfig.getKeepAliveTime(), TimeUnit.SECONDS).bossEventLoopGroup(bossGroup)
.workerEventLoopGroup(workerGroup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ public void setRatelimitTier(String ratelimitTier) {

this.ratelimitTier = ratelimitTier;
}
}
}
Loading

0 comments on commit af63478

Please sign in to comment.