-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add cache in cac client #268
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package expclient | ||
|
||
/* | ||
#include "libexperimentation_client.h" | ||
#include "../../../headers/libexperimentation_client.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Datron can you please verify the path change for the header file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pratikmishra356 don't change this, this go file runs in the users system, not inside superposition repo |
||
*/ | ||
import "C" | ||
import ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,18 +12,18 @@ func main() { | |
pollingFrequency := 1 | ||
cachostName := "http://localhost:8080" | ||
|
||
client, error := cacclient.NewCacClient(tenant, pollingFrequency, cachostName) | ||
client, error := cacclient.NewCacClient(tenant, pollingFrequency, cachostName, nil, nil, nil) | ||
if error != nil { | ||
fmt.Println(error) | ||
} | ||
|
||
fmt.Println("\n------------Configs----------------------------\n") | ||
fmt.Println("\n------------Configs----------------------------") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as it is already using println , that's why |
||
|
||
fmt.Println("Default Configs => ", client.GetConfig(nil, nil)) | ||
fmt.Println("Resolved Config => ", client.GetResolvedConfig(map[string]string{}, nil, cacclient.MERGE)) | ||
fmt.Println("Default Config => ", client.GetDefaultConfig(&[]string{})) | ||
|
||
fmt.Println("\n------------Experiments----------------------------\n") | ||
fmt.Println("\n------------Experiments----------------------------") | ||
|
||
expClient, error1 := expclient.NewExperimentationClient(tenant, pollingFrequency, cachostName) | ||
if error1 != nil { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont we need to update the path for the header files for Haskell client ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,10 +20,11 @@ import Data.List (intercalate) | |||||
import Foreign.C.String (CString, newCAString, peekCAString) | ||||||
import Foreign.C.Types (CInt (CInt), CULong (..)) | ||||||
import Foreign.ForeignPtr | ||||||
import Foreign.Marshal.Alloc (free) | ||||||
import Foreign.Marshal.Alloc (malloc, free) | ||||||
import Foreign.Marshal.Array (withArrayLen) | ||||||
import Foreign.Ptr | ||||||
import Prelude | ||||||
import Foreign.Storable (poke) | ||||||
|
||||||
data Arc_Client | ||||||
|
||||||
|
@@ -35,7 +36,7 @@ type Tenant = String | |||||
type Error = String | ||||||
|
||||||
foreign import ccall unsafe "cac_new_client" | ||||||
c_new_cac_client :: CTenant -> CULong -> CString -> IO CInt | ||||||
c_new_cac_client :: CTenant -> CULong -> CString -> Ptr CULong -> Ptr CULong -> Ptr CULong -> IO CInt | ||||||
|
||||||
foreign import ccall unsafe "&cac_free_client" | ||||||
c_free_cac_client :: FunPtr (Ptr CacClient -> IO ()) | ||||||
|
@@ -80,12 +81,22 @@ getError = c_last_error_message | |||||
cleanup :: [Ptr a] -> IO () | ||||||
cleanup items = mapM free items $> () | ||||||
|
||||||
createCacClient:: Tenant -> Integer -> String -> IO (Either Error ()) | ||||||
createCacClient tenant frequency hostname = do | ||||||
allocateCLongPtr :: Maybe Integer -> IO (Ptr CULong) | ||||||
allocateCLongPtr Nothing = return nullPtr | ||||||
allocateCLongPtr (Just val) = do | ||||||
ptr <- malloc :: IO (Ptr CULong) -- Allocate memory for CULong | ||||||
poke ptr (fromInteger val :: CULong) -- Store the value | ||||||
return ptr -- Return the pointer | ||||||
|
||||||
createCacClient:: Tenant -> Integer -> String -> Maybe Integer -> Maybe Integer -> Maybe Integer -> IO (Either Error ()) | ||||||
createCacClient tenant frequency hostname cacheMaxCapacity cacheTTL cacheTTI = do | ||||||
let duration = fromInteger frequency | ||||||
cTenant <- newCAString tenant | ||||||
cHostname <- newCAString hostname | ||||||
resp <- c_new_cac_client cTenant duration cHostname | ||||||
cacheCapacity <- allocateCLongPtr cacheMaxCapacity | ||||||
cacheTimeToLive <- allocateCLongPtr cacheTTL | ||||||
cacheTimeToIdle <- allocateCLongPtr cacheTTI | ||||||
resp <- c_new_cac_client cTenant duration cHostname cacheCapacity cacheTimeToLive cacheTimeToIdle | ||||||
Comment on lines
+96
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: Align the arrows for style |
||||||
_ <- cleanup [cTenant, cHostname] | ||||||
case resp of | ||||||
0 -> pure $ Right () | ||||||
|
@@ -108,7 +119,7 @@ getFullConfigStateWithFilter client mbFilters mbPrefix = do | |||||
cPrefix <- case mbPrefix of | ||||||
Just prefix -> newCAString (intercalate "," prefix) | ||||||
Nothing -> return nullPtr | ||||||
config <- withForeignPtr client $ \client -> c_get_config client cFilters cPrefix | ||||||
config <- withForeignPtr client $ \val -> c_get_config val cFilters cPrefix | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its client pointer, why rename it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Datron it was giving error , as we are using client name in functional parameter also |
||||||
_ <- cleanup [cFilters] | ||||||
if config == nullPtr | ||||||
then Left <$> getError | ||||||
|
@@ -132,7 +143,7 @@ getResolvedConfigWithStrategy client context mbKeys mergeStrat = do | |||||
cStrKeys <- case mbKeys of | ||||||
Just keys -> newCAString (intercalate "|" keys) | ||||||
Nothing -> return nullPtr | ||||||
overrides <- withForeignPtr client $ \client -> c_cac_get_resolved_config client cContext cStrKeys cMergeStrat | ||||||
overrides <- withForeignPtr client $ \val -> c_cac_get_resolved_config val cContext cStrKeys cMergeStrat | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
_ <- cleanup [cContext, cStrKeys] | ||||||
if overrides == nullPtr | ||||||
then Left <$> getError | ||||||
|
@@ -145,7 +156,7 @@ getDefaultConfig client mbKeys = do | |||||
cStrKeys <- case mbKeys of | ||||||
Just keys -> newCAString (intercalate "|" keys) | ||||||
Nothing -> return nullPtr | ||||||
overrides <- withForeignPtr client $ \client -> c_cac_get_default_config client cStrKeys | ||||||
overrides <- withForeignPtr client $ \val -> c_cac_get_default_config val cStrKeys | ||||||
_ <- cleanup [cStrKeys] | ||||||
if overrides == nullPtr | ||||||
then Left <$> getError | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,7 +11,7 @@ import Prelude | |||||
|
||||||
main :: IO () | ||||||
main = do | ||||||
createCacClient "dev" 10 "http://localhost:8080" >>= \case | ||||||
createCacClient "dev" 10 "http://localhost:8080" Nothing Nothing Nothing>>= \case | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Left err -> putStrLn err | ||||||
Right _ -> pure () | ||||||
threadId <- forkOS (cacStartPolling "dev") | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Datron can you please verify the path change for the header file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pratikmishra356 we shouldn't change this, rather use
$SUPERPOSITON_INCLUDE_PATH/libcac_client.h