投稿時間:2022-05-03 12:16:29 RSSフィード2022-05-03 12:00 分まとめ(18件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT 気になる、記になる… Amazon、今年後半に「Kindle」でEPUB形式をサポートへ https://taisy0.com/2022/05/03/156529.html amazon 2022-05-03 02:25:43
IT ITmedia 総合記事一覧 [ITmedia ビジネスオンライン] 漫画家・赤松健に聞く海賊版ビジネスの課題 電子化がもたらす若手作家への功罪とは https://www.itmedia.co.jp/business/articles/2205/03/news027.html itmedia 2022-05-03 11:20:00
TECH Techable(テッカブル) ネイキッドのAI占いアート展が海外進出! 感染症予防対策アートや台湾の占い師とのコラボも https://techable.jp/archives/177032 naked 2022-05-03 02:00:17
python Pythonタグが付けられた新着投稿 - Qiita 大怪我して孤独なGWを過ごしていたので、同じく孤独な数字 "素数" を数えて時を加速させた話 https://qiita.com/watanabe-tsubasa/items/51c5581c2b9a15fbdebf 前十字靭帯 2022-05-03 11:31:01
AWS AWSタグが付けられた新着投稿 - Qiita 【AWS】【SysOps】複数のAWSアカウントにAmazon GuardDutyを開始させる2つの方法(AWS Organizations, Invitation) https://qiita.com/Soojin/items/0f8e1eed9a60b61b66bc amazonguardduty 2022-05-03 11:15:53
Docker dockerタグが付けられた新着投稿 - Qiita Dockerでsshdを動かしてIntelliJのリモート開発を使ってみる https://qiita.com/skta/items/97055493328da56a0a2a docker 2022-05-03 11:06:36
Git Gitタグが付けられた新着投稿 - Qiita Gitのrebaseに関して https://qiita.com/hikaru0816/items/fd9875452848360e413d gitrebasemast 2022-05-03 11:12:38
海外TECH DEV Community No More VPN! Securely Connect to Private Resources with Twingate [Step-by-Step] https://dev.to/n3wt0n/no-more-vpn-securely-connect-to-private-resources-with-twingate-step-by-step-l8a No More VPN Securely Connect to Private Resources with Twingate Step by Step When moving to the cloud and in fast paced DevOps environments securely connecting to your private networks can be very challenging And if you and your team want to be able to do it from any device PCs phones tablets etc in an easy way while keep a Zero Trust approach and without a very complex VPN solution Well I d normally say good luck Today however I have for you a solution to that A service which lets you create a secure network between your servers computers and cloud instances even when separated by firewalls or subnets and that just works Oh and you can start with it for free Let s talk about Twingate Try out Twingate today and start securely accessing your private resources VideoAs usual if you are a visual learner or simply prefer to watch and listen instead of reading here you have the video with the whole explanation and demo which to be fair is much more complete than this post Link to the video If you rather prefer reading well let s just continue Why Twingate And Not a VPN Let s firstly see why we would want to use a Zero Trust Networking solution like Twingate over a normal VPN And for me it is down to main pillars SecurityPerformanceMaintainabilityUser Experience SecurityLet s start with Security With normal VPNs user access is usually granted to the entire network that the VPN secures and access to specific applications need to be managed with complex routing changes or by the applications themselves Twingate instead allows you to control access granularly at the application level not the network level The access is granted on a per application basis Moreover access to a specific resource can be based on a wide variety of factors including an identity authenticated by a third party SSO or identity provider using MFA the user s physical location time of day device and other contextual data Finally Twingate provides comprehensive logging in a single centralized view making monitoring way easier PerformanceLet s talk now about Performance If you ve ever used a VPN you know that in most cases that comes with a degradation of performance Not with Twingate this service in fact uses something called Smart Routing that promises to have no impact on user performance or latency And it works on levels First one is Resource level Split Tunneling With a normal VPN solution unless you have complex rules in place all traffic is sent to the VPN gateway and flows through it With Twingate instead only the traffic that needs to go to the private endpoint is sent through the service meaning that all your non private traffic is not affected We then have the NAT Traversal Traditional VPN clients are relatively limited They relay information to a VPN server and it is the job of that server and other network infrastructure to process authorization requests and manage traffic routing This is known to cause increased latency Twingate pushes these processing activities to the network edge by making its clients intelligent and creating peer to peer connections between clients and resources to minimize latency The final point about performance has to do with how the traffic is managed Instead of using single plexing which basically queues the traffic in a single stream and therefore causes performance degradation Twingate delivers concurrent data streams by multiplexing them over a single connection In general Twingate is able to improve connectivity performances to private resources and reduce corporate network congestion and bandwidth usage Deployment and MaintainabilityI mentioned before that another point I consider an advantage of Twingate over traditional VPN solutions is about Deployment and Maintainability We will see in a moment how quick and easy it is to deploy Twingate and this is something you don t usually get with a traditional VPN but it doesn t stop there Twingate provides a centralized admin console which controls access to private resources throughout the organization regardless of whether they are inside or outside the traditional network Additionally not much maintenance is needed on the connectors you deploy and the service uses an API first approach so you can automate the configuration make it part of your CI CD and even use Terraform to manage them User ExperienceI don t think I need to add much else to what we have seen so far to see why the user experience for both admins and end users is better than a traditional VPN Twingate ArchitectureBefore we see this in action I want to spend a moment talking about the overall service architecture and its components so later it will be easier to understand the steps we are taking Twingate relies on four components ControllerClientsConnectorsRelays The Controller is the central coordination component for Twingate It s a multi tenant component that stores configuration changes via the Admin console registers Connectors and issues signed authorizations to Clients making connection requests amongst other responsibilities The Client is installed onto user devices and acts as a combined authentication and authorization proxy for user requests for private Resources The Client is where most of the decision making takes place in a Twingate network deployment with routing and authorization taking place at the edge within the Client The Connector is deployed inside your private network or behind your firewall and takes care of validating the client connections and ACLs and performing local DNS resolutions among other things Finally the Relay is the simplest component in the Twingate architecture No data or network identifiable information is stored in the Relay and no data carrying connections are terminated at the Relay It basically serves as a registration point for Connectors and as a connection point for clients Step by Step VideosAlright enough talking Let s see this in action We will start from scratch installing the connectors the client and see how to use them all together ️⃣Demo setup overview️⃣Create a Twingate Network️⃣Installing the Twingate Connectors️⃣Add Resources to Twingate️⃣Twingate Clients Setup️⃣Connect to Private Resources️⃣Twingate Security and User Management️⃣Integration with Identity Provider AAD Okta etc ️⃣Advanced Management Devices and Policies PricingAs I ve mentioned before you can start with Twingate completely for free And you can keep it free forever if you don t need more than users or more than remote networks However with the free tier you will miss out on the most innovative and useful features If you want to have resource level access policies or integrate with your identity provider for example or if you need to have it rolled out to more users more devices or more remote networks then you ll have to go to one of their paid plans And as you have seen that can be even for unlimited users devices and remote networks But remember to factor in the cost of your deployed connectors as well as we have seen before Try out Twingate today and start securely accessing your private resources ConclusionsThere is so much more about the service we could explore like for example use Twingate to remotely connect to a NAS using it as an access control mechanisms for Staging Environments even use it for securing SaaS applications let me know in the comments below if you wanna see more about it and I ll try and make another article video about Twingate So what do I think about this service I do like it and I think it is on a whole new level if compared to standard VPN solutions One thing I d love to see implemented is some sort of automated provisioning of the connectors with Twingate using the cloud provider APIs to deploy it for you This may not apply to more enterprise level users where we normally prefer having more control over the deployments but I think smaller users could benefit from something like that Let me know in the comments below what your thoughts are about Twingate and if you will consider using it instead of a normal VPN or if you are already using it or some other Zero Trust Networking solution Finally check out this video in which I talk about DevSecOps and how to do it properly Like share and follow me for more content YouTube Buy me a coffeePatreonNewsletterCoderDave io WebsiteMerchFacebook page‍GitHubTwitterLinkedInPodcast 2022-05-03 02:30:53
海外TECH DEV Community A load shedding protector against bursting requests https://dev.to/kevwan/a-load-shedding-protector-against-bursting-requests-46ah A load shedding protector against bursting requests Why do we need load shedding In a microservice cluster the invocation chain is complex and as a service provider it needs a mechanism to protect itself from being overwhelmed by mindless invocations and to ensure the high availability of its own services The most common protection mechanism is flow limiting mechanism the premise of using flow limiter is to know the maximum number of concurrency that it can handle usually through pressure testing to get the maximum number of concurrency before going online and the flow limiting parameters of each interface are different in the daily request process while the system has been constantly iterating its processing capacity will often change each time before going online it is necessary to pressure test and then adjust the flow limiting The parameters become very tedious So is there a more concise flow limiting mechanism that can achieve maximum self protection What is adaptive load sheddingAdaptive load shedding is a very intelligent way to protect the service itself and dynamically determine whether it needs to be downgraded based on the system load of the service itself Design goals to ensure that the system is not dragged down maintain the system throughput under the premise of system stability The key then is how to measure the load of the service itself Judging high load depends on two main indicators whether the cpu is overloaded whether the maximum number of concurrency is overloaded When the above two points are satisfied at the same time it means that the service is in a high load state and adaptive load reduction is performed It should also be noted that the cpu load and concurrency of the high concurrency scenario tend to fluctuate greatly and we call this phenomenon burr from the data which may lead to frequent auto dowload operations so we generally obtain the average value of the indicators over a period of time to make the indicators more smooth The implementation can be done by accurately recording the metrics over a period of time and then directly calculating the average value but it takes up some system resources There is a statistical algorithm exponential moving average which can be used to estimate the local average of variables so that the update of variables is related to the historical values over time and the average can be estimated without recording all the historical local variables which saves valuable server resources Principle of Sliding Average Algorithm Refer to this article for a very clear explanation The variable V is noted as Vt at time t and θt is the value of the variable V taken at time t That is Vt θt when the sliding average model is not used and after using the sliding average model Vt is updated by the following formula Vt β⋅Vt β ⋅θtVt θt for β β which is approximately the average of the last θt valuesβ which is approximately the average of the last θt values Code ImplementationNext let s look at the code implementation of go zero adaptive load reduction core load adaptiveshedder goAdaptive downgrade interface definition callback functionPromise interface This function is called back when the request succeeds Pass Callback when the request fails Fail Drop the interface definitionShedder interface Drop check Allow the call you need to manually execute Promise accept reject to report the actual execution task structure Reject the call and it will return err Service overloaded error ErrServiceOverloaded Allow Promise error The interface definition is very concise meaning it is actually very simple to use exposing an Allow Promise error to the outside world Example of go zero usage The business only needs to call the method to determine whether to dowload if it is dowloaded then directly end the process otherwise the implementation of the business finally use the return value Promise according to the results of the implementation of the callback results can be func UnarySheddingInterceptor shedder load Shedder metrics stat Metrics grpc UnaryServerInterceptor ensureSheddingStat return func ctx context Context req interface info grpc UnaryServerInfo handler grpc UnaryHandler val interface err error sheddingStat IncrementTotal var promise load Promise Check if it was downgraded promise err shedder Allow drop the load and record the relevant logs and metrics if err nil metrics AddDrop sheddingStat IncrementDrop return Final callback execution result defer func Failed to execute if err context DeadlineExceeded promise Fail Execution succeeded else sheddingStat IncrementPass Promise Pass Execute the business method return handler ctx req Interface implementation class definition There are three main types of propertiescpu load threshold exceeding this value means the cpu is in a high load state cooling period if the service has been down loaded before then it will enter the cooling period the purpose is to prevent the load from being down during the process of down loading and immediately pressurized resulting in back and forth jitter Because it takes some time to reduce the load you should continue to check whether the number of concurrency exceeds the limit during the cooling off period and continue to discard requests if the limit is exceeded concurrency the number of concurrency currently being processed the average number of concurrency currently being processed and the number of requests and response time in the most recent period in order to calculate whether the number of concurrency currently being processed is greater than the maximum number of concurrency that can be carried by the system option parameter patternShedderOption func opts shedderOptions Optional configuration parametersshedderOptions struct sliding time window size window time Duration Number of sliding time windows buckets int cpu load threshold cpuThreshold intcpuThreshold int adaptiveShedder struct need to implement Shedder interfaceadaptiveShedder struct cpu load threshold higher than the threshold means high load needs to be down loaded to ensure service cpuThreshold int How many buckets in s windows int number of concurrent flying int Number of concurrent sliding smoothing avgFlying float Spin lock one service shares one drop Lock must be applied when counting the number of requests currently being processed lossless concurrency improves performance avgFlyingLock syncx SpinLock Last rejection time dropTime syncx AtomicDuration whether it has been rejected recently droppedRecently syncx AtomicBool request count statistics with a sliding time window to record metrics for the most recent period passCounter collection RollingWindow response time statistics with a sliding time window to record metrics over the most recent period rtCounter collection RollingWindow Adaptive dropload constructor func NewAdaptiveShedder opts ShedderOption Shedder To ensure code uniformity return the default empty implementation when the developer closes to achieve code uniformity go zero uses this design in many places such as Breaker the logging component if enabled True return newNopShedder options mode sets optional configuration parameters options shedderOptions Default statistics for the last s window defaultWindow default bucket count of buckets defaultBuckets cpu load cpuThreshold defaultCpuThreshold for opt range opts opt amp options Calculate the interval for each window default is ms bucketDuration options window time Duration options buckets return amp adaptiveShedder cpu load cpuThreshold options cpuThreshold How many sliding window units are contained in s of time windows int time Second bucketDuration last rejection time dropTime syncx NewAtomicDuration whether it has been rejected recently droppedRecently syncx NewAtomicBool qps statistics sliding time window ignore the current writing window bucket incomplete time period may lead to data exceptions NewRollingWindow options buckets bucketDuration passCounter collection IgnoreCurrentBucket Response time statistics sliding time window Ignore the current writing window bucket incomplete time period may lead to data exceptions rtCounter collection NewRollingWindow options buckets bucketDuration collection IgnoreCurrentBucket Drop check Allow Check if the current request should be dropped and if it is dropped the business side needs to interrupt the request directly to protect the service which also means that the downgrade takes effect while entering the cooling off period If released then return promise and wait for the business side to execute the callback function to perform the metrics statistics Drop checkfunc as adaptiveShedder Allow Promise error Check if the request was dropped if as shouldDrop Set the drop time as dropTime Set timex Now Recently dropped as droppedRecently Set true return overloaded return nil ErrServiceOverloaded Add to the number of requests being processed as addFlying Each allowed request here returns a new promise object promise holds the drop pointer object internally return amp promise start timex Now shedder as nil Check if shouldDrop whether the request should be dropped or notfunc as adaptiveShedder shouldDrop bool The current cpu load exceeds the threshold The service should continue to check the load and try to drop the request while it is on cooldown if as systemOverloaded as stillHot Check if the concurrency being processed exceeds the current maximum number of concurrency that can be hosted Discard the request if it exceeds it if as highThru flying atomic LoadInt amp as flying as avgFlyingLock Lock avgFlying as avgFlying as avgFlyingLock Unlock msg fmt Sprintf dropreq cpu d maxPass d minRt f hot t flying d avgFlying f stat CpuUsage as maxPass as minRt as stillHot flying avgFlying logx Error msg stat Report msg return true return false cpu threshold check systemOverloaded The cpu load value calculation algorithm uses a sliding average algorithm to prevent burrs Sampling every ms βis which is roughly equivalent to the average of cpu loadings in history with a time period of about s whether the cpu is overloadedfunc as adaptiveShedder systemOverloaded bool return systemOverloadChecker as cpuThreshold cpu checker functionsystemOverloadChecker func cpuThreshold int bool return stat CpuUsage gt cpuThreshold cpu sliding averagecurUsage internal RefreshCpu prevUsage atomic LoadInt amp cpuUsage cpu cpuᵗ ¹ beta cpuᵗ beta sliding average algorithmusage int float prevUsage beta float curUsage beta atomic StoreInt amp cpuUsage usage Check if the system is in a cooling period stillHot Determine if the current system is in a cooling period if it is it should continue to try to check if the request is dropped The main purpose is to prevent the system in the process of recovery from overload load has not yet come down immediately increase the pressure again resulting in back and forth jitter at this time should try to continue to discard the request func as adaptiveShedder stillHot bool No requests have been dropped recently means the service is fine if as droppedRecently True return false Not on cooldown dropTime as dropTime Load if dropTime return false cool down time defaults to s hot timex Since dropTime lt coolOffDuration not in the cool off period normal processing of requests in progress if hot reset the drop record as droppedRecently Set false return hot Check the number of concurrency currently being processed highThru Once current concurrency being processed gt concurrency carrying limit then go into a down load state Why do we need to add locks here Because adaptive downgrading is used globally to ensure that the concurrency average is correct Why do we need to add spin locks here Because the concurrent processing can be done without blocking other goroutine execution tasks using lock free concurrency to improve performance func as adaptiveShedder highThru bool locking as avgFlyingLock Lock Get the sliding average update at the end of each request avgFlying as avgFlying Unlock as avgFlyingLock Unlock Maximum number of concurrent requests at this point in the system maxFlight as maxFlight whether the number of concurrent processes and the average number of concurrent processes is greater than the system s maximum number of concurrent processes return int avgFlying gt maxFlight amp amp atomic LoadInt amp as flying gt maxFlight How do I get the number of concurrency being processed versus the average concurrency The current concurrency count is actually very simple concurrency for each allowed request for the promise object callback after the request is completed and the average concurrency can be solved using the sliding average algorithm type promise struct request start time count the time spent on request processing start time shedder adaptiveSheddershedder adaptiveShedder func p promise Fail End of request for the number of requests currently being processed p shedder addFlying func p promise Pass response time in milliseconds rt float timex Since p start float time Millisecond end of request number of requests currently being processed p shedder addFlying p shedder rtCounter Add math Ceil rt p shedder passCounter Add func as adaptiveShedder addFlying delta int flying atomic AddInt amp as flying delta After the request ends count the concurrency of requests currently being processed if delta lt as avgFlyingLock Lock Estimate the average number of requests for the current service over the recent time period as avgFlying as avgFlying flyingBeta float flying flyingBeta as avgFlyingLock Unlock It s not enough to get the current system count we also need to know the maximum number of concurrent requests the system can handle i e the maximum number of concurrent requests The number of requests passed and the response time are achieved by a sliding window which can be implemented in the Adaptive Fuse article The maximum concurrency of the current system the maximum number of passes per unit time of the window the minimum response time per unit time of the window Calculate the maximum concurrency of the system per second max concurrency max requests qps min response time rt func as adaptiveShedder maxFlight int windows buckets per second maxQPS maxPASS windows minRT min average response time in milliseconds maxQPS minRT milliseconds per second as maxPass as windows maximum qps per bucket number of buckets contained in s as minRt e the smallest average response time of all buckets in the window ms here to convert to seconds return int math Max float as maxPass as windows as minRt e Sliding time window with multiple buckets find the one with the highest number of requests Each bucket takes up internal ms qps refers to the number of requests in s qps maxPass time Second internalfunc as adaptiveShedder maxPass int var result float The bucket with the highest number of requests in the current time window as passCounter Reduce func b collection Bucket if b Sum gt result result b Sum return int result Sliding time window with multiple buckets Calculate the minimum average response time because it is necessary to calculate the maximum number of concurrency the system can handle in a recent period of timefunc as adaptiveShedder minRt float default is ms result defaultMinRt as rtCounter Reduce func b collection Bucket if b Count lt return request average response time avg math Round b Sum float b Count if avg lt result result avg return result ReferenceGoogle BBR Congestion Control AlgorithmPrinciple of sliding average algorithmgo zero adaptive load shedding Project addressFeel free to use go zero and star to support us 2022-05-03 02:27:51
海外TECH DEV Community My best practices on Go fuzzing https://dev.to/kevwan/best-practices-for-go-fuzzing-in-go-118-4ic8 My best practices on Go fuzzing As programmers we often hope that our code is bug free But the fact is that bug free can only be disproved not proven The upcoming release of Go officially provides a great tool to help us prove it in most cases go fuzzing Go is all about generics but I really think go fuzzing is the most useful feature of Go at the moment even compared with generics In this article we ll take a closer look at go fuzzing What is it How to use go fuzzing What are the best practices What is go fuzzingAccording to the official documentation go fuzzing is a way to automate tests by continuously giving different inputs to a program and analyzing the code coverage to intelligently find the failed cases The problems found in the test are usually difficult to find How to use go fuzzingThe official rules for writing fuzz tests are The function must start with Fuzz the only argument is testing F and there is no return valueFuzz tests must be in the test go fileThe fuzz target in the above image is a method call testing F Fuzz with testing T as the first argument and then arguments called fuzzing arguments with no return valueThere can be only one fuzz target in each fuzz testCalling f Add requires that the arguments be of the same order and type as the fuzzing argumentsfuzzing arguments only supports the following types string byteint int int int rune intuint uint byte uint uint uintfloat floatboolfuzz target Do not rely on global state it will run in parallel Run fuzzing testsIf I write a fuzzing test e g See for the specific codefunc FuzzMapReduce f testing F Then we can execute it like this go test fuzz MapReduceWe would get something like the following result fuzz elapsed s gathering baseline coverage completedfuzz elapsed s gathering baseline coverage completed now fuzzing with workersfuzz elapsed s execs sec new interesting total fuzz elapsed s execs sec new interesting total fuzz elapsed s execs sec new interesting total fuzz elapsed s execs sec new interesting total Cfuzz elapsed s execs sec new interesting total PASSok github com zeromicro go zero core mr sThe C is because I pressed Ctrl C to terminate the test see the official documentation for details best practices in go zeroBased on my experience with go zero I ve summarized the best practices in four preliminary steps define fuzzing arguments first figure out how to define fuzzing arguments and write fuzzing target with the given fuzzing arguments think about how to write fuzzing target the focus here is on how to verify the correctness of the results because fuzzing arguments are given randomly so there should be a general method to verify the resultsthink about how to print the result of a failed case so that a new unit test can be generatedwrite a new unit test based on the results of the failed fuzzing test this new unit test will be used to debug the problems found by the fuzzing test and solidify them for the CI The next step is to show the above steps with a simple array summation function The actual case in go zero is slightly more complicated and I will give the internal go zero landing case at the end of the article for you to write complex scenarios Here is a bug injected implementation of the summation code func Sum vals int int var total int for val range vals if val e total val return total Define fuzzing argumentsYou need to give at least one fuzzing argument otherwise go fuzzing can t generate test code so even if we don t have good input we need to define a fuzzing argument that will have an impact on the result here we use the number of slice elements as fuzzing arguments and then Go fuzzing will automatically generate different arguments to simulate the test based on the code coverage that is run func FuzzSum f testing F f Add f Fuzz func t testing T n int n Here n is the number of elements that go fuzzing can simulate in a slice To make sure the number of elements is not too high we limit it to is fine and we add a corpus of called corpus in go fuzzing which is the value that makes go fuzzing cold start it doesn t matter how much it is How to write the fuzzing targetThis step focuses on writing a verifiable fuzzing target writing test code based on the given fuzzing arguments and generating data to verify the correctness of the results For our Sum function it is actually relatively simple to generate a random slice of n elements and then sum up the expected result As follows func FuzzSum f testing F rand Seed time Now UnixNano f Add f Fuzz func t testing T n int n var vals int var expect int for i i lt n i val rand Int e vals append vals val expect val assert Equal t expect Sum vals This code is still very easy to understand their own summation and Sum summation to do a comparison only will not explain in detail But complex scenarios you need to think carefully about how to write the verification code but this will not be too difficult too difficult it may not be enough understanding of the test function or simplify At this point you can run fuzzing tests with the following command and the result will be similar to the following go test fuzz Sumfuzz elapsed s gathering baseline coverage completedfuzz elapsed s gathering baseline coverage completed now fuzzing with workersfuzz elapsed s execs sec new interesting total FAIL FuzzSum s FAIL FuzzSum s sum fuzz test go Error Trace sum fuzz test go value go value go fuzz go Error Not equal expected actual Test FuzzSum Failing input written to testdata fuzz FuzzSum aceffffefbbdecabeeecffaaff To re run go test run FuzzSum aceffffefbbdecabeeecffaaffFAILexit status FAIL github com kevwan fuzzing sSo here s the problem We see the result is not right but we can hardly analyze why it is not right you taste carefully this output above how do you analyze How to print the input for the failed caseFor the above failed test if we can print out the input and form a simple test case then we can debug it directly It is better to copy paste the printed input directly to the new test case if the format is not right you need to adjust the format line by line for so many lines of input is too tired and it may not be only one failure case So we changed the code to the following func FuzzSum f testing F rand Seed time Now UnixNano f Add f Fuzz func t testing T n int n var vals int var expect int var buf strings buf WriteString n for i i lt n i val rand Int e vals append vals val expect val buf WriteString fmt Sprintf d n val assert Equal t expect Sum vals buf String Running the command again gives the following result go test fuzz Sumfuzz elapsed s gathering baseline coverage completedfuzz elapsed s gathering baseline coverage completed now fuzzing with workersfuzz elapsed s execs sec new interesting total FAIL FuzzSum s FAIL FuzzSum s sum fuzz test go Error Trace sum fuzz test go value go value go fuzz go Error Not equal expected actual Test FuzzSum Messages Failing input written to testdata fuzz FuzzSum dacfaaefbfecfeabbfadbbfdbcf To re run go test run FuzzSum dacfaaefbfecfeabbfadbbfdbcfFAILexit status FAIL github com kevwan fuzzing s Write a new test caseBased on the output of the failure case above we can copy paste the following code but of course the framework is written by ourselves and the input parameters can be copied in directly func TestSumFuzzCase t testing T vals int assert Equal t int Sum vals This makes it easy to debug and to add a valid unit test to ensure that the bug never comes up again go fuzzing more experience Go versioning issuesI believe that Go has been released and most projects will not immediately upgrade their online code to so what if the testing F introduced by go fuzzing doesn t work If the online go mod is not upgraded to Go but we are fully recommended to upgrade locally then we just need to put the above FuzzSum into a file with a name like sum fuzz test go and add the following directive to the header go build go build goNote The third line must be a blank line otherwise it will become a package comment This way we don t report errors online no matter which version we use and we run fuzz testing usually locally and are not affected go fuzzing does not reproduce failuresThe above steps are for simple cases but sometimes the problem becomes complicated when the input from the failure case forms a new unit test that does not reproduce the problem especially if there is a goroutine deadlock problem as you can see in the following output go test fuzz MapReducefuzz elapsed s gathering baseline coverage completedfuzz elapsed s gathering baseline coverage completed now fuzzing with workersfuzz elapsed s execs sec new interesting total fuzz elapsed ms execs sec new interesting total FAIL FuzzMapReduce s fuzzing process hung or terminated unexpectedly exit status Failing input written to testdata fuzz FuzzMapReduce eeaecadadefbacacdcdebcaad To re run go test run FuzzMapReduce eeaecadadefbacacdcdebcaadFAILexit status FAIL github com zeromicro go zero core mr sIn this case it just tells us that the fuzzing process is stuck or has ended abnormally with a status code of In this case the re run is not normally reproduced Why does it simply return an error code of I went through the source code of go fuzzing and each fuzzing test is run by a separate process and then go fuzzing throws away the process output of the fuzzing test and just shows the status code So how do we solve this problem After careful analysis I decided to write a regular unit test code like fuzzing test myself which would ensure that the failures are in the same process and would print the error message to the standard output the code is roughly as follows func TestSumFuzzRandom t testing T const times rand Seed time Now UnixNano for i i lt times i n rand Intn var vals int var expect int var buf strings buf WriteString n for i i lt n i val rand Int e vals append vals val expect val buf WriteString fmt Sprintf d n val assert Equal t expect Sum vals buf String This way we can do a simple simulation of go fuzzing ourselves but with any errors we can get clear output Here maybe we study through go fuzzing or there are other ways to control it if you know thanks for letting me know But this simulated case that takes a long time to run we wouldn t want it to be executed every time at CI so I put it in a separate file named something like sum fuzzcase test go and added the following directive to the header of the file go build fuzz build fuzzThis way we can add tags fuzz when we need to run this mock case e g go test tags fuzz Complex usage examplesThe above is an example still relatively simple if you encounter complex scenarios do not know how to write you can first see how go zero is landed go fuzzing as follows MapReduce stringx Project addressFeel free to use go zero and star to support us 2022-05-03 02:07:19
Apple AppleInsider - Frontpage News Apple's latest iPad mini dips to lowest price ever on Amazon https://appleinsider.com/articles/22/05/03/apples-latest-ipad-mini-dips-to-lowest-price-ever-on-amazon?utm_medium=rss Apple x s latest iPad mini dips to lowest price ever on AmazonMay iPad deals are off to a great start at Amazon with the current iPad mini dipping to off just in time for Mother s Day Apple s iPad mini makes a great Mother s Day gift at up to offThe staggering to discounts are valid on numerous models from the GB Wi Fi config for to the GB Wi Fi spec in Space Gray for off Read more 2022-05-03 02:22:11
ニュース BBC News - Home Roe v Wade: Leaked US Supreme Court document suggests abortion law repeal https://www.bbc.co.uk/news/world-us-canada-61302740?at_medium=RSS&at_campaign=KARANGA politico 2022-05-03 02:56:01
北海道 北海道新聞 知床、船体の水中カメラ調査を再開 速い潮流に阻まれ作業難航 https://www.hokkaido-np.co.jp/article/676779/ 水中カメラ 2022-05-03 11:27:52
北海道 北海道新聞 J3の2試合が中止 複数のコロナ陽性者 https://www.hokkaido-np.co.jp/article/676792/ 陽性 2022-05-03 11:16:00
北海道 北海道新聞 河瀬さん五輪映画、カンヌで上映 フランスの映画祭、5月開催 https://www.hokkaido-np.co.jp/article/676775/ 開催 2022-05-03 11:05:02
北海道 北海道新聞 女子ゴルフ世界ランク、畑岡6位で変わらず 笹生は13位 https://www.hokkaido-np.co.jp/article/676753/ 世界ランキング 2022-05-03 11:02:23
海外TECH reddit Megathread: Draft memo shows the Supreme Court has voted to overturn Roe V Wade https://www.reddit.com/r/politics/comments/uh61gv/megathread_draft_memo_shows_the_supreme_court_has/ Megathread Draft memo shows the Supreme Court has voted to overturn Roe V WadeThe Supreme Court has voted to strike down the landmark Roe v Wade decision according to an initial draft majority opinion written by Justice Samuel Alito circulated inside the court Submissions that may interest you SUBMISSION DOMAIN Supreme Court votes to overturn Roe v Wade report says komonews com Supreme Court Draft Decision Would Strike Down Roe v Wade thedailybeast com Supreme Court has voted to overturn abortion rights draft opinion shows politico com Report A leaked draft opinion suggests the Supreme Court will overturn Roe v Wade npr org Draft opinion published by Politico suggests Supreme Court will overturn Roe v Wade wgal com A draft Supreme Court opinion indicates Roe v Wade will be overturned Politico reports in extraordinary leak nbcnews com Supreme Court Leak Shows Justices Preparing To Overturn Roe Politico Reports huffpost com Leaked draft Supreme Court decision would overturn Roe v Wade abortion rights ruling Politico report says cnbc com Report Draft opinion suggests high court will overturn Roe apnews com Supreme Court draft opinion that would overturn Roe v Wade published by Politico cnn com Leaked initial draft says Supreme Court will vote to overturn Roe v Wade report claims independent co uk submitted by u PoliticsModeratorBot to r politics link comments 2022-05-03 02:26:32
海外TECH reddit [TOR-TBL] Perry and Maroon go after Simmonds after a hit along the boards. A scrum ensues, and a line brawl occcurs during the TV timeout after Simmonds goes after Hedman. (Both feeds, penalties in comments) https://www.reddit.com/r/hockey/comments/uh5l32/tortbl_perry_and_maroon_go_after_simmonds_after_a/ TOR TBL Perry and Maroon go after Simmonds after a hit along the boards A scrum ensues and a line brawl occcurs during the TV timeout after Simmonds goes after Hedman Both feeds penalties in comments submitted by u nopClip to r hockey link comments 2022-05-03 02:01:52

コメント

このブログの人気の投稿

投稿時間:2021-06-17 22:08:45 RSSフィード2021-06-17 22:00 分まとめ(2089件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)