Apis in Action
Apis in Action
Apis in Action
WHITE PAPER
APIs in Action
A Guide to Monitoring APIs
for Performance
WHITE PAPER
Table of Contents
Introduction.............................................................................................................................................3
Understanding APIs............................................................................................................................3
APIs in Action..........................................................................................................................................4
Chapter One: Soap, Rest and Json...........................................................................................5
Chapter Two: Why Monitor APIs.................................................................................................5
Chapter Three: How to Monitor APIs.......................................................................................7
Chapter Four: Monitoring for SLAs........................................................................................ 11
Chapter Five: Splunk’s API Checks........................................................................................13
APIs in Action 2
WHITE PAPER
APIs in Action 3
WHITE PAPER
APIs in Action
Let’s look at a well-known company that relies on Now let’s compare that public API scenario to an
public APIs. example of how APIs can be used to trigger tasks to
The Weather Company collects weather data improve internal business processes.
from millions of endpoints and sources around the Splunk Web Optimization captures a number of
globe. They store this data and make it accessible performance metrics for digital businesses and
to consumer-facing applications via hundreds of provides smart suggestions for how to improve site
different APIs. performance. The optimization tool can help teams
Consider a widget on your home screen or desktop identify when any changes to a website introduce a
that always displays current temperature and weather regression in performance, meaning a site or web
conditions based on your location. Your device may not app has some content that’s making it load slower
have a thermometer or a barometer or any baked-in than it could.
technology that detects or predicts weather patterns, Using the optimization tool’s API, the team at Splunk
but your device can send information about your can integrate performance testing into deployments
location to an API and return the correct data such as and identify any performance regressions introduced.
the temperature and forecast based on your location. A request was built into the deployment process
Even if you’re not on the Weather Company website for the optimization API that triggers a performance
or using one of the Weather Company’s native mobile scan to Splunk’s staging environment and posts the
applications you may be interacting with data from a details of the scan into our Slack chat channel. Now
Weather Company API responding to simple requests. we can use our existing ChatOps setup to notify
the team when anything we build in staging will
make our application slower.
APIs in Action 4
WHITE PAPER
CHAPTER ONE
CHAPTER TWO
APIs in Action 5
WHITE PAPER
Or, let’s say that you’ve developed a new internal • Response time: How quickly is the API returning
API that passes order data from a mobile device responses? Is the response time degrading over
to a system in your product warehouse. Maybe it’s time? Is the response time worse in production
critical that the data passes to the warehouse within than in pre-production?
two minutes, or the entire production schedule will • Data validation: Is the API returning the correct
be off. When you developed the API and tested it in data in the right format?
staging it always passed data successfully within • Multi-step processes: Can I successfully save and
one minute, but when you launch the API and start reuse a variable from this API? Does authentication
processing real requests you notice that the real work as expected? Can I complete a transaction
response time is creeping up closer and closer to with data from this API?
that two-minute threshold. Without active monitoring
on the API in production, your team might assume These are just the basic concepts that your team
that the developed API is fast enough based on should be looking for when it comes to monitoring API
pre-production tests. performance. In the next section we’ll cover how to
technically implement monitoring for APIs and what
types of features are important to build out robust,
Note: If you host an API that other people rely on,
flexible performance tests.
be sure to actively monitor that API in both pre-
production and production environments.
APIs in Action 6
WHITE PAPER
CHAPTER THREE
APIs in Action 7
WHITE PAPER
We could continue to add more functional steps to this When using any type of direct authentication, it’s
transaction or add an Assert step to confirm that the important that you also use SSL/TLS or
session ID is set as expected. https:// at the start of the API endpoint URL. Using
SSL/TLS will ensure that the HTTP basic authentication
Handling authentication credentials or API keys aren’t exposed in the URL.
In the above example we used request headers to Interested in learning more about SSL/TLS and how
send over a username and password for authentication. to optimize for performance? There are a number of
Let’s take a minute to focus on the security aspect excellent articles on the Zoompf blog.
of APIs and how we can consider this as we build
performance tests. HTTP basic authentication
Authentication for an API defines who has permission If you are using basic authentication to secure your
to access secure data or endpoints. This is especially APIs, it’s super simple to include that authentication
important for APIs sharing sensitive information, APIs when configuring an external monitor to check for
that allow end users to make changes, or for companies API performance.
that charge some cost for accessing data via API. And
The most common and reliable way to set up a
while securing an API for an individual human end user
monitoring request with HTTP basic authentication
is one undertaking, there are additional considerations
is to go ahead and encode that username:password
as we authenticate systems for an increasing number
value in base64 and send that value over in an
of non-human entities.
authorization header:
As APIs become more secure, proactive monitoring
systems are adapting to make it possible to access
secure systems externally.
Direct authentication
A good example of direct authentication is HTTP basic
authentication. HTTP basic authentication is a standard
part of HTTP, and it can be used for API endpoints
or any HTTP URL. You simply send a username and It’s important to note that while it’s easy to encode
password — encoded together in base64 — as usernames and passwords into base64, it’s also
part of your request to the API. The benefit of HTTP very easy to reverse or decode so that a system can
basic authentication is that it’s easy to implement authenticate a request. You can try this yourself with an
and is typically included in standard frameworks. On online base64 encoder/decoder. Because base64 is so
the downside, HTTP basic authentication offers no accessible, it’s important to protect this type of direct
advanced options and may be easily decoded. authentication with SSL/TLS.
Another example of direct authentication
would be using API keys or tokens. API keys
are just a long string of hexadecimal digits, i.e.
34d83d84f28d146aeae0e32f7803c88d, that
can be sent instead of a username or password to
authenticate access to an API endpoint. API keys
are essentially the same as a set of username and
password credentials, but they provide a layer of
abstraction that is useful. For example, multiple end
users could share a single API key.
APIs in Action 8
WHITE PAPER
API keys bring her back in a few minutes.” That would be similar
to direct authentication in the sense that I’m giving the
From a monitoring standpoint, it’s fairly simple to
car key directly to you based on your name.
replicate the process of hitting an endpoint with an API
key in the URL or with request headers. Supply the key Now imagine that I’m selling you a luxury vehicle from
and just remember that if it ever changes you’ll need to a dealership. You meet me at the dealership and give
update your monitoring test’s configuration as well. me your driver’s license. I don’t have one key that will
work for all of the cars on the lot. I have to take your
driver’s license and use it to register your information
to a computer system that will verify that you’re an
upstanding gentleperson. This will then unlock a box
where I can take out a key that will only work for the
vehicle you’re now registered to test drive. This is
similar to a ticket-based system in the sense that I’m
relying on a centralized system to distribute a key that’s
now connected to you through the ticket.
OAuth, Kerberos, single sign on and webforms are all
Note that different systems may accept API keys in
examples of ticket-based authentication systems.
different ways — for example, as part of the POST
You may even develop your own custom authentication
data instead of as a request header — so check with
system. While there are many different ways to
the API you are monitoring to understand how to
implement this type of protocol, most ticket-based
properly transmit the API Key.
systems share a similar structure in the sense that
you first make a request for a ticket or a token and then
use that ticket or token to access secured data
Ticket-based authentication or endpoints.
While there are certainly some conveniences to The tickets in ticket-based authentication systems look
implementing direct authentication, we may need very similar to the API keys we discussed above. One
to add an additional layer of security to our APIs. main difference is that the tickets are ephemeral. They
Ticket-based authentication systems rely on central are only valid a short period of time and can be easily
authentication servers that act as intermediaries, revoked, which provides an extra layer of security.
accepting credentials from end users and then sending
back tickets, tokens or keys that allow the specific end
Monitoring with ticket-based authentication
user to access only specific secured data. Ticket-based
authentication is ideal for any scenario where you’re In order to effectively monitor an API that uses ticket-
protecting sensitive information, allowing an API to based authentication you must be able to complete
create objects or make changes or if you’re charging multiple steps and save the ticket or token in a variable
some cost for use of your API. that can be reused in future steps.
A simple example of this would be to make a request
Understanding ticket-based systems with a username and password and some type of
specification in the header, then retrieve a token from
We might think of ticket-based authentication as similar
the system, save that token as a variable and then
to how we might obtain keys to test-drive vehicles.
make another request to an endpoint with that token
Imagine that I’m selling my junker of a car on Craigslist. as a header.
You meet me at the local diner so you can give my car a
test drive. You show me your driver’s license. I say, “Hey!
You seem to be this nice person who I just met online. I
trust you absolutely. Here’s the key. Give her a spin and
APIs in Action 9
WHITE PAPER
If you’re not already implementing some authentication In the example that follows we’re using a Splunk API
for your API, it’s critical that you start doing so to Check to:
protect your data and your systems. And, as you 1. Make a request with an API key to Splunk API’s
increase security make sure that your external endpoint for real browser check data.
monitoring systems also have the permission and
2. Assert that the response code contains the
ability to monitor the performance and reliability
value ‘200.’
of your system. If you’re only monitoring your API
performance on the application side, you could miss 3. Extract the check ID from the JSON using
all sorts of connectivity problems preventing your end JSON path.
users from accessing data or making changes through
your API.
APIs in Action 10
WHITE PAPER
This is just one simple example of how to implement strategy is to write tests in a way that allows a system
robust monitoring for an API. If your current API tests to call an API and not receive data.
only monitor for response code and response time, When writing code with lots of local calls, a wrapper
it might be time to consider adding some additional that calls to an external API often goes unnoticed with
criteria for data format and quality. the context of an application. If your test is designed
to alert when no data is present, this will help make
Write performance tests to assume failure sure you don’t miss critical errors. Remember to make
So far we’ve looked at how to monitor with request your code resilient so that when it receives an error
headers, authentication and data validation in mind. message, mangled data or no response at all, it will
When it comes to writing performance tests, one continue to function.
CHAPTER FOUR
APIs in Action 11
WHITE PAPER
How to ensure that you’re upholding your SLAs With the proactive data that simulates real end users
interacting with our mapping system we can:
As business owners for the mapping provider we might
say, “Hey, we need some data to get ahead of issues so 1. Get ahead of performance issues before they
that we can make sure that we’re upholding our end of affect our real users, and
the bargain. And, it would be nice if we could share that 2. Share reports with our partner to demonstrate that
data publicly with our partners at the ride-sharing web our uptime is exactly what we promised.
app so they know they can trust our service.”
We could rely on the internal monitoring of our
application, but that might only give us part of the
picture. How do we know whether our map data
is available from our API to the end user outside of
our system? How do we confirm that data isn’t just
available but in the right format?
We can build a synthetic, external monitor to test
pulling data from our own API and put alerting in place
so that our engineers know right away if there’s any
type of issue that might be putting us close to breach
of our agreement.
APIs in Action 12
WHITE PAPER
CHAPTER FIVE
APIs in Action 13
WHITE PAPER
To get the full details and technical walk through, read more about API Check on Splunkbase.
Splunk, Splunk>, Data-to-Everything, D2E and Turn Data Into Doing are trademarks and registered trademarks of Splunk Inc. in the United States and other countries.
All other brand names, product names or trademarks belong to their respective owners. © 2021 Splunk Inc. All rights reserved. 21-16715-SPLK-APIs-In-Action-TWP-106