Skip to content

Commit caaff4e

Browse files
committed
Add keyCtx to ingestion layer
1 parent f41f891 commit caaff4e

33 files changed

+98
-160
lines changed

ako-gateway-api/k8s/ako_init.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"k8s.io/client-go/tools/cache"
3434
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
3535

36-
"github.com/google/uuid"
3736
akogatewayapilib "github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/ako-gateway-api/lib"
3837
akogatewayapinodes "github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/ako-gateway-api/nodes"
3938
akogatewayapistatus "github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/ako-gateway-api/status"
@@ -230,7 +229,6 @@ func (c *GatewayController) addIndexers() {
230229
}
231230

232231
func (c *GatewayController) FullSyncK8s(sync bool) error {
233-
234232
if c.DisableSync {
235233
utils.AviLog.Infof("Sync disabled, skipping full sync")
236234
return nil
@@ -245,8 +243,7 @@ func (c *GatewayController) FullSyncK8s(sync bool) error {
245243

246244
var filteredGatewayClasses []*gatewayv1.GatewayClass
247245
for _, gwClassObj := range gwClassObjs {
248-
UUID := uuid.New()
249-
key := lib.GatewayClass + "/" + utils.ObjKey(gwClassObj) + "-" + UUID.String()
246+
key := lib.GatewayClass + "/" + utils.ObjKey(gwClassObj)
250247
meta, err := meta.Accessor(gwClassObj)
251248
if err == nil {
252249
resVer := meta.GetResourceVersion()
@@ -258,6 +255,7 @@ func (c *GatewayController) FullSyncK8s(sync bool) error {
258255
}
259256
for _, filteredGatewayClass := range filteredGatewayClasses {
260257
key := lib.GatewayClass + "/" + utils.ObjKey(filteredGatewayClass)
258+
261259
akogatewayapinodes.DequeueIngestion(key, true)
262260
}
263261

@@ -288,6 +286,7 @@ func (c *GatewayController) FullSyncK8s(sync bool) error {
288286
})
289287
for _, filteredGateway := range filteredGateways {
290288
key := lib.Gateway + "/" + utils.ObjKey(filteredGateway)
289+
291290
akogatewayapinodes.DequeueIngestion(key, true)
292291
}
293292

@@ -318,6 +317,7 @@ func (c *GatewayController) FullSyncK8s(sync bool) error {
318317
})
319318
for _, filteredHTTPRoute := range filteredHTTPRoutes {
320319
key := lib.HTTPRoute + "/" + utils.ObjKey(filteredHTTPRoute)
320+
321321
akogatewayapinodes.DequeueIngestion(key, true)
322322
}
323323

@@ -347,6 +347,7 @@ func (c *GatewayController) FullSyncK8s(sync bool) error {
347347
for _, podObj := range podObjs {
348348
podLabel := utils.ObjKey(podObj)
349349
key := utils.Pod + "/" + podLabel
350+
350351
if _, ok := podObj.GetAnnotations()[lib.NPLPodAnnotation]; !ok {
351352
utils.AviLog.Warnf("key : %s, msg: 'nodeportlocal.antrea.io' annotation not found, ignoring the pod", key)
352353
continue
@@ -456,6 +457,7 @@ func SyncFromIngestionLayer(key interface{}, wg *sync.WaitGroup) error {
456457
akogatewayapinodes.DequeueIngestion(keyStr, false)
457458
return nil
458459
}
460+
459461
func SyncFromFastRetryLayer(key interface{}, wg *sync.WaitGroup) error {
460462
keyStr, ok := key.(string)
461463
if !ok {

ako-gateway-api/lib/types.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,36 @@
1515
package lib
1616

1717
import (
18+
"context"
19+
"strings"
20+
1821
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
1922

23+
"github.com/google/uuid"
24+
25+
"github.com/vmware/alb-sdk/go/logger"
26+
2027
"github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/internal/lib"
2128
)
2229

2330
var SupportedKinds = map[gatewayv1.ProtocolType][]gatewayv1.RouteGroupKind{
2431
gatewayv1.HTTPProtocolType: {{Kind: lib.HTTPRoute}},
2532
gatewayv1.HTTPSProtocolType: {{Kind: lib.HTTPRoute}},
2633
}
34+
35+
type traceID string
36+
type KeyContext struct {
37+
KeyStr string
38+
Ctx context.Context
39+
}
40+
41+
func getNewTraceId() string {
42+
traceID := uuid.New().String()
43+
traceID = strings.Replace(traceID, "-", "", -1) // default value
44+
return traceID
45+
}
46+
47+
func NewKeyContextWithTraceID(key string, ctx context.Context) KeyContext {
48+
return KeyContext{KeyStr: key,
49+
Ctx: logger.SetTraceID(ctx, getNewTraceId())}
50+
}

ako-gateway-api/nodes/dequeue_ingestion.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import (
2929
)
3030

3131
func DequeueIngestion(key string, fullsync bool) {
32-
utils.AviLog.Infof("key: %s, msg: starting graph Sync", key)
32+
keyCtx := akogatewayapilib.NewKeyContextWithTraceID(key, context.Background())
33+
ctx := keyCtx.Ctx
34+
utils.AviLog.WithContext(ctx).Infof("key: %s, msg: starting graph Sync", key)
3335
objType, namespace, name := lib.ExtractTypeNameNamespace(key)
3436

3537
schema, valid := ConfigDescriptor().GetByType(objType)

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ require (
3737
sigs.k8s.io/service-apis v0.1.0
3838
)
3939

40+
replace github.com/vmware/alb-sdk => ../alb-sdk
41+
4042
require (
4143
github.com/beorn7/perks v1.0.1 // indirect
4244
github.com/cespare/xxhash/v2 v2.2.0 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,6 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb
512512
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=
513513
github.com/vmware-tanzu/service-apis v0.0.0-20200901171416-461d35e58618 h1:ZLkxMxSr/YrYENjUJ8g6uB4rUQpZKBR3Olqf2DvuMFk=
514514
github.com/vmware-tanzu/service-apis v0.0.0-20200901171416-461d35e58618/go.mod h1:afqpDk9He9v+/qWix0RRotm3RNyni4Lmc1y9geDCPuo=
515-
github.com/vmware/alb-sdk v0.0.0-20240619053936-3103500da639 h1:UaTxFP5LeiSOlLEyHC9kmYuzdZWmvYpPB7jevg+ASNw=
516-
github.com/vmware/alb-sdk v0.0.0-20240619053936-3103500da639/go.mod h1:fuRb4saDY/xy/UMeMvyKYmcplNknEL9ysaqYSw7reNE=
517515
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
518516
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
519517
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=

pkg/utils/avi_rest_utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ func NewAviRestClientPool(num uint32, api_ep, username,
5454
if !isSecure || protocol == "http" {
5555
options = append(options, session.SetInsecure)
5656
}
57-
if protocol == "http" {
58-
options = append(options, session.SetScheme("http"))
59-
}
57+
// if protocol == "http" {
58+
// options = append(options, session.SetScheme("http"))
59+
// }
6060

6161
if authToken == "" {
6262
options = append(options, session.SetPassword(password))

pkg/utils/log.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
package utils
1616

1717
import (
18+
"context"
1819
"fmt"
1920
"os"
2021
"strings"
2122
"time"
2223

2324
"github.com/go-logr/logr"
25+
"github.com/vmware/alb-sdk/go/logger"
2426
"go.uber.org/zap"
2527
"go.uber.org/zap/zapcore"
2628
lumberjack "gopkg.in/natefinch/lumberjack.v2"
@@ -81,7 +83,8 @@ func (AviLogger) Init(info logr.RuntimeInfo) {
8183
// Not used
8284
}
8385

84-
func (aviLogger AviLogger) WithContext(traceID int) *zap.SugaredLogger {
86+
func (aviLogger AviLogger) WithContext(ctx context.Context) *zap.SugaredLogger {
87+
traceID := logger.GetTraceID(ctx)
8588
return aviLogger.sugar.With("trace-id", traceID)
8689
}
8790

vendor/github.com/vmware/alb-sdk/go/logger/logger.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/vmware/alb-sdk/go/models/alert_config.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/vmware/alb-sdk/go/models/auth_profile.go

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)