<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Gal Ben Ami</title>
    <description>The latest articles on Forem by Gal Ben Ami (@galusben).</description>
    <link>https://forem.com/galusben</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F237677%2F06705dce-221f-49f0-97a3-a33137138f13.jpeg</url>
      <title>Forem: Gal Ben Ami</title>
      <link>https://forem.com/galusben</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/galusben"/>
    <language>en</language>
    <item>
      <title>Reversee, yet another web debugger?</title>
      <dc:creator>Gal Ben Ami</dc:creator>
      <pubDate>Mon, 13 Jan 2020 17:10:57 +0000</pubDate>
      <link>https://forem.com/galusben/reversee-yet-another-web-debugger-44d0</link>
      <guid>https://forem.com/galusben/reversee-yet-another-web-debugger-44d0</guid>
      <description>&lt;p&gt;A while ago I have started a project named Reversee. On first sight, it looks just like another web debugger. So, why bother developing yet another web debugger?&lt;/p&gt;

&lt;p&gt;At the time, I used Charles Proxy and WireShark on a mac and Fidler on windows. Those tools are great!&lt;/p&gt;

&lt;p&gt;But, Fiddler was never great on platforms other than Windows. WireShark felt like using a surgical knife to slice bread.&lt;/p&gt;

&lt;p&gt;All of the above tools sometimes just give you too much information, for some, it takes too long to get them running. If you are dealing with non standard clients, like CLIs, microservices, web applications etc, you must know how to configure a proxy for them to work.&lt;/p&gt;

&lt;p&gt;All I needed is a tool to debug apis between client and server, I wanted it to take 2 seconds to start and get some data, and as a side bonus, I wanted it to work on Mac Windows and Linux. That is why I decided to write my own as a side project.&lt;/p&gt;

&lt;p&gt;So, I fired up my computer and started writing. Luckily, Electron was there when I started. So, after the first night (I work during the days), I had the basic functionality running!&lt;/p&gt;

&lt;p&gt;What can you do with Reversee?&lt;br&gt;
The core functionality is something like the network tab on chrome. You have a client, a server, and Reversee in the middle. You can see http requests, body, headers, responses. Basically, what you would expect from a web debugger.&lt;/p&gt;

&lt;p&gt;So, what is the difference?&lt;/p&gt;

&lt;p&gt;In Reversee, reverse proxy is a first class citizen. Internally Reversee uses reverse proxy to get the requests from the client and fire them to the server, just like NGINX does.&lt;/p&gt;

&lt;p&gt;Charles and Fidler mostly uses forward proxy, which has its benefits and drawbacks. &lt;/p&gt;

&lt;p&gt;This gives you the ability to simplify many things, consider the following use case.&lt;/p&gt;

&lt;p&gt;You are developing a web service that consumes info from some other web service (can be a public service, your own lambda function or whatever).&lt;/p&gt;

&lt;p&gt;We will call the first web service the client, and the other one the server. Assume the server can only accept https. Now, you want to see the traffic between those services.&lt;/p&gt;

&lt;p&gt;Using Charles, Wireshark or Fiddler, you will have to add some certificates for SSL/TLS proxy.&lt;/p&gt;

&lt;p&gt;Using Reversee you only need to set Reversee up to listen on http traffic and send https traffic, and to configure the client to use &lt;a href="http://localhost:" rel="noopener noreferrer"&gt;http://localhost:&lt;/a&gt;. No certificates headache is involved.&lt;/p&gt;

&lt;p&gt;Another cool feature of Reversee is request and response interceptors, you can run Javascript code on requests and responses. For example, assume you need to rename a header, change the response body, go to a different URL, etc. All can be easily achieved with a couple lines of code.&lt;/p&gt;

&lt;p&gt;Let's see an example how to use Reversee.&lt;br&gt;
We will work with &lt;a href="https://jsonplaceholder.typicode.com/" rel="noopener noreferrer"&gt;https://jsonplaceholder.typicode.com/&lt;/a&gt; as an example API. &lt;/p&gt;

&lt;p&gt;Start Reversee.&lt;br&gt;
Select http for the client protocol.&lt;br&gt;
Select a random high port that is not in use on your computer. We will use 9000 in our example.&lt;br&gt;
Select https for the server protocol.&lt;br&gt;
Switch it to on.&lt;/p&gt;

&lt;p&gt;See below: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fch36h8jzd6hepoqsdvol.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fch36h8jzd6hepoqsdvol.png" alt="Setup Reversee"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will use cURL for our example. &lt;/p&gt;

&lt;p&gt;Run the following command from commandline:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;curl http://localhost:9000/todos/1&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Look in Reversee and see your request:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fr1cf0vlxsgq4le7ox818.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fr1cf0vlxsgq4le7ox818.png" alt="Request 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This shows you how fast it is to start using Reversee. Notice that we are debugging an https endpoint. In most tools, this is not trivial! In other tools, you will have to install certificate in your machine and trust it. Here, we are using a trick. the client is using http and Reversee is using https to talk to the server, that is how we can see traffic going out from the client and coming back from the server.&lt;/p&gt;

&lt;p&gt;For clients that will not support http, but only https, you can also install Reversee's root certificate, but this is for another time.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Request/Response modifications&lt;/em&gt; - With Reversee you can change the Request or the Response using a few lines of code. This is useful for example if you want to add/modify header, change the request or response body, add a request query parameter, etc.&lt;/p&gt;

&lt;p&gt;For example, assume you are developing the client in this client-server and you need to develop a new feature that requires a new field in the response named rating. We can add it easily to the response.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Forbylyy54z28e8xyjmrw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Forbylyy54z28e8xyjmrw.png" alt="changing response body"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you haven't done so already, download Reversee and start (Web) debugging: &lt;a href="https://reversee.ninja" rel="noopener noreferrer"&gt;https://reversee.ninja&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>desktop</category>
      <category>network</category>
      <category>electron</category>
    </item>
    <item>
      <title>Auto-MAT - Analyse Java Heap Dumps From Commandline</title>
      <dc:creator>Gal Ben Ami</dc:creator>
      <pubDate>Sat, 28 Sep 2019 19:03:34 +0000</pubDate>
      <link>https://forem.com/jfrog/auto-mat-analyse-java-heap-dumps-from-commandline-10hg</link>
      <guid>https://forem.com/jfrog/auto-mat-analyse-java-heap-dumps-from-commandline-10hg</guid>
      <description>&lt;p&gt;A while ago, I had to analyse a large java heap dump, generated by one of our servers after a memory leak. This was hard. &lt;br&gt;
I usually use &lt;a href="https://www.eclipse.org/mat/" rel="noopener noreferrer"&gt;Eclipse MAT&lt;/a&gt; for the job, but this time, it was so large the tool could not parse the heap dump in an acceptable time, and required more and more memory.&lt;/p&gt;

&lt;p&gt;I eventually took a strong machine with GUI in the cloud and got it to work, but the experience was bad. I had to use GUI for that, because all the tools I knew back then required GUI to operate.&lt;/p&gt;

&lt;p&gt;Running a server with GUI in the cloud is not something I do every day, and it took some time to configure the server, start it, connect with remote desktop etc'.&lt;/p&gt;

&lt;p&gt;I figured there must be a better option. So I looked around, and discovered that you can let Eclipse MAT parse the heap dump from commandline!&lt;/p&gt;

&lt;p&gt;You can use a script that comes with the Linux installation of Eclipse MAT. The script will calculate indexes for later use in eclipse MAT and can also generate some nice HTML reports that are usually good enough to understand the problem.&lt;br&gt;
The index files will help Eclipse MAT open in seconds, instead of long hours.&lt;/p&gt;

&lt;p&gt;This is much better than the experience I had, I could run the script on a remote server from terminal, which is easy to set up, and I usually have a couple of servers ready to do some work for me.&lt;/p&gt;

&lt;p&gt;I've tried the script and it worked great. But, it comes only with the linux installation. What if I wanted to run it on Mac or Windows? Also, Eclipse MAT requires Java to be installed.&lt;/p&gt;

&lt;p&gt;So, I decided to wrap it in a docker container, and that is how &lt;a href="https://github.com/jfrog/auto-mat" rel="noopener noreferrer"&gt;Auto-MAT&lt;/a&gt; got created.&lt;br&gt;
Now every time I need to analyse a heap dump I could just run something like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;
 run -it --mount src=$(pwd),target=/data,type=bind docker.bintray.io/jfrog/auto-mat heap1.hprof 11g suspects,overview

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will parse the heap dump, create indexes and will generate nice 2 HTML reports. Suspects and Overview.&lt;/p&gt;

&lt;p&gt;After running this, it will usually be enough to open the HTML reports to understand the problem. But if you need a deeper drill down into the memory, you could open the heap dump with MAT and, since the indexes are already there, Eclipse MAT will open in a snap. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fstr2vc20iklwyht48vsr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fstr2vc20iklwyht48vsr.png" alt="Sample Report"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8dl0c47hg2ag7fvis69m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8dl0c47hg2ag7fvis69m.png" alt="Sample Repoet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, that was great, but if I needed a strong machine to run &lt;a href="https://github.com/jfrog/auto-mat" rel="noopener noreferrer"&gt;Auto-MAT&lt;/a&gt;, I would still have to find a machine, upload the heap dump, install docker if it is not installed, and then download everything back or store it somewhere.&lt;/p&gt;

&lt;p&gt;So, I decided to build an automation around it. First, I've asked my colleague to build a Jenkins job that will take a heap dump from a production server, and will upload it to Artifactory.&lt;/p&gt;

&lt;p&gt;Later I built a second Jenkins job that will download the heap dump from Artifactory and run Auto-MAT on it. The artifacts of Auto-MAT run will be uploaded back to artifactory.&lt;/p&gt;

&lt;p&gt;The second Jenkins job can be triggered by the first, or manually after someone has uploaded the heap dump to Artifactory.&lt;/p&gt;

&lt;p&gt;In this way, anyone in the organisation can analyse heap dumps with a click of a button. &lt;/p&gt;

&lt;p&gt;If you are planning to work with heap dumps in automation, I recommend to compress them, I use pigz which is a faster version of gzip. I used Artifactory to store the files for my automation, you can use anything else, but if you are using Artifactory check out &lt;a href="https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory" rel="noopener noreferrer"&gt;jfrog-cli&lt;/a&gt;, and especially the parallel download and upload features.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/jfrog/auto-mat" rel="noopener noreferrer"&gt;Auto-MAT&lt;/a&gt; is open source and you can visit the github page for more: &lt;a href="https://github.com/jfrog/auto-mat" rel="noopener noreferrer"&gt;https://github.com/jfrog/auto-mat&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>commandline</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
