Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4925,226 +4925,6 @@ data:
"title": "Package cache size",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "$datasource"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "Hit ratio",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"links": [

],
"mappings": [

],
"max": 1,
"min": 0,
"noValue": "0%",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green"
},
{
"color": "red",
"value": 80
}
]
},
"unit": "percentunit"
},
"overrides": [

]
},
"gridPos": {
"h": 6,
"w": 12,
"x": 0,
"y": 90
},
"id": 92,
"options": {
"legend": {
"calcs": [

],
"displayMode": "list",
"placement": "bottom",
"showLegend": false
},
"tooltip": {
"hideZeros": false,
"mode": "multi",
"sort": "none"
}
},
"pluginVersion": "11.6.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "$datasource"
},
"editorMode": "code",
"expr": "sum(patchman_engine_evaluator_vmaas_cache{type=\"hit\"})/sum(patchman_engine_evaluator_vmaas_cache)",
"hide": false,
"legendFormat": "__auto",
"range": true,
"refId": "A"
}
],
"title": "VMaaS cache hit ratio",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "$datasource"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "items",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"links": [

],
"mappings": [

],
"noValue": "0%",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green"
},
{
"color": "red",
"value": 80
}
]
},
"unit": "none"
},
"overrides": [

]
},
"gridPos": {
"h": 6,
"w": 12,
"x": 12,
"y": 90
},
"id": 93,
"options": {
"legend": {
"calcs": [

],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "multi",
"sort": "desc"
}
},
"pluginVersion": "11.6.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "$datasource"
},
"editorMode": "code",
"expr": "sum(patchman_engine_evaluator_vmaas_cache_size) by (container)",
"hide": false,
"legendFormat": "__auto",
"range": true,
"refId": "A"
}
],
"title": "VMaaS cache size",
"type": "timeseries"
},
{
"collapsed": false,
"gridPos": {
Expand Down
39 changes: 1 addition & 38 deletions evaluator/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import (
"app/base/types"
"app/base/utils"
"app/base/vmaas"
"app/tasks"
"context"
"net/http"
"sync"
"time"

"github.com/bytedance/sonic"
"github.com/google/uuid"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"go.opentelemetry.io/otel/trace"
"gorm.io/gorm"
Expand Down Expand Up @@ -53,9 +51,6 @@ var (
preloadPackageCache bool
packageCacheSize int
packageNameCacheSize int
enableVmaasCache bool
vmaasCacheSize int
vmaasCacheCheckDuration time.Duration
vmaasCallMaxRetries int
vmaasCallUseExpRetry bool
vmaasCallUseOptimisticUpdates bool
Expand Down Expand Up @@ -120,12 +115,6 @@ func configureEvaluator() {
packageCacheSize = utils.PodConfig.GetInt("package_cache_size", 1000000)
// Size of package name cache
packageNameCacheSize = utils.PodConfig.GetInt("package_name_cache_size", 60000)
// Toggle caching of vmaas responses
enableVmaasCache = utils.PodConfig.GetBool("vmaas_cache", true)
// Size of vmaas response cache
vmaasCacheSize = utils.PodConfig.GetInt("vmaas_cache_size", 10000)
// Interval to check vmaas API if there was a data change thus if cache is still valid
vmaasCacheCheckDuration = time.Duration(utils.PodConfig.GetInt("vmaas_cache_check_duration_sec", 60)) * time.Second
// How many tries before we consider vmaad API call failed
vmaasCallMaxRetries = utils.PodConfig.GetInt("vmaas_call_max_retries", 8)
// Use exponential delay between two vmaas calls
Expand Down Expand Up @@ -362,17 +351,6 @@ func getUpdatesData(ctx context.Context, system *models.SystemPlatformV2) (*vmaa
func getVmaasUpdates(ctx context.Context, system *models.SystemPlatformV2) (*vmaas.UpdatesV3Response, error) {
defer utils.ObserveSecondsSince(time.Now(), evaluationPartDuration.WithLabelValues("vmaas-updates-prepare"))

var vmaasDataCopy vmaas.UpdatesV3Response
// first check if we have data in cache
vmaasData, ok := memoryVmaasCache.Get(system.Inventory.JSONChecksum)
if ok {
// return copy of vmaasData to avoid modification of cached data e.g. by templates
err := copier.CopyWithOption(&vmaasDataCopy, vmaasData, copier.Option{DeepCopy: true})
if err != nil {
return nil, err
}
return &vmaasDataCopy, nil
}
updatesReq, err := tryGetVmaasRequest(system)
if err != nil {
return nil, errors.Wrap(err, "unable to get vmaas request")
Expand All @@ -388,20 +366,11 @@ func getVmaasUpdates(ctx context.Context, system *models.SystemPlatformV2) (*vma
updatesReq.OptimisticUpdates = utils.PtrBool(useOptimisticUpdates)
updatesReq.EpochRequired = utils.PtrBool(true)

vmaasData, err = callVMaas(ctx, updatesReq)
vmaasData, err := callVMaas(ctx, updatesReq)
if err != nil {
evaluationCnt.WithLabelValues("error-call-vmaas-updates").Inc()
return nil, errors.Wrap(err, "vmaas API call failed")
}

if memoryVmaasCache.enabled {
// store copy of vmaasData to cache to avoid modification of cached data e.g. by templates
err := copier.CopyWithOption(&vmaasDataCopy, vmaasData, copier.Option{DeepCopy: true})
if err != nil {
return nil, err
}
memoryVmaasCache.Add(system.Inventory.JSONChecksum, &vmaasDataCopy)
}
return vmaasData, nil
}

Expand Down Expand Up @@ -824,12 +793,6 @@ func evaluateHandler(ctx context.Context, m mqueue.KafkaMessage) error {
func loadCache() {
memoryPackageCache = NewPackageCache(enablePackageCache, preloadPackageCache, packageCacheSize, packageNameCacheSize)
memoryPackageCache.Load()
tx := tasks.CancelableDB()
memoryVmaasCache = NewVmaasPackageCache(tx, enableVmaasCache, vmaasCacheSize, vmaasCacheCheckDuration)
if memoryVmaasCache.enabled {
// no need to check cache validity when cache is not enabled
go memoryVmaasCache.CheckValidity(tx)
}
}

func run(wg *sync.WaitGroup, readerBuilder mqueue.CreateReader) {
Expand Down
Loading
Loading