<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Bleacher Report Engineering - Medium]]></title>
        <description><![CDATA[Bleacher Report‘s Engineering team manages two mobile apps and and a constellation of web products and custom tools. - Medium]]></description>
        <link>https://medium.com/bleacher-report-engineering?source=rss----ea01471dcd9---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Bleacher Report Engineering - Medium</title>
            <link>https://medium.com/bleacher-report-engineering?source=rss----ea01471dcd9---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 19:56:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/bleacher-report-engineering" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Diving into Distributed Tracing]]></title>
            <link>https://medium.com/bleacher-report-engineering/diving-into-distributed-tracing-ce9638025576?source=rss----ea01471dcd9---4</link>
            <guid isPermaLink="false">https://medium.com/p/ce9638025576</guid>
            <category><![CDATA[distributed-tracing]]></category>
            <category><![CDATA[opentracing]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[opencensus]]></category>
            <dc:creator><![CDATA[Greg Mefford]]></dc:creator>
            <pubDate>Tue, 28 May 2019 20:48:53 GMT</pubDate>
            <atom:updated>2019-05-28T20:48:53.320Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o5ZYb1N3jUUw-XNEXojQ4Q.png" /><figcaption>An example of a distributed trace across several back-end services</figcaption></figure><p>At Bleacher Report, we have gotten a lot of value out of splitting up our monolithic Rails codebase into several smaller services, mostly using Elixir. We were able to significantly reduce the number of server instances we needed to absorb our large traffic spikes. Today, we operate a couple of dozen services, which are written in several languages, including C#, Elixir, NodeJS, and Ruby. We choose technologies to use for each new service based on a number of technical and organizational factors, so we need to make sure that our tools will be compatible across our whole infrastructure. One of the big challenges that came with this transition to a multi-service architecture was observability. As we added more services, it was increasingly difficult to establish the right set of vendors, libraries, and integrations to allow us to get a cohesive picture of what was going on. It was hard to diagnose where the problems were when we had high latency, high error rates, or time-outs during a big traffic spike. We often had to make a guess based on gut feeling and past experience, then hypothesize and verify with metrics and logs.</p><h3>Distributed Tracing</h3><p>For a good, in-depth intro on what distributed tracing is and how it works, check out <a href="https://www.roguelynn.com/words/tracing-fast-and-slow/">Lynn Root’s blog post about it</a> and the accompanying conference talk. I also recently gave a talk called “Continuous Tracing in Production” at Code BEAM STO 2019, so <a href="https://github.com/GregMefford/presentations/releases/tag/2019-code-beam-sto">check out the slides</a> and look for the video of that when it is posted.</p><p>The fundamental concepts of distributed tracing are <em>traces</em>, <em>spans</em>, and <em>context propagation</em>. Each <em>span</em> in a <em>trace</em> has a name, a range of time during which that operation happened, and some other metadata that can be associated with it. Spans know what their parent span is and what trace (i.e., related group of spans) they belong to. Context propagation is the process by which one service can tell another service how to connect its spans into the overall trace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vR8dNoiJyiaP_BS_P-IMxg.png" /><figcaption>Tracing and context propagation overview</figcaption></figure><p>Context propagation is required so that downstream services can contribute their spans to the overall trace, without having to send that data back to the upstream services. Instead, they send their spans directly to the trace collector, using the same trace ID as the upstream service, so that the collector can connect them all together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vmIZ6cUp0o7g3kZjkljpXg.png" /><figcaption>Each node sends its spans directly to the trace collector</figcaption></figure><h3>Getting Started</h3><p>With basic logging and metrics in place, filling in the distributed tracing gap was difficult to prioritize over other things. In mid-2018, we were able to allocate some time to really focus on improving our observability and monitoring across services. Our initial research led us to <a href="http://opencensus.io/">OpenCensus</a> as a great option that would allow us to aggregate metrics and traces by instrumenting our code with a unified set of vendor-neutral libraries and protocols. At that time, the <a href="https://github.com/opencensus-beam">opencensus-beam</a> project didn’t offer any simple drop-in integrations for our Elixir-based services, and we weren’t prepared to invest until it was clear that there was value for us in distributed tracing as a technology. We also wanted to avoid operating our own trace-collection infrastructure.</p><p>We evaluated several vendor-specific solutions but in the end decided that Datadog APM fit best with our Datadog-based metrics and alerting infrastructure we already had in place. Datadog APM supports a similar standard to OpenCensus, called <a href="http://opentracing.io/">OpenTracing</a>. When we started the evaluation, they already had first-party support for C#, NodeJS, and Ruby (among others). There was no first-party support for Erlang or Elixir, but based on feedback from both Datadog and the Elixir community, we chose the <a href="https://github.com/spandex-project">Spandex</a> library to integrate with our Elixir-based services.</p><h3>Instrumenting the Code</h3><p>We rolled out our Datadog APM instrumentation to our various services using a staged approach:</p><ol><li>Pick a few interconnected services</li><li>Add some easy tracing integrations with popular libraries</li><li>Get them running in production</li><li>Verify that complete distributed traces are showing up</li><li>Iteratively add more services and more manual instrumentation</li></ol><p>Regardless of which language a given service is using, the second step was mostly a matter of configuration to hook into the instrumentation APIs provided by the libraries we use. For example, for Elixir-based services, it’s pretty easy to integrate with <a href="https://github.com/spandex-project/spandex_phoenix">spandex_phoenix</a> and <a href="https://github.com/spandex-project/spandex_ecto">spandex_ecto</a> (there’s even a <a href="https://github.com/spandex-project/spandex_example">spandex_example</a> project that has GitHub diff links in the README that show exactly what to do). For Ruby-based services, there are <a href="https://github.com/DataDog/dd-trace-rb/blob/master/docs/GettingStarted.md">quite a few supported libraries</a> that can be easily instrumented by configuring a few options. In the image at the top of the article, for example, we can see a distributed trace originating from a user-facing service at the top and passing through HTTP calls to various downstream services. The details of each span are not shown in this image, but they were nearly all generated by one of the “easy integrations.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GxavxIumzP7DqbeUlcFT7Q.png" /></figure><p>The fifth step is also easy to do, but it comes with some initial challenges in deciding what to trace, what conventions to use, and how to deal with idiosyncrasies of each runtime. For example, the Datadog-provided libraries for Ruby use a lot of meta-programming magic to add instrumentation to various libraries without those libraries needing to know anything about tracing. With Elixir being more explicit about where code is defined, it’s necessary to use macros or function decorators to specifically mark where we wanted to add manual tracing to the codebase.</p><p>One specific issue we struggled with in Elixir is that Spandex uses the Process Dictionary to maintain the state of the trace in a process. That means that when doing work asynchronously, we needed to pass the trace context from the parent process to the child process, so that the child could continue adding spans to the same trace, in the same way that a downstream HTTP call needs to propagate the trace state using HTTP headers. For example, we use code like the following to transparently call Tracer.async/1 when we would normally call Elixir’s <a href="https://hexdocs.pm/elixir/Task.html">Task.async/1</a> function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c88ad2fa28bb02da01fa63ac6c7bf11a/href">https://medium.com/media/c88ad2fa28bb02da01fa63ac6c7bf11a/href</a></iframe><h3>Low-Hanging Fruit</h3><p>Adding this new dimension of observability to our services allowed us to immediately see some things that weren’t obvious before. For example, when a request is slow, we can now get a much better understanding of whether it’s because of downstream HTTP calls, inefficient database queries, or simply heavy in-memory processing operations. Traces allow us to see into a sampling of the details that make up our aggregated time-series metrics, which was all we had in the past. Seeing the trace visualized makes it much easier to say, “wait…why is it doing that?” and then go to the code and make an improvement. It also allows us to more easily apply <a href="https://en.wikipedia.org/wiki/Amdahl%27s_law">Amdahl’s Law</a> when making our performance improvements by investing our effort where it will matter the most in practice.</p><p>Another clear advantage of distributed tracing is that it allows us to see our errors and stack-traces in the broader context of how we got into a bad state. For example, we can see in the following trace that there is an error being raised in one of the downstream service calls (denoted by the red outline around one of the blue spans), but it is being handled and not causing the higher-level service to also fail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dg89vz8IGK2TxGMzKAEN9A.png" /></figure><p>If we click on that error span, we can see the error message itself, along with the stack-trace, showing where within that codebase the error happened. Since we can set metadata on various spans throughout the trace, it makes the process of reproducing the error much easier, because we can see what the URL was that led to the error. We might also be able to see what the relevant query or body parameters were, if we chose to include them as metadata on the spans.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IdpHVFZX_rjzGIqVeHme5w.png" /></figure><h3>Culture Change</h3><p>Perhaps the most important outcome from our deployment of distributed tracing has been the shift in the way we respond to alerts and troubleshoot bugs. Before, we had to bring up a dashboard of a lot of metrics and theorize about why one or the other of them had a dip or a spike in it. We could look for errors in the logs, but more often than not, there was no error associated with a slow request or an unexpected response. Now, we can share a link to a particular trace and discuss what’s happening and why. We can look for traces of slow requests or traces that resulted in an error. All of our teams from development to operations and QA are using the same tools to monitor performance in production, test new code in staging, and investigate errors.</p><h3>Trace Sampling</h3><p>An important consideration when using distributed tracing at scale is how to sample the traces that get sent to the collector. As of this writing, <a href="https://github.com/spandex-project/spandex/issues/42">Spandex does not have full support for trace sampling</a>, mainly because Datadog APM uses the traces to measure aggregate service metrics, which would be incorrectly counted when using priority sampling with distributed traces. This lack of sampling support can significantly contribute to performance issues under heavy load. There <a href="https://hexdocs.pm/spandex_datadog/readme.html">are options</a> to control the number of traces sent to Datadog APM per batch and the number of concurrent batches to send before applying synchronous back-pressure, but all of the traces are ultimately sent over HTTP to the Datadog Agent regardless of sampling priority. One technique we’ve used to mitigate this issue is to <a href="https://hexdocs.pm/spandex_datadog/readme.html">override the default</a> HTTPoison client that Spandex uses to send traces, <a href="https://github.com/benoitc/hackney#use-the-default-pool">specifying a dedicated hackney pool</a>, which will allow us to control the number of connections used for tracing so that the rest of the system isn’t bottlenecked when trying to make HTTP requests using the default pool.</p><h3>The Future: OpenTelemetry</h3><p>The worst thing about both OpenCensus and OpenTracing has always been that <a href="https://www.cncf.io/blog/2019/05/21/a-brief-history-of-opentelemetry-so-far/">they both exist, and they’re very similar but incompatible</a>. Those days are finally coming to an end because OpenCensus and OpenTracing projects are in the process of <a href="https://medium.com/opentracing/a-roadmap-to-convergence-b074e5815289">merging into a combined project</a> called <a href="https://opentelemetry.io/">OpenTelemetry</a>. The first release of OpenTelemetry is intended to be considered the next major release of both OpenCensus and OpenTracing. The idea is to try to make the transition as smooth as possible for clients of either of the existing projects and to sunset the existing projects by the end of 2019. This is great news for each of the projects and for the overall distributed tracing community, because it will mean that more people are working on, and using, the same set of technologies. For example, the Spandex maintainers are already teaming up with the OpenCensus-BEAM maintainers to work on the transition toward standardized OpenTelemetry support for BEAM languages.</p><h3>Conclusion</h3><p>At Bleacher Report, we’ve seen a lot of benefit from investing in distributed tracing in addition to our logs and metrics. Some of them were what we expected, but others were a welcome surprise. If you are interested in distributed tracing, we recommend that you get started on the <a href="http://opencensus.io/">OpenCensus</a> path and follow along as the <a href="https://opentelemetry.io/">OpenTelemetry</a> project convergence efforts continue to merge these projects into a unified telemetry platform for distributed tracing as well as metrics and logs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce9638025576" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bleacher-report-engineering/diving-into-distributed-tracing-ce9638025576">Diving into Distributed Tracing</a> was originally published in <a href="https://medium.com/bleacher-report-engineering">Bleacher Report Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working Remotely at B/R]]></title>
            <link>https://medium.com/bleacher-report-engineering/working-remotely-at-b-r-fac57de65810?source=rss----ea01471dcd9---4</link>
            <guid isPermaLink="false">https://medium.com/p/fac57de65810</guid>
            <category><![CDATA[office-culture]]></category>
            <category><![CDATA[remote-working]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Alexander Quine]]></dc:creator>
            <pubDate>Fri, 24 May 2019 17:03:44 GMT</pubDate>
            <atom:updated>2019-05-24T17:06:03.062Z</atom:updated>
            <content:encoded><![CDATA[<h3>Working Remotely at Bleacher Report</h3><p>Ever wonder what it’s like to work at B/R from the comfort of your own home?</p><p>Joe McLaughlin, Functional Lead for iOS Engineering, detailed <a href="https://josephmclaughl.in/posts/working-remotely/">his experiences working remotely with B/R Engineering for the last three years</a>. Visit <a href="https://josephmclaughl.in/">his blog</a> and check it out!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qSkJ0bzk0nLWyioOCB5I6g.png" /><figcaption>The record player and vinyl are not part of our remote employee setup… (But maybe they should be??)</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fac57de65810" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bleacher-report-engineering/working-remotely-at-b-r-fac57de65810">Working Remotely at B/R</a> was originally published in <a href="https://medium.com/bleacher-report-engineering">Bleacher Report Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Not Just Tests: Automating QA Workflows]]></title>
            <link>https://medium.com/bleacher-report-engineering/not-just-tests-automating-qa-workflows-725d375302e2?source=rss----ea01471dcd9---4</link>
            <guid isPermaLink="false">https://medium.com/p/725d375302e2</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[qa]]></category>
            <category><![CDATA[robot-framework]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[marisa kemnitz]]></dc:creator>
            <pubDate>Fri, 10 May 2019 22:51:29 GMT</pubDate>
            <atom:updated>2019-05-11T01:52:08.695Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*mPktNMEln0Q4yucCWhsn8A.jpeg" /><figcaption><a href="https://www.flickr.com/photos/peyri/34685785/in/photolist-44LSM-TjsJdh-24C7oTn-NVpBtS-21b26qD-2aKk5aM-5wz4xp-25iNi6P-2df7fnU-DFxLeX-22TUHgL-bjRtsJ-VmJLU1-fzYPHV-36Dmfn-8zuB47-7gxHSL-5j2BC7-5Uv8vT-5gK7gA-ntxtWP-27YrN3W-qJ7UDS-o8R9jC-fuZq6-8hda9Q-8Cy1yW-27jVJHk-2cTbaVs-SPGV9G-nqB2PM-pDxdH3-PzyFH-8ua1MR-5qC9tk-jw71uM-pYbwte-SuVksN-2aptGYs-HMfweo-239f3Gi-iSKBju-Yv9RpJ-4wXkbd-25HBZ4x-FxqdvF-286naBU-TkFs3j-piS1FB-borLQL">“purple robot” by Peyri Herrera</a></figcaption></figure><p>A little over a year ago, we started building a QA tool that would automate most of our daily tasks outside of our automated tests. The tool, which we dubbed the QA Robot, would help us scale along with our fast-growing development team and allow us to focus on more important aspects of quality.</p><p>The tasks that we identified as being automatable were:</p><ul><li>Deploying a ticket to a staging environment</li><li>Verifying that a pull request is mergeable</li><li>Running automated tests and reporting the result</li><li>Deploying a ticket to the production environment</li></ul><p>To make building this tool a little less daunting, we broke it into a few phases:</p><p>Phase 1: Testing on staging</p><ul><li>Deploying to staging</li><li>Verifying pull requests</li><li>Running automated tests</li></ul><p>These areas are pretty straightforward and are good wins for the QA team.</p><p>Phase 2: Learning and making improvements</p><p>We knew we weren’t going to get it right the first time, so we made sure to give ourselves time to learn from our mistakes and make improvements.</p><p>Phase 3: Deploying tickets to production</p><p>This was tricky, potentially risky, and we wanted to be sure we had it right.</p><h3><strong>Decisions</strong></h3><p>We decided to use Python primarily because of its abundance of libraries that would make this easier to solve — plus, a few members of our team were already familiar with the language. Our script uses the Jira API library to identify which tickets to test, then uses the GitHub API library to determine if the pull request is actually ready for testing. We use the Jenkins API library to deploy our code.</p><p>We used <a href="https://robotframework.org/">Robot Framework</a> in the QA Robot since it’s an automation framework built on Python, making it easy to integrate with our script. This required us to spend time converting our existing tests from Cucumber to Robot Framework before fully rolling out. This was no small task in and of itself. We converted a few tests at first and made sure they’d work well with the QA Robot. Once we saw that the integration of running our tests after the script deployed the code and updating Jira tickets with the results was seamless, we moved forward with converting the rest of our tests.</p><h3><strong>Learnings</strong></h3><ul><li>Because our script calls many third-party services (GitHub, Jenkins, Jira), we are often troubleshooting issues and adjusting our code to accommodate when their systems presented issues.</li><li>Process plays a huge part in success for this project. We rely on users to create pull requests and update Jira in standardized ways. This is facilitated by having detailed documentation, constant communication and training sessions.</li><li>As the QA Robot matured and started picking up more tickets, more tests were running concurrently, so we needed to look for ways to be efficient. One way we accomplished this was to wait for dependent services to be in a good state and then only running the tests once, then combined the results into one report at the end of the run.</li><li>Providing instant feedback on the failures is needed to build trust in the QA Robot. We are careful to monitor tickets that have not passed the automated tests, and having a dedicated, stable and reliable test environment is crucial.</li></ul><h3><strong>Completion</strong></h3><p>We recently rolled out the final phase: automatic deploys to production. Fortunately, we were able to reuse much of the code created in the earlier phases for rerunning tests and deploys.</p><p>We scheduled these deploys to run twice a day and set up a rotation so someone is monitoring the status of each deploy. This allows us to have predictable releases and reduces the workload of having each person responsible for their own release.</p><h3>Metrics</h3><p>Here is an idea of the number of tickets handled by the QA Robot since we completed each phase:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MAXXmaGqTy3jCY6c4llkhQ.png" /></figure><h3><strong>Conclusion</strong></h3><p>The QA Robot saves us a ton of time — about an hour of each individual’s day — and allows us to focus on improving quality at a higher level. Time can be spent doing more exploratory testing. We can shift toward writing test automation while developers are writing new features that aid in delivering features faster. Automation presents opportunities for growth to the QA team, such as release management. We can also automate other manual and repetitive QA tasks by building more tools like this.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=725d375302e2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bleacher-report-engineering/not-just-tests-automating-qa-workflows-725d375302e2">Not Just Tests: Automating QA Workflows</a> was originally published in <a href="https://medium.com/bleacher-report-engineering">Bleacher Report Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview w/Miguel DeAvila, SVP Engineering]]></title>
            <link>https://medium.com/bleacher-report-engineering/interview-w-miguel-deavila-svp-engineering-aa58c1ec1058?source=rss----ea01471dcd9---4</link>
            <guid isPermaLink="false">https://medium.com/p/aa58c1ec1058</guid>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[management]]></category>
            <dc:creator><![CDATA[Miguel DeAvila]]></dc:creator>
            <pubDate>Fri, 15 Mar 2019 19:28:19 GMT</pubDate>
            <atom:updated>2019-03-15T19:28:19.344Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZfH9xUA9j3J6Nrfle9lHGw.png" /></figure><p>Interview w/Miguel DeAvila, SVP Engineering</p><p>What is Bleacher Report? Advice/Challenges? Did you ever find the magic ball-bearings?</p><p>It was great being on Change Wave with Tim Nicklas from Treehouse!</p><p>Check it out: <a href="https://trhou.se/CW-MiguelDeAvila">https://trhou.se/CW-MiguelDeAvila</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa58c1ec1058" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bleacher-report-engineering/interview-w-miguel-deavila-svp-engineering-aa58c1ec1058">Interview w/Miguel DeAvila, SVP Engineering</a> was originally published in <a href="https://medium.com/bleacher-report-engineering">Bleacher Report Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lonestar ElixirConf 2019 Recap]]></title>
            <link>https://medium.com/bleacher-report-engineering/lonestar-elixirconf-2019-recap-905b59fbee12?source=rss----ea01471dcd9---4</link>
            <guid isPermaLink="false">https://medium.com/p/905b59fbee12</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[phoenix-framework]]></category>
            <dc:creator><![CDATA[Jason Stewart]]></dc:creator>
            <pubDate>Fri, 15 Mar 2019 19:12:28 GMT</pubDate>
            <atom:updated>2019-03-15T19:07:39.929Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gzNa-Xf5UF785gwzIWDNpg.jpeg" /></figure><p>Lonestar ElixirConf 2019 took place February 28 thru March 2 in Austin, Texas. Several engineers from Bleacher Report attended the conference, and three of them, Greg Mefford, Chris Keathley, and Ben Marx, led training classes. I enjoyed my time at the conference, and the following is a recap of some of the highlights from the three days in Austin.</p><h3>Distributed Elixir</h3><p>Elixir is well known for its distributed computing abilities. The language, OTP, and the BEAM platform provide out-of-the-box functionality that make concurrent and distributed computing first-class citizens. However, among many new and mid-level Elixir developers it still remains a mystery of how to utilize these tools in a useful way. And there is a reason for that; doing distributed computing correctly is a very hard problem, and most people don’t actually need it.</p><p>Two members of the Bleacher Report engineering team, Ben Marx and Chris Keathley, conducted a full-day training class devoted to building resilient, distributed systems using Elixir. The class started out introducing the basic Elixir constructs for distributed programming such as nodes and processes and discussed some of the common fallacies of distributed systems (e.g., networks are reliable, zero latency between nodes, etc). Building off of this, Ben and Chris discussed local caching using <a href="http://erlang.org/doc/man/ets.html">ETS</a>, process grouping using the <a href="http://erlang.org/doc/man/pg2.html">PG2 module</a> and finished by discussing CRDTs and how they can be used to maintain consistent state among multiple nodes. There were several exercises that the class worked on during the training to put these principles into action, including a distributed implementation of MapReduce.</p><p>The training was very informative and very popular (the training was sold out). Even for those familiar with the underlying distributed computing constructs of Elixir, the training provided an opportunity to put these ideas into practice in ways you may not have thought of doing in the past.</p><p>I know Ben and Chris are planning on offering this training at <a href="http://www.elixirconf.eu/">ElixirConf EU</a> this year and may offer it again at other future conferences. If you are interested in learning more about distributed computing with Elixir, I highly recommend attending this training if you have the opportunity.</p><h3>Phoenix LiveView</h3><p>By now most people have probably at least heard of Phoenix LiveView. Chris McCord introduced the exciting new technology at ElixirConf last year, and many people have eagerly been awaiting its release since then.</p><p>For those unfamiliar with LiveView, it is an Elixir-based alternative to using a JavaScript framework like React to render dynamic HTML client-side in the browser. It utilizes Phoenix channels to send HTML content that can be dynamically updated as needed from a Phoenix application. Chris McCord provides a great overview of LiveView on the <a href="https://dockyard.com/blog/2018/12/12/phoenix-liveview-interactive-real-time-apps-no-need-to-write-javascript">Dockyard blog</a>.</p><p>Chris’ keynote demoed many of the same features detailed in the blog post. First, he showed a prototype of a smart thermostat that dynamically updated based on user input to illustrate how the LiveView templates work within a Phoenix application. He then showed the classic game Snake implemented using LiveView. This showcased the performance aspects of the technology where there was no distinguishable lag from rendering while he played a few games for the audience. Although network latency was not an issue for his demo because he was running and playing the game on the same machine, it was an impressive demonstration nonetheless.</p><p>We are excited about LiveView at Bleacher Report and have been evaluating if it would be a good fit for some of the projects we are working on. We don’t envision it being a full replacement for all of the projects we use JavaScript for, but for some smaller internal projects, it is potentially a great fit.</p><p>LiveView was just released, and we are excited to start experimenting with it now that it is available to the public.</p><h3>Broadway</h3><p>José Valim’s keynote focused on two major topics. The first was the announcement of the Erlang Ecosystem Foundation (EEF), which was first announced at Code BEAM SF the day before he gave his keynote presentation. I’ll go into more detail about the EEF a little later.</p><p>The second topic was the release of the Broadway library. Broadway is a library built on top of <a href="https://hex.pm/packages/gen_stage">GenStage</a> that allows developers to set up processing pipelines for data sources. A thorough discussion of the library can be found on the <a href="http://blog.plataformatec.com.br/2019/02/announcing-broadway/">Plataformatec blog</a>. The list of features that Broadway provides includes:</p><ul><li>Back-pressure</li><li>Automatic acknowledgments</li><li>Batching</li><li>Automatic restarts in case of failures</li><li>Graceful shutdown</li><li>Built-in testing</li><li>Partitioning</li></ul><p>One of the more exciting features of Broadway is that it can be connected to a variety of different types of data sources. We utilize Kafka and RabbitMQ for several of our services at Bleacher Report, and being able to create processing pipelines consistently regardless of the data source could be a huge win for us.</p><p>Broadway has been released to the public but is still in the early stages of its development. Currently, there is support for Amazon SQS, and additional support and features for other data sources are planned for the future.</p><h3>Moving Forward</h3><p>There were two big announcements that pertain to the future of Elixir and Lonestar ElixirConf. The first, as mentioned before, is the creation of the Erlang Ecosystem Foundation (EEF). The EEF is focused on unifying efforts for languages and technologies that use the BEAM platform. The EEF goal, according to its mission statement, is “to grow and support a diverse community around the Erlang and Elixir Ecosystem, encouraging the continued development of technologies and open source projects based on/around its runtime and languages.”</p><p>With the core of Elixir being “done,” it is important to have a group like the EEF to ensure the community has the support necessary to continue to build the ecosystem on top of the core language.</p><p>More information about the EEF can be found on the organization’s <a href="https://erlef.org/">website</a>.</p><p>The second announcement was that Bruce Tate would be taking over planning and organization for Lonestar ElixirConf, which is being renamed to Lonestar Elixir. It is fantastic that Bruce will be organizing this conference in the future. He is the organizer of the Gig City Elixir conference, which in its inaugural year received nothing but rave reviews.</p><p>Bruce has a great pulse on the community. In his conference talk, titled “Elixir.next,” he focused on where Elixir has come from and where it needs to go. He has been a part of the Elixir community since the beginning and is committed to seeing it continue to grow and flourish. It will be exciting to see what the future holds for the conference with Bruce leading the charge.</p><h3>Final Thoughts</h3><p>I feel very fortunate that I get to work in Elixir professionally. It is not only a great language, but the community is full of awesome, smart people doing really cool things with the language. I enjoy attending conferences like Lonestar ElixirConf to meet many of these people in person and hear about new and exciting things happening in the ecosystem. I typically come away with new perspectives and ideas that I can’t wait to try out and put into practice.</p><p>I would encourage anybody interested in Elixir to attend this conference next year or any of the other Elixir conferences that happen throughout the year. It’s the perfect opportunity to be a part of the community and get inspired about Elixir.</p><h3>Resources</h3><ul><li><a href="https://www.youtube.com/channel/UCOy-_b9bqjokoWX9Hg5ZgUg">Lonestar ElixirConf talks</a></li><li><a href="https://hex.pm/packages/broadway">Broadway Hex page</a></li><li><a href="https://github.com/phoenixframework/phoenix_live_view">Phoenix LiveView GitHub repository</a></li><li><a href="https://erlef.org/">Erlang Ecosystem Foundation website</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=905b59fbee12" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bleacher-report-engineering/lonestar-elixirconf-2019-recap-905b59fbee12">Lonestar ElixirConf 2019 Recap</a> was originally published in <a href="https://medium.com/bleacher-report-engineering">Bleacher Report Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Delicate sensibilities: techniques to block offensive usernames]]></title>
            <link>https://medium.com/bleacher-report-engineering/delicate-sensibilities-techniques-to-block-offensive-usernames-1dbdfdd1f994?source=rss----ea01471dcd9---4</link>
            <guid isPermaLink="false">https://medium.com/p/1dbdfdd1f994</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[bleacherreport]]></category>
            <dc:creator><![CDATA[Peter Hastie]]></dc:creator>
            <pubDate>Tue, 05 Jun 2018 18:43:37 GMT</pubDate>
            <atom:updated>2018-06-05T00:35:40.695Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cl_z2QH676zmUYTVsipDQA.jpeg" /></figure><p>We’re making some big changes to the B/R app that we hope will make it a more interesting and useful place for people to spend time. Although Bleacher Report doesn’t require an account to read our content, we hope that people will create accounts to take advantage of the exciting new features we’ll be offering. In order to foster a vibrant community where everyone feels welcome, we’ve been doing some work on the backend to discourage spammy and offensive usernames during the signup process.</p><p>Over the years we’ve accumulated a frankly shocking list of the creatively offensive terms people have entered into our site. When users create a new account, the Elixir backend checks the string terms against this list to ensure they don’t contain any of these unwelcome words.</p><p>We can’t treat all profanity the same way, though, because of the <a href="https://en.wikipedia.org/wiki/Scunthorpe_problem">Scunthorpe problem</a>. Rather than an alias for a 19th-century pugilist, this describes the tendency of filters of this type to flag perfectly innocent words that happen to contain a substring from our list. We’ve tried to avoid this by running three separate comparisons.</p><ol><li>Check if the user term contains any substrings from the profanity list.</li><li>Check if the user term is exactly equal to a string in the exact profanity list, which contains mostly shorter words that are likely to be found in regular words and names.</li><li>Check if the user term contains any substrings from a separate list but allow certain exceptions that we’ve been made aware of through user feedback.</li></ol><p>In order to illustrate this without traumatizing the reader, I will use the lists from a more innocent time, from back when the site was simply “An Upstanding Victorian’s Report from the Bleachers.”</p><pre>{<br>  profanity = [<br>    &quot;arsenic&quot;,<br>    &quot;bloomers&quot;,<br>    &quot;bosom&quot;,<br>    &quot;bounder&quot;,<br>    &quot;fustilugs&quot;,<br>    &quot;suffrage&quot;,<br>    &quot;zounderkite&quot;<br>  ],<br>  exact_profanity = [<br>    &quot;cad&quot;,<br>    &quot;gin&quot;<br>  ],<br>  overridden_terms: {<br>    &quot;bottom&quot;: [&quot;winterbottom&quot;],<br>    &quot;free&quot;: [&quot;freeman&quot;]<br>  }<br>}</pre><p>Our SpamFilter module is a GenServer which loads the profanity list into state when it initializes, then each call to the GenServer uses String.contains?/2 to test for profanity within the user’s string. Since the second argument to this function can be a list of strings, we can check against the full list in one call. This function almost seems to be designed for this use case, but it’s not without its limitations.</p><p>One technique users employ to circumvent the filter is to replace letters with numbers. A proper cad might choose the username 4r53n1c or 3100mers to confound the filter. Rather than adding all the possible variations to the lists themselves, it makes sense to convert the numbers in the username back to letters and compare as normal. The problem in this example is that 1 is being used to represent both i and l, and 3 is being used to represent both B and e. Given that a username can have 16 characters, our worst-case username 1111111111111111 has 2¹⁶ permutations. That would mean calling String.contains?/2 65,536 times! Even for a less dramatic example, comparing against the full list of profanity words each time is inefficient.</p><p>A more appropriate data structure for the profanity words would be a <a href="https://en.wikipedia.org/wiki/Trie">trie</a>, a specialised tree that places each character of the word at a node. In our case a node can have up to 26 children, one for each alphabet character. Searching the trie means descending through the tree, comparing each node to the next character in the string until a leaf is found. This data structure is perfect for our purposes: We can do the hard work of building the trees once when the GenServer initializes; after that, each lookup has a worst-case run time bounded by the length of the user term and is only marginally affected by the number of terms in the list.</p><p>In Elixir we can represent the trie as a series of nested maps.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4238ee99a30075c266e9b2ddfe1fc9cc/href">https://medium.com/media/4238ee99a30075c266e9b2ddfe1fc9cc/href</a></iframe><p>To check for the word bounder we would first check the b node at the top level, then check for o as a child of that node, continuing through each character until we see that the final character r is marked as a leaf, meaning we found a match. In contrast, we will not find a match for bouncer because once we’re at the b-&gt;o-&gt;u-&gt;n node we see that there is no key c, only d.</p><p>Building the tree requires just a small amount of recursive code. This example assumes that the list doesn’t contain any substrings of other words on the list. For example, suffragette shouldn’t be in the list because suffrage is present and will match both. This use case allows us to use a simplified trie where a node can either be a parent or a leaf, but not both.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/694b2c3feb300f367374d8e7f20ad8ce/href">https://medium.com/media/694b2c3feb300f367374d8e7f20ad8ce/href</a></iframe><p>The search code is similarly terse. At each node we attempt to fetch the value stored at the key corresponding to the current letter we’re matching. We call the search function recursively with that value as the next node. If the value was another map, we repeat the process for the next letter. If not, the function terminates, returning false if a :leaf atom was found, indicating our string matched a word from the list and is not valid. To test for substrings, as in the example below, we check each character in the string against the root of the tree; this is not necessary when checking for an exact match.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ba5d3761b1a66a7b17fc7d053baeaf7/href">https://medium.com/media/3ba5d3761b1a66a7b17fc7d053baeaf7/href</a></iframe><p>With these basics in place, implementing the new feature to handle the different translations of digits is a breeze. A new check_char clause for each digit to be translated can be added before the final clause; Elixir will pattern match the arguments to the appropriate clause. When 3 is encountered, we first check for the key b at the current node and follow that branch until a leaf is found. If no leaf is found, we return to the node we were at and do the same thing for the key e — we don’t need to reprocess the part of the string that we’ve already checked.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a806be13af96bb8ede9062cda8efcac/href">https://medium.com/media/3a806be13af96bb8ede9062cda8efcac/href</a></iframe><p>The chart below shows the time taken to filter 10,000 16-character usernames containing only alphabet characters against a profanity list containing 152 words. The benchmark uses Enum.filter/2 to filter the list of autogenerated usernames against the !String.contains?/2 and Trie.valid_word?/2 implementations in turn, yielding approximately 6,900 valid usernames in each run. On macOS running Elixir 1.5, the trie implementation is about 8 times faster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*l68fffocHjFMFU8wy3jI8Q.png" /></figure><p>Hopefully these efficiency gains allow us to keep improving the filters while providing a smooth experience for new signups. The filter is unlikely to ever be perfect, though, and we will be relying on human moderators to remove any undesirable names that do get through. And if anyone feels that the filter is being too aggressive in rejecting their input, please reach out to us through the Send Feedback button in the app.</p><p><em>Header image courtesy of </em><a href="http://www.victorianweb.org/art/illustration/dumaurier/trilby/113.html"><em>Philip V Allingham</em></a><em>. Thanks to Pancham Mehrunkar for the implementation of the </em><em>check_char/2 translation clause.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1dbdfdd1f994" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bleacher-report-engineering/delicate-sensibilities-techniques-to-block-offensive-usernames-1dbdfdd1f994">Delicate sensibilities: techniques to block offensive usernames</a> was originally published in <a href="https://medium.com/bleacher-report-engineering">Bleacher Report Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Passive Transparency]]></title>
            <link>https://medium.com/bleacher-report-engineering/passive-transparency-3fde5f7323b9?source=rss----ea01471dcd9---4</link>
            <guid isPermaLink="false">https://medium.com/p/3fde5f7323b9</guid>
            <category><![CDATA[management]]></category>
            <dc:creator><![CDATA[Miguel DeAvila]]></dc:creator>
            <pubDate>Mon, 19 Mar 2018 21:46:37 GMT</pubDate>
            <atom:updated>2018-03-19T21:46:37.013Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XvPOe8i_PCHv0iPEPUab5w.jpeg" /><figcaption>Licensed under Creative Commons. <a href="https://creativecommons.org/licenses/by/2.0/">Some rights reserved</a> by <a href="https://www.flickr.com/photos/cpstorm/">C.P.Storm</a></figcaption></figure><p>Sitting at the head of the engineering org, I need clarity on statuses and priorities from my teams. I can consume a lot of information, and I can follow up on needful topics, but the team is too big and moving too quickly (yay!) for me to run everything down myself.</p><p>On smaller teams, status is shared as a natural side effect of “sitting close” (either virtually or in real life). It gets harder as your team grows; there are too many people and too many communication channels. You want your team to act decisively based on your strategic input, but you sure would like to know what your engineers are doing and how their work is going.</p><p>The phrase that I use on this topic at B/R is “passive transparency.” I want reasonable detail on status (that’s the transparency part), but I want that information coming to me passively (I don’t expect to participate in all the email threads, Slack channels and meetings whereby the state of things becomes known).</p><p>There are two dimensions in play here:</p><ol><li>Active versus Passive — How actively should you gather/synthesize the info that’s flying around?</li><li>Transparent versus Opaque — How much visibility do you need?</li></ol><p>For myself, I’m aiming for mid-level transparency (I need enough detail to assess risk and maintain accountability) and to be passive in how I receive the information (so I can consume a lot of it).</p><p>You’ll have to calibrate to what is appropriate for you and your org at a given stage. If you haven’t yet established sufficient trust with your team, then you may have to become more active (so you have greater transparency).</p><p>As your team grows, you’ll likely need to recalibrate the active/passive dimension more quickly than the transparency dimension. Your ability to gather and synthesize project status will degrade more quickly than your need for visibility.</p><p>If you have engineering management layers, then each layer will also likely strike a different balance. Roughly speaking, as you move down the engineering management ladder, the need for transparency increases, and so does the demand to pursue information actively.</p><p>Here’s what it looks like, XKCD-style,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*7Elp6ib6NftQBtJyluAdjQ.png" /><figcaption>h/t <a href="http://jakevdp.github.com/blog/2012/10/07/xkcd-style-plots-in-matplotlib/">Pythonic Perambulations</a> by Jake Vanderplas</figcaption></figure><p>Exactly where these roles (Manager, Director, VPE) land on the two dimensions will vary across orgs … don’t get stuck on it! Rather, use the transparency and level-of-effort dimensions to consider and adjust the information flow in your org.</p><p>How you respond to the specific information that’s coming your way is another consideration entirely. For example, you can use transparency for harmful (squelch risk-taking, shoot the messenger) or healthful (acknowledge and encourage risks, support honesty and inquiry) ends. That is an exercise for the reader ;-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fde5f7323b9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bleacher-report-engineering/passive-transparency-3fde5f7323b9">Passive Transparency</a> was originally published in <a href="https://medium.com/bleacher-report-engineering">Bleacher Report Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Small Commits for Fun and Profit, part 2: git commit --amend and git rebase --interactive]]></title>
            <link>https://medium.com/bleacher-report-engineering/small-commits-for-fun-and-profit-part-2-git-commit-amend-and-git-rebase-interactive-e986d4a64c21?source=rss----ea01471dcd9---4</link>
            <guid isPermaLink="false">https://medium.com/p/e986d4a64c21</guid>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Alexander Quine]]></dc:creator>
            <pubDate>Thu, 15 Feb 2018 22:18:01 GMT</pubDate>
            <atom:updated>2019-02-28T22:26:00.691Z</atom:updated>
            <content:encoded><![CDATA[<p>(<a href="http://medium.com/p/c0966a562b10">Check out Part 1, all about </a><a href="http://medium.com/p/c0966a562b10">git add --patch.</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*75GIyh005_Wl9vRQF3tgTQ.png" /></figure><p>It’s helpful for code reviewers (and future code archaeologists) to have a neatly-organized history of changes to your code. In Part 1 we looked at how git add --patch lets us be mindful about exactly what code will go into each commit. But what if you notice that you’ve made a mistake in a previous commit? It’s easy to create a new commit with a message like “fix typo” or “swap order of parameters” or whatever, and as long as that’s the only thing you’re doing it the commit, that seems Good Enough.</p><h4>git commit --amend</h4><p>If the commit which introduced the error happens to be the very last commit you made*, you’re in luck! We’re going to git add the typo fix, but instead of creating a normal new commit, we’ll use git commit --amend to “squish together” the last commit <em>plus</em> this typo-fix. This will bring up your editor, giving you the opportunity to modify the commit message now that you’ve fixed the typo. When you’re happy with the commit message, save and close your editor, and thengit log --patch -1 to see a diff of your now-typo-less commit.</p><p>* …and you haven’t pushed that last commit anywhere! See “A brief warning” section below…</p><h4>git rebase --interactive</h4><p>Unfortunately, I often discover an error or typo a few commits in the past. Fortunately, all is not lost! If I haven’t touched the code around that error-containing line*, git rebase --interactive is here to save me.</p><p>* it’s still possible to rebase like this if I <em>have</em> touched nearby code; it’s just a little more fiddly… that’ll be for a later blog post.</p><p>Okay, here’s how it works. To set the stage: I’m already working on a feature branch, where I can mess with git history with ̶i̶m̶p̶u̶n̶i̶t̶y̶ care and won’t botch the working environments of any of my colleagues (i.e., <strong>do not do this on shared branches!</strong>).</p><p>(As <a href="http://2ndscale.com/rtomayko/2008/the-thing-about-git">Ryan Tomayko so eloquently put it</a>, git rebase --interactive “is a bit like git commit --amend hopped up on acid and holding a chainsaw — completely insane and quite dangerous but capable of exposing entirely new states of mind.” This blog post is an attempt at explaining one of these new states of mind, while ignoring the insane and dangerous bits.)</p><p>I’ve already made commits A, B, and C, but when I look at my git history, I notice that I’ve made a crucial error in commit B (turns out, I can’t spell function). I can’t simply use git commit --amend because that would modify the most recent commit which is C, whereas I need to modify commit B.</p><p>In order to modify commit B, I’m first going to make a temporary commit D. This will contain <em>only</em> the correction which I want to end up in commit B. This is a normal commit: edit the file with the error, git add it (perhaps git add --patch if that file has other not-yet-committed modifications!), and git commit it with a helpful message (such as “correct funciton to function”).</p><p>Now I have Commits A, B, C, and D. My goal is to combine Commit D into Commit B, and end up with a single Commit B-prime, which replaces Commit B. Then my git history will have, in order: Commits A, B-prime, C (the temporary Commit D will be “gone”).</p><p>The interactive rebase command wants to know the <em>parent</em> of the earliest commit to modify. Because we want to modify back to and including Commit B, we will need to give the rebase command the SHA of Commit B’s <em>parent</em>, which is Commit A. (Use git log to identify the SHA of Commit A on your local repo; I will use “a1aaaaa” as an example.)</p><p>Grab your shell and run git rebase --interactive a1aaaaa and it should pop open your trusty editor again. It’s showing a list of the three commits between Commit A and HEAD, and asking what we’d like to do with them; after the list of commits, it lists what we can do for each commit: pick, reword, edit, squash, fixup, or exec. There are two more things we can do: remove a commit completely (by deleting the line referencing the commit), or reorder the commits (by swapping around the lines). (Are you starting to see where we’re heading here?)</p><p>The note for squash says that it will “use commit, but meld into previous commit”, which is <em>almost</em> what we want—we are trying to squash Commit D into Commit B, but B is not the <em>previous</em> commit. However, we can also reorder commits right here, so we can literally move Commit D to come <em>before</em> Commit C, whereupon squash becomes exactly what we want.</p><p>Here we go: swap the line referencing Commit C with the line referencing Commit D, so the order becomes (top to bottom) B, D, C.</p><p>Now that Commit D is immediately after Commit B, we can squash D right into B, thus creating a Commit B-prime which is a combination of the two—and thereby making it look like the typo never happened. The first word of each of these lines referencing a commit is initially pick, the default action which means “use this commit normally”. For Commit D, change that pick to squash, so that commit will be merged into the previous one (which is now Commit B).</p><p>With the order now B, D, C, and the line for Commit D starting with squash, save and close the editor. It’ll pop right back up again, but this time with the log messages for both Commit B and D. Now it’s asking you to create a new-and-improved commit message for the new-and-improved Commit B-prime. Tweak the message to your heart’s content, then save-and-quit the editor. You should see git printing out some progress notes as it shuffles things, and then once it’s done: “Successfully rebased and updated refs/heads/name-of-your-branch.”</p><p>(Pro tip: in this contrived typo-fix example, you’ll probably want to continue using the message from commit B, without noting that you had to delve into history to fix a typo. If that’s the case, use fixup: it’ll discard the message for Commit D entirely, and reuse Commit B’s message.)</p><h4>a brief warning</h4><p>What we’re doing here is called “rewriting history”, and that should sound dangerous. Git helps us share code between people, and part of its underlying social contract is that once the history for code has been “established”, it should stay that way. The primary reason for this is practical: when multiple people are working on the same chunk of code, a modification to the history of that code will propagate to all the people working on it — and when they don’t expect that modification, they get surprised and upset when the foundation they’re building upon has suddenly changed.</p><p>My corollary to this understanding is that branches which are not yet intended to be shared with other people (such as my still-in-development feature branch) <em>may</em> have their histories rewritten without surprising and upsetting my colleagues. Said another way: if I’m the only one depending on a piece of history, I can rewrite it and it won’t screw up my coworkers’ development.</p><p>So: <strong>Don’t rewrite <em>shared</em> history!</strong></p><h4>Wrapping things up</h4><p>If you’ve been following along, we’ve just “Successfully rebased” and our git log reflects that rather than our original commits A B C and D, we now have A B-prime and C. This worked smoothly because the mistake in commit B could be cleanly fixed by commit D and then combined together to create commit B-prime, without modifying the code which was changed in the intervening commit C.</p><p>This basic example illustrates the use of git rebase --interactive to modify the code associated with an existing commit. This is a powerful (almost magical) tool, so it must be used carefully — do not surprise your colleagues with an ever-changing Git log! — but it will give you the power to curate an easily-understood history of code changes.</p><p>That’s all for now!</p><p><em>Next in my Git Manifesto Series: Part 3 will show how to use </em><em>git cherry-pick to merge specific commits from other branches!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e986d4a64c21" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bleacher-report-engineering/small-commits-for-fun-and-profit-part-2-git-commit-amend-and-git-rebase-interactive-e986d4a64c21">Small Commits for Fun and Profit, part 2: git commit --amend and git rebase --interactive</a> was originally published in <a href="https://medium.com/bleacher-report-engineering">Bleacher Report Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React and Redux Testing with Jest: How Some Jokers Learned to Take Snapshots]]></title>
            <link>https://medium.com/bleacher-report-engineering/react-and-redux-testing-with-jest-how-some-jokers-learned-to-take-snapshots-c186c7e419e6?source=rss----ea01471dcd9---4</link>
            <guid isPermaLink="false">https://medium.com/p/c186c7e419e6</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Tory Briggs]]></dc:creator>
            <pubDate>Mon, 17 Jul 2017 20:50:49 GMT</pubDate>
            <atom:updated>2017-07-17T20:50:49.095Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3gjJ5s9ZYIHta3bdXp_gIw.jpeg" /><figcaption>Photo by <a href="https://www.flickr.com/photos/bantam10/5873672925">Ted Van Pelt</a>. Used under the CC license.</figcaption></figure><h3>TL;DR</h3><p>We rewrote a large chunk of our tests using Jest. Snapshots replaced a whole slew of Enzyme expect statements and allowed us to more easily test our Redux actions and store. In the future, we hope to make use of some other features of Jest, such as the <a href="https://facebook.github.io/jest/blog/2017/05/06/jest-20-delightful-testing-multi-project-runner.html">Multi-Project-Runner</a>.</p><h3>Old Tests</h3><p>To understand the motivation behind rewriting some of our tests I’d like to show an example of what our component tests used to look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb162c218df69a71398908ccfba6a8ad/href">https://medium.com/media/fb162c218df69a71398908ccfba6a8ad/href</a></iframe><p>This is an example of a simple button that renders a small bit of HTML with the correct icon. In this specific case, it should render as a trash can. Even in this simple example there is a large list of expect statements to verify the component is rendering the correct HTML. Let’s look at another, slightly larger example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b45a22e2099d8b767fe94946cc4f6656/href">https://medium.com/media/b45a22e2099d8b767fe94946cc4f6656/href</a></iframe><p>There are a couple of problems with this old test. The first is that once again we have to write a whole bunch of expect statements to verify the component is rendering the correct HTML. In this case, we find the input, label, and menu elements for which to run tests against. A second problem is the expect statements in the “renders the input field” test that check the prop values of the input. These tests are completely unnecessary in my opinion because they simply test that React is doing its job passing prop values. We shouldn’t have to test React itself.</p><p>These examples are from a couple of very simple components and only demonstrate testing the markup. Now imagine trying to test more complicated components and behavior. Your test files will quickly become unmanageable. If you really want to trigger a panic attack, now imagine a product manager and designer decide a redesign is in order and most of the markup will be changing. You’ll now have to revisit all of these tests and update them line by line.</p><h3>Jest</h3><p>Enter Jest. Facebook fancies the framework with the tagline “Delightful JavaScript Testing.” This has mostly been true in our experience. Setting it up is quite simple, and the tests run very quickly. You can choose not to configure Jest out of the box and it will Just Work™, but we did apply some configuration in the form of a jest.config.json file that is applied via the command jest --config path/to/jest.config.json. The small amount of configuration we applied is mostly for telling Jest where to output coverage files and to load with a <a href="https://facebook.github.io/jest/docs/en/configuration.html#setupfiles-array">setup file</a>.</p><p>The parts of Jest we find most useful are the expectation objects/matchers, the mocking library, and the snapshots.</p><h4>Expectations and Matchers</h4><p>These tests should look familiar to anyone who has used the <a href="http://chaijs.com/">Chai Assertion Library</a>. The expect function takes a value and returns an “expectation” object. You will rarely (never) call expect on its own. Rather, you will chain a matcher function to assert the value input is what you’re expecting. A simple example <a href="https://facebook.github.io/jest/docs/expect.html">from the docs</a>:</p><pre>test(“two plus two is four”, () =&gt; {<br>  expect(2 + 2).toBe(4);<br>});</pre><p>There are some useful matchers that help distinguish between falsey values, such astoBeNull, toBeDefined, toBeUndefined, etc.</p><h4>Mocks</h4><p>The mocking library has proved extremely useful in our tests. Oftentimes we want to test that after an API call is made we’re properly updating the Redux store and any corresponding React components are rendered correctly. But we don’t want our tests to be reliant on a network request. Making API calls within your tests can greatly reduce the speed at which they run and can be error-prone. Your application shouldn’t be responsible for testing the network and availability of an API. There are monitoring tools that are much better suited for that sort of thing.</p><p>All right, let’s see an example!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c9f4e5a295fcc2fc663d5a61d2c65ed/href">https://medium.com/media/3c9f4e5a295fcc2fc663d5a61d2c65ed/href</a></iframe><p>Typically, we place all the interactions with a particular API into its own file. We then export relevant functions to be used in different parts of the app. In the first block of the above example we’ve exported the get function, which simply fetches data from a defined endpoint using a query string.</p><p>In the second block we’re calling jest.mock and passing it two arguments. The first is a reference to the “content_api” module where we’ve defined that get function. The second is a function that returns an object of defined mocked functions. We define our get mock and set it equal to jest.fn, which returns a predefined API response. With that mock in place, anytime the get function is called in a test we can use a matcher on it. One example for if we expect it to have been called with the correct URL:</p><pre>expect(ContentApi.get).toHaveBeenCalledWith(contentID);</pre><h4>Snapshots</h4><p>Now let’s re-examine the aforementioned “old” tests and how they would be written with Jest and snapshots. We can replace all of those expect statements with a snapshot (for some reason the Gist wouldn’t render, so here is a regular code block):</p><pre>it(&quot;renders with proper defaults&quot;, function () {<br> const BasicTabComponent = renderer.create(<br>   &lt;Tab title=&quot;Awesome Tab&quot; isActive/&gt;<br> );<br><br> expect(BasicTabComponent).toMatchSnapshot();<br>});</pre><p>Which outputs a snapshot file with the following contents:</p><pre>// __snapshots__/basic-tab.test.js.snap<br><br>exports[`Basic Tab renders with proper defaults 1`] = `<br>&lt;li<br>  className=&quot;tab active&quot;<br>  title=&quot;Awesome Tab&quot;&gt;<br>  Awesome Tab<br>&lt;/li&gt;<br>`;</pre><p>With a single expect statement we can capture the markup of the entire component. And when you decide to change the component all you have to do is re-run the test to see a diff of the old and new snapshots. Once you verify the change is correct you can update the snapshot with a single keystroke. Here is the output if I change the title attribute to “Potato Tab”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nO_cTAX861UQhfX1." /><figcaption>Test output</figcaption></figure><p>When we initially created these snapshot files, they were often quite large and took a fair amount of time to review and verify the markup was correct. This initial work was a bit of pain point for us. To help reduce the size of these snapshots and reduce their complexity, we’ve learned to mock any child components we aren’t currently concerned with (and are covered in their own tests). We like to try to isolate the snapshot for the component we are testing.</p><h3>Redux Testing</h3><p>Not only is Jest great for testing components, it can also be used for testing Redux. According to the <a href="https://facebook.github.io/jest/docs/snapshot-testing.html#frequently-asked-questions">Jest FAQ</a>:</p><blockquote><a href="https://facebook.github.io/jest/docs/tutorial-react.html">React</a> and <a href="https://facebook.github.io/jest/docs/tutorial-react-native.html">React Native</a> components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct.</blockquote><p>Being able to snapshot basically any object means that we can test the contents of our Redux store. In order to do so, we developed an integration style test to make sure a dispatched action had the correct effect and stored the correct data in our Redux store (credit <a href="https://medium.com/u/d2b843ad93ae">Nick Cantelmi</a>!).</p><p>In order to demonstrate, we’ll have to revisit the Mocking concept from above. Let’s contrive an example where when we dispatch an action, an API is supposed to be called that stores the returned data in our store. Here’s the action example:</p><pre>store.dispatch(ContentActions.contentQuery(contentID));</pre><p>After dispatching that action we can run an expectation that the API was called with the passed contentID. Remember our mock from above?</p><pre>expect(ContentApi.get).toHaveBeenCalledWith(contentID);</pre><p>But we can also test that the returned data was stored correctly in Redux. First we import our store into our test, then call getState to retrieve the part of the store we’re concerned with, and then we simply snapshot it:</p><pre>expect(store.getState().content).toMatchSnapshot();</pre><p>This allows us to verify that data is flowing through our application correctly from end to end. From the point of the API call, to the storing of the data in Redux. There might be a lot of work going on within that contentQuery action, but if we can verify that the output is correct in the store, we can have a good confidence level things are working as expected.</p><p>When we started writing these types of tests, we took a snapshot of the entire store. But we started isolating different parts of the store in much the same way we had been doing for our components. This created more reasonably sized snapshots that were easier to review and verify.</p><h3>Conclusion</h3><p>We’ve grown to love Jest at Bleacher Report. It alleviates some of the pain points we were experiencing trying to test our components and also helps us test the data in our application. I find the way we’re using snapshots to test the contents of our Redux store to be a lesser-known, but invaluable use case for using Jest.</p><p>Please don’t hesitate to reach out with any questions. And please let me know if you’d like to see a separate post going into more detail about any of the above topics.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c186c7e419e6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bleacher-report-engineering/react-and-redux-testing-with-jest-how-some-jokers-learned-to-take-snapshots-c186c7e419e6">React and Redux Testing with Jest: How Some Jokers Learned to Take Snapshots</a> was originally published in <a href="https://medium.com/bleacher-report-engineering">Bleacher Report Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elixir: Testing with Bypass]]></title>
            <link>https://medium.com/bleacher-report-engineering/elixir-testing-with-bypass-68a7f738db7a?source=rss----ea01471dcd9---4</link>
            <guid isPermaLink="false">https://medium.com/p/68a7f738db7a</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Michael Smykowski]]></dc:creator>
            <pubDate>Mon, 10 Jul 2017 19:53:15 GMT</pubDate>
            <atom:updated>2017-07-10T19:53:14.551Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ldbVvKisFVwk6H2FlkHsNQ.jpeg" /><figcaption>Photo by <a href="https://www.flickr.com/photos/emeryway/3070695393/in/photolist-5Fm7L2-6iNGcK-aE3zwF-4mdRUA-riiKyx-aA4RwK-2aiX1x-qCvRC-BThbux-upwa7d-ivEFML-jvwdn-dBRbWS-3JPBmt-fjmJqH-cFNjgU-dBRbTG-p72Gyy-r2rp6S-iozqzT-FGSHJG-cM31L-T4uJSr-axnWc1-fjmBDp-fjASL5-FqVZ3A-FGSKBu-brS2TR-8AjC6M-FR3Gbr-EVN48x-FNKARL-FNKJNN-FKbKpg-34Rj6D-4RFJe1-FNKCef-aYimNr-EVB9Au-FGST4d-gQ2jTs-FKbM6T-9D7bkL-gQ2iF7-gQ2iuW-3b4CeN-5ifqXE-dHWQf7-axnUwA">Emery Way</a>. Used under the CC license.</figcaption></figure><p>Testing integration points in your application can be difficult and imperfect.</p><p>I have two main goals when testing integration points —</p><ol><li>Test that the correct request is made with associated path, body, headers etc.</li><li>Test the response and its expected transformation</li></ol><h3><strong>ExVCR</strong></h3><p><a href="https://github.com/parroty/exvcr">https://github.com/parroty/exvcr</a></p><p>ExVCR is a popular library that records initial HTTP responses in “cassettes”. Subsequent test runs will return these prerecorded responses for external HTTP requests.</p><p>Upside:</p><ul><li>ExVCR test setup is quick and easy.</li><li>Tests use real data (very useful for catching changes to response data structures)</li></ul><p>Downside:</p><ul><li>Cassettes must be updated frequently to prevent stale data</li><li>Upon updating cassettes, ephemeral data can lead to tedious test maintenance</li><li>Requests are environment specific</li><li>It is difficult to test connection properties (e.g., path, query, etc.) — because ExVCR does not give you access to the connection object, all assertions have to be made using the corresponding response</li></ul><h3>Bypass</h3><p><a href="https://github.com/PSPDFKit-labs/bypass">https://github.com/PSPDFKit-labs/bypass</a></p><p>Bypass takes a very different approach to testing HTTP requests. Bypass spins up a local server that intercepts outgoing requests. Assertions can be made on the intercepted request connection, and a manually constructed response can be sent back.</p><p>Upside:</p><ul><li>Tests written with Bypass are not environment specific and do not require internet to pass (tests work out of the box)</li><li>Asserting on the connection object is easy and intuitive</li><li>Response data values are predictable, tests are more robust</li></ul><p>Downside:</p><ul><li>Test setup with Bypass is a manual process. A local Bypass server needs to be initialized for every external service to be <em>bypassed</em>. Responses need to be constructed by hand</li><li>Response data is not real. The developer must be aware of response data structure changes, and update the test accordingly</li></ul><p>Bypass is a great solution for testing integration points, however the test setup can be tedious and redundant.</p><p>Here is an example test using Bypass:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OZoHnDXkKHRqOCYFDMNGMA.png" /></figure><p>Alone, one test does not look to0 bad, but a file full of Bypass tests can become an eyesore full of duplicate code and repeat assertions.</p><h3><strong>ExUnit Tags to the Rescue</strong></h3><p>ExUnit tags are a great way to organize tests and provide custom test setups. Tags can be accessed via ExUnit’s context, where they can be used in callbacks to tailor individual tests.</p><p>Using tags, we can rewrite the previous test as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D_LLKcOuEbIPKzIhk4niFA.png" /><figcaption>service_one_controller_test.exs</figcaption></figure><p>The test is tagged with the ExUnit tag “service_one”. The presence of this tag is responsible for initializing a Bypass server for that particular service. The map of values will be used to make assertions and return a response from the Bypass server.</p><p>Internally, here is what is happening —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*s6z6_0TPHSlHDgQlCRfoDA.png" /><figcaption>conn_case.ex</figcaption></figure><p>We have defined a list of Bypass tags. The key corresponds to the service-specific ExUnit tag to be used when initializing a Bypass server, while the value corresponds to the system configuration environment variable to be pointed towards the Bypass server (this setup works for initializing multiple Bypass servers).</p><p>In our setup we have access to the ExUnit tags for the current test being run. When one of these tags matches a defined Bypass tag, we pass those values to our Bypass module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0CICjuJuiMsBiQIByin0yA.png" /><figcaption>bypass.ex</figcaption></figure><p>Our Bypass module initializes a Bypass server, and points the system configuration to the local Bypass server. The on_exit callback is used to restore this configuration once the test has ended. This will be done for each service with a corresponding ExUnit tag present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XJwmloecMHFYRf2QVbSHLQ.png" /><figcaption>bypass.ex</figcaption></figure><p>The Bypass module also handles the assertions for the specific test, asserting on all relevant parameters provided via the ExUnit tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FPPK6758MJ-RpMgS5tGNtA.png" /><figcaption>bypass.ex</figcaption></figure><p>Furthermore, the Bypass module will return a predefined status code and response from the Bypass server (using the parameters provided or a default).</p><p>All of our Bypass setup and assertion code is consolidated into a single module, which DRY’s our tests significantly.</p><p>Additionally, our tests are now documenting external requests. The properties of our external requests are listed in a readable map, rather than jumbled within the code.</p><p>Of course there are times where this setup can be restrictive. For these cases, the Bypass object is still returned in the test context to be used as needed in the test itself.</p><p>This is one solution I have found works well when testing integration points. Feedback and improvements would be greatly appreciated!</p><p>More of the code, examples, and documentation can be found at: <a href="https://github.com/msmykowski/double_bypass">https://github.com/msmykowski/double_bypass</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68a7f738db7a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bleacher-report-engineering/elixir-testing-with-bypass-68a7f738db7a">Elixir: Testing with Bypass</a> was originally published in <a href="https://medium.com/bleacher-report-engineering">Bleacher Report Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>