<?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[Stories by Nimrod Shneor on Medium]]></title>
        <description><![CDATA[Stories by Nimrod Shneor on Medium]]></description>
        <link>https://medium.com/@nimrodshn?source=rss-d3aeafdf4d03------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*gS8YIhuc3rQIDRpX27H1aA.jpeg</url>
            <title>Stories by Nimrod Shneor on Medium</title>
            <link>https://medium.com/@nimrodshn?source=rss-d3aeafdf4d03------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 07:50:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nimrodshn/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Writing a storage engine in Rust: Writing a persistent BTree — Crash Recovery]]></title>
            <link>https://nimrodshn.medium.com/writing-a-storage-engine-in-rust-writing-a-persistent-btree-crash-recovery-7ac623dd3b1f?source=rss-d3aeafdf4d03------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ac623dd3b1f</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[database-design]]></category>
            <category><![CDATA[b-tree]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Nimrod Shneor]]></dc:creator>
            <pubDate>Thu, 14 Oct 2021 10:23:16 GMT</pubDate>
            <atom:updated>2021-10-15T08:25:39.026Z</atom:updated>
            <content:encoded><![CDATA[<h3>Writing a storage engine in Rust: Crash Recovery</h3><p>In <a href="https://nimrodshn.medium.com/writing-a-storage-engine-in-rust-writing-a-persistent-btree-part-1-916b6f3e2934">the previous chapter</a> of this series we have considered the alternatives of using a B-Tree vs LSM Tree as our storage engines index and concluded with our design of mapping disk pages to nodes.</p><p>In this article I won’t focus too much about the implementation of CRUD operations of a BTree — for that I recommend the excellent Cormen’s “Introduction to Algorithms” and “Modern B-Tree Techniques” by Graefe.</p><p>Instead, I will cover one of the most crucial features that certainly has to be supported by any data structure (BTree or other) as an index for storage engines — Crash Recovery.</p><h3>Motivation</h3><p>One of the most basic requirements from a BTree index (or any index for that matter) is its ability to withstand a machine crash. What should happen if we didn’t support crash recovery?</p><p>Lets take the simplest example of inserting a key-value pair to our tree causing the a leaf to split but than suddenly our machine crashes <em>before writing the pointer to the new node - we will lose not only the new key-value pair but also B-1 key-value pairs (Possibly hundreds of rows!).</em></p><h3>Copy-on-Write</h3><p>There are many subtle ways to implement this feature — I chose a popular technique called “Copy-on-Write”, simply put, every time a change is made in the tree (e.g. inserting a key-value pair) instead of searching for the leaf which needs to hold the new key-value pair and then inserting that pair, <em>we would make a copy of all the nodes in the root-to-leaf path for the node to insert and than insert the new pair.</em></p><p>In the example below; a key was added to a leaf node #8 resulting in a copy of the root-to-leaf path. Notice how not only did the leaf node get copied over but also the branch nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*FNIw5OpXQiysVm5hbbu11w.png" /><figcaption>An example of a COW Tree. Taken from <a href="http://www.bzero.se/ldapd/btree.html">http://www.bzero.se/ldapd/btree.html</a></figcaption></figure><p>Whenever we copy over a new node we would simply append its page to our DB file; this approach is called an “append only” tree and is widely used in commercial databases (For example: CouchDB).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*JAHe8_WluqvP4GFqoXTsEA.png" /><figcaption>From CouchDB’s guides: <a href="https://guide.couchdb.org/draft/btree.html">https://guide.couchdb.org/draft/btree.html</a></figcaption></figure><h3>Tree Recovery</h3><p>A clear consequence of this approach is we would result with <em>multiple versions of the same tree.</em> How would we know which page now holds the latest version of the root?</p><p>The simplest mechanism is to use a “Write-ahead-Log” that is, whenever we copy over the root-to-leaf path during a write operation we append the offset of the copied over root to a log. That way we can keep track of the latest root as the latest offset in the log file.</p><p>If at any point during the write process our machine crashes <em>we can recover the latest tree using the latest offset of the root from our log.</em></p><p>One caveat with this approach is that it quickly occupies a lot of memory as we are quickly creating copies of nodes on each write. To overcome this we would need to implement a garbage collection mechanism (But that is out of scope for this article).</p><p>One should note that the “Copy-on-Write” approach has other benefits; namely that it allows us to support some levels of <em>isolation</em> (if we would ever implement ACID transactions), as reads and writes “see” a different version (“snapshot”) of the tree. This technique is called <a href="https://en.wikipedia.org/wiki/Snapshot_isolation#:~:text=In%20databases%2C%20and%20transaction%20processing,the%20transaction%20itself%20will%20successfully">“snapshot isolation”</a> and is widely used in transactions management.</p><h3>Implementation</h3><p>The following snippet is an implementation of insert using the methods described in this article, the full code can be found <a href="https://github.com/nimrodshn/btree">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2aed179de3e0249d5a60471d3461d184/href">https://medium.com/media/2aed179de3e0249d5a60471d3461d184/href</a></iframe><p>Thats it! I hope you have enjoyed this chapter..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ac623dd3b1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing a storage engine in Rust: Writing a persistent BTree (Part 1)]]></title>
            <link>https://nimrodshn.medium.com/writing-a-storage-engine-in-rust-writing-a-persistent-btree-part-1-916b6f3e2934?source=rss-d3aeafdf4d03------2</link>
            <guid isPermaLink="false">https://medium.com/p/916b6f3e2934</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[database-design]]></category>
            <category><![CDATA[b-tree]]></category>
            <dc:creator><![CDATA[Nimrod Shneor]]></dc:creator>
            <pubDate>Wed, 10 Mar 2021 08:00:39 GMT</pubDate>
            <atom:updated>2021-03-26T10:52:47.938Z</atom:updated>
            <content:encoded><![CDATA[<p>As part of a recent personal journey to better understand databases and better learn Rust, I have recently took on the project of writing a simple key-value storage engine. Crazy, right? Lets get started!</p><h3>B-Trees vs LSM Trees</h3><p>The first thing one must think of when writing a key-value storage engine is -”How should I store my data so that I can perform reads and writes efficiently?”; The two most common approaches for storing data on disk are B-Trees and LSM Trees.</p><p><a href="https://en.wikipedia.org/wiki/B-tree">BTrees</a> have been around for five decades and are used in “traditional” SQL databases such as PostgreSQL as an index on tables. A BTree is essentially a generalization of a Binary Search Tree, by allowing a “branching factor” larger than two (parameterized as <em>t</em>). Thus, BTrees are well suited for reads; reads run in <em>O(tlogₜ(N))</em> for a tree with N keys (This can be improved using binary search), but less for writes which at worst case require <em>O(tlogₜ(N))</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*ABSTmbYOn0ntBO1eYp1cJQ.png" /><figcaption>From the “BTree” wikipedia page — a tree with up to four keys in each node and five children in each internal node</figcaption></figure><p>On the other hand, <a href="https://en.wikipedia.org/wiki/Log-structured_merge-tree">LSM-Trees </a>(Log Structured Merge Trees) are a seemingly newer invention (at least, newer to me) usually used by newer “NoSQL” databases for example: “Scyalla”, “RocksDB”, “BigTable” etc. An LSM-Tree essentially takes a simple log and extends it by dumping the log to disk once it reaches a certain size (Commonly referred to as a “segment”). Concurrently a designated process is responsible for merging the previously dumped segments. Thus, depending on the implementation, a write is as simple as appending to a file and runs in <em>O(1)</em> while reads can be as slow as reading all the data in all the segment from the latest to the oldest, i.e. <em>O(N)</em>. The segments themselves can be kept sorted which might slow down writes but can speed up reads and merges drastically — mergers can be done efficiently using a procedure similar to the one used in <a href="https://en.wikipedia.org/wiki/Merge_sort#Bottom-up_implementation">“merge-sort”</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ngPVEscxHnZaPyV5HItuA.png" /><figcaption>From the “LSM-Tree” wikipedia page</figcaption></figure><h3>A Persistent B-Tree</h3><p>After considering the alternatives I’ve decided to write a “traditional” BTree.</p><p>To make things simpler we are going to store the tree in a single file and the leaf nodes will contain our keys and values (This variation is called a B⁺Tree). Thus we will need to restrict the size of our keys and values as they need to somehow fit in a single page.</p><p>A BTree stores its nodes to disk in “pages” (Traditionally of size 4096 bytes), thus, minimizing the number of I/O to disk as the operating system fetches chunks of memory in “pages” — For example; a BTree with t=100 can lookup a key in a tree with 1 million keys in just <strong>three</strong> I/Os. Lets look at a naive yet effective design of a page representing a node —</p><p><em>An internal node -</em></p><pre>| IS-ROOT 1-byte| NODE-TYPE 1-byte | PARENT OFFSET - 8 bytes |      | Number of children - 8 bytes |<br>| Key #0 - ? bytes | Key #2 - ? bytes | ...<br>| Child Offset #0 - 8 bytes| Child offset #1 - 8 bytes | ...</pre><p><em>A leaf node-</em></p><pre>| IS-ROOT 1-byte| NODE-TYPE 1-byte | PARENT OFFSET - 8 bytes |      | Number of pairs - 8 bytes |<br>| Key #0 - ? bytes | Value #0 - ? bytes | ...<br>| Key #N - ? bytes | Value #N - ? bytes |</pre><p>How long should we limit our keys given the above layout? Lets do some “over the napkin” arithmetic; Lets say we would like to support a maximum branching factor of 200 — That means that a leaf node needs to accommodate up to 200 key-value pairs:</p><pre>SPACE_FOR_PAIRS = PAGE_SIZE — HEADER_SIZE = 4096–18 = 4078 bytes.</pre><pre>MAX_SIZE_OF_PAIR = SPACE_FOR_PAIRS / MAX_BRANCHING_FACTOR = <br>4078 / 200 ~= 20 bytes. (78 bytes remain as junk)</pre><p>Thus each pair is twenty bytes long — For simplicity we will keep our values in the leaf nodes; alternatively, we could have allowed for variable sized values by keeping a <strong>pointer </strong>to the values in the leafs with the added cost of another I/O to disk. Since the keys and values should take up to twenty bytes we will simply split that between them: ten bytes for keys and ten bytes for values. To keep things simple we will treat our keys and values as UTF-8 encoded strings.</p><h3>A Node struct:</h3><p>Lets look at a Node struct capturing the design we have thus far-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a64d2a0520586c73f2643eeec89a4b65/href">https://medium.com/media/a64d2a0520586c73f2643eeec89a4b65/href</a></iframe><p>Given the design we have we can now write the conversion of Pages to Nodes and Nodes to Pages-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf1df0b64a16441671d809634bb6212b/href">https://medium.com/media/bf1df0b64a16441671d809634bb6212b/href</a></iframe><h3>A Page struct:</h3><p>This is a simple wrapper for a page of memory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/023ae87d3a9bfd22905020589625afd1/href">https://medium.com/media/023ae87d3a9bfd22905020589625afd1/href</a></iframe><h3>Conclusion:</h3><p>In this first chapter we have designed our on disk page (i.e. node) structure and written methods to serialize nodes to pages and back. In the next chapter we will start writing the BTree.</p><p>The entire source code including tests and more can be found at - <a href="https://github.com/nimrodshn/btree">https://github.com/nimrodshn/btree</a>, PRs are most welcome!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=916b6f3e2934" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How writing in Rust made me a better Go developer]]></title>
            <link>https://nimrodshn.medium.com/how-writing-in-rust-made-me-a-better-go-developer-4aaecb580ef2?source=rss-d3aeafdf4d03------2</link>
            <guid isPermaLink="false">https://medium.com/p/4aaecb580ef2</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[Nimrod Shneor]]></dc:creator>
            <pubDate>Mon, 06 Jul 2020 13:02:27 GMT</pubDate>
            <atom:updated>2020-07-06T13:02:27.726Z</atom:updated>
            <content:encoded><![CDATA[<h3>A bit of background</h3><p>I have been writing Go professionally for about two years now as part of a large corporation. Recently I have decided to pick up Rust; I started the way I usually approach picking up new languages — Writing a <a href="http://github.com/nimrodshn/orpheus">small project</a> while reading the documentation (in this case — the <a href="https://doc.rust-lang.org/book/">Rust book</a>).</p><p>My first impression of the language was how “large” and verbose it is compared to Go. It took me a month and a half to finish “The Book”. For comparison, <a href="https://tour.golang.org/">“A tour of Go”</a> took me about a week. Go is simply a “smaller” language with less features. This meant that picking up Rust was <strong>much</strong> harder and required much more cognitive load.</p><h3>What do you mean by “more verbose”?</h3><p>Lets look at the following code written in Go:</p><pre>type Publisher interface {<br>  Publish(s []string) error<br>}</pre><p>For comparison here is the above interface written as a “trait” in Rust:</p><pre>pub trait Publisher {<br>  fn publish(&amp;self, s &amp;str);<br>}</pre><p>Now lets take a look at the following implementations:</p><p>Go:</p><pre>type NewYorkTimes struct{}<br>func (t *NewYorkTimes) Publish(s []string) {<br>  fmt.Println(&quot;Publishing... %s&quot;, s)<br>}</pre><p>Rust:</p><pre>struct NewYorkTimes {}</pre><pre>impl Publisher for NewYorkTimes {<br>  fn publish(&amp;self, s &amp;str) {<br>    println!(&quot;Publishing... {}&quot;, s);<br>  }<br>}</pre><h3>Getting over the hurdle</h3><p>After about a month of reading regularly about Rust and writing on and off, I found my self conforming to the language; the compilers strict requirements meant I had to think of each allocation and reference I made — “Who was owning that data?”, “How long does this reference remain valid?”. These types of questions didn’t occur to me coming from Go. Then I looked at old code I had written; I found my self asking <strong>the same</strong> questions: “Is this reference going to be valid by the end of this method?”, “Can this shared mutable reference lead to unexpected behavior?” etc.</p><h3>Lets talk code</h3><p>Here is a real world example I found in my code base:</p><pre>type CidrValidator interface {<br>  func ValidateNetworkCIDRs(cidr []string)<br>}</pre><pre>type AWSCidrValidator struct{}</pre><pre>func (v *AWSCidrValidator) ValidateNetworkCIDRs(cidr []string) {<br>  // Do something here ..<br>}</pre><pre>type GCPCidrValidator struct{}</pre><pre>func (v *GCPCidrValidator) ValidateNetworkCIDRs(cidr []string) {<br>  // Do something here ..<br>}</pre><pre>...</pre><pre>func validateNetworkCIDRs(network models.Network, isMultiAZ bool, cloudProviderID string) error {<br>	validator, err := getCIDRValidator(cloudProviderID)<br>	if err != nil {<br>		return err<br>	}<br>	return validator.ValidateNetworkCIDRs(network, isMultiAZ)<br>}<br><br>func getCIDRValidator(cloudProviderID string) (validators.CidrValidator, error) {<br>	switch cloudProviderID {<br>	case cloudprovider.AwsCloudProviderID:<br>		return &amp;validators.AWSCidrValidator{}, nil<br>	case cloudprovider.GcpCloudProviderID:<br>		return &amp;validators.GCPCidrValidator{}, nil<br>	default:<br>		return nil, errors.Errorf(&quot;unsupported cloud provider &#39;%s&#39;&quot;, cloudProviderID)<br>	}<br>}</pre><p>These functions (originally methods) validate a REST request to one of our HTTP services containing some <a href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing">CIDR address</a>. Lets try and write the getCIDRValidator function in Rust:</p><pre>enum CidrValidator {<br>  GCP<br>  AWS<br>}</pre><pre>impl CidrValidator {<br>  fn validate(&amp;self) {<br>    // Do some validation here<br>  }<br>}</pre><pre>fn get_cidr_validator(cloud_provider_id: &amp;str) -&gt; Result&lt;CidrValidator, Error&gt; {<br>    match cloud_provider_id {<br>        &quot;aws&quot; =&gt; Ok(CidrValidator::AWS),<br>        &quot;gcp&quot; =&gt; Ok(CidrValidator::GCP),<br>        _ =&gt; Err(Error::UnexpectedCloudProvider),<br>    }<br>}</pre><p>Two things are strikingly different:</p><ol><li>The use of <a href="https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html">Enums</a> and the match statement makes for a very slick and verbose code.</li><li>No new allocations are done on the heap for each call! This is extremely important, specifically on a garbage collected language like Go.</li></ol><p>Granted there are ways to get around these redundant allocations:</p><ol><li>The actual validation code is stateless thus using the validation logic as a method in a FooValidator is redundant — one can simply make the validation code <a href="https://en.wikipedia.org/wiki/Pure_function">pure function</a>. Thus we can alleviate the redundant allocations.</li><li>Allocate the {GCP,AWS}Validator as fields of the parent struct. As mentioned before the above functions are originally methods of some “parent” struct. This has the limitation of using a stateless struct to perform some “validation” computation — which is, again, redundant. But alleviates the heap-allocations-per-request.</li></ol><h3>Summary</h3><p>My aim writing this article was to show how writing code in one language can shed light on code written in another language and <strong><em>enrich everyone</em></strong>, both camps of the battlefield.</p><p>Hope you guys enjoyed this article!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4aaecb580ef2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to deploy Prometheus on Openshift 4 and configure it to scrape Pods metrics]]></title>
            <link>https://nimrodshn.medium.com/how-to-deploy-prometheus-on-openshift-4-and-configure-it-to-scrape-pods-metrics-a020ed03d5d8?source=rss-d3aeafdf4d03------2</link>
            <guid isPermaLink="false">https://medium.com/p/a020ed03d5d8</guid>
            <category><![CDATA[red-hat-openshift]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[openshift-4]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[monitoring]]></category>
            <dc:creator><![CDATA[Nimrod Shneor]]></dc:creator>
            <pubDate>Thu, 18 Jun 2020 17:40:23 GMT</pubDate>
            <atom:updated>2020-10-13T17:12:38.077Z</atom:updated>
            <content:encoded><![CDATA[<h3>Step 1: Setting up Openshift</h3><p>The simplest way to setup Openshift locally is using <a href="https://developers.redhat.com/products/codeready-containers/overview">“CodeReady Containers”</a>. It provides a minimal “Openshift 4” installation on a VM running locally. Follow the steps in the link above to setup you’re cluster.</p><h3>Step 2: Setting up Prometheus</h3><p>To set up Prometheus lets first create a namespace for it:</p><pre>oc new-project monitoring &amp;&amp; oc project monitoring</pre><p>Next, we need to deploy Prometheus:</p><pre>oc new-app prom/prometheus</pre><p>The above command will pull the latest Prometheus image to our clusters registry and create a “Deployment” of a single pod running Prometheus.</p><h3>Step 3: Expose Prometheus</h3><p>There are several ways to expose and application running on Openshift, I find the simplest way, for my own local use cases, is using a NodePort type service. (For more details see <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport">here</a>.)</p><p>To create a service for our prometheus application run the following command:</p><pre>oc expose dc prometheus --type=NodePort --generator=service/v1</pre><p>This will create a service for Prometheus:</p><pre>$ oc get service<br>NAME         TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE<br>prometheus   NodePort   172.30.84.198   &lt;none&gt;        9090:31138/TCP   9h</pre><p>Notice the port assigned to the service; this port will be used to access the service behind the clusters IP address. In this example the port assigned to my service is 31138.</p><p>To retrieve the crc cluster ip address run crc ip . Finally to access Prometheus use &lt;cluster-ip&gt;:31138 .</p><h3>Step 4: Configure Prometheus RBAC</h3><p>If you look at the logs of the Prometheus pod you have just deployed (by running oc logs promtheus ) you will find that its showing a lot of warnings and errors related to the fact that it isn’t authorized to List or Watch for Pods . In order to allow Prometheus to list and watch for pods, we need to create a ClusterRole and a ClusterRoleBinding for it:</p><p>For example here is a ClusterRole I create for Prometheus:</p><pre>apiVersion: rbac.authorization.k8s.io/v1<br>kind: ClusterRole<br>metadata:<br>  name: prometheus<br>rules:<br>- apiGroups:<br>  - &quot;&quot;<br>  resources:<br>  - pods<br>  verbs:<br>  - get<br>  - list<br>  - watch</pre><p>And a corresponding ClusterRoleBinding attached to the default service account in the monitoring project, used by Prometheus .</p><pre>apiVersion: rbac.authorization.k8s.io/v1<br>kind: ClusterRoleBinding<br>metadata:<br>  name: prom_role_binding<br>subjects:<br>- kind: ServiceAccount<br>  name: default<br>  namespace: monitoring<br>roleRef:<br>  kind: ClusterRole<br>  name: prometheus<br>  apiGroup: rbac.authorization.k8s.io</pre><p>Now Prometheus is ready to scrape!</p><h3>Step 5: Configure Prometheus to scrape pods metrics</h3><p>In order to configure Prometheus to scrape our pods metrics we need to supply it with a configuration file, to do that we will create our configuration file in a ConfigMap and mount it to a predefined path in the Prometheus container (namely /etc/prometheus/ ).</p><p>Here is and example config file I created to scrape all pods matching the label app=ocm-api-tests . The kubernetes_sd_configs allow Prometheus to retrieve scrape targets from <a href="https://kubernetes.io/">Kubernetes’</a> REST API and stay synchronized with the cluster state. In our example Prometheus is configured to <em>discover</em> pods running.</p><p>These are concurrent pods which run “load” testing against one of our backend services at “cloud.redhat.com”. Once the pods finish running their request against the backend service they expose their results (latency, throughout and errors) for Prometheus to scrape.</p><p>To find out more details about the scraping rules see <a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config">here</a>.</p><pre>$ cat prometheus.yml<br>global:<br>  scrape_interval:     5s <br>  evaluation_interval: 5s<br>scrape_configs: <br>  - job_name: ocm-api-tests<br>    scrape_interval: 10s<br>    kubernetes_sd_configs:<br>      - role: pod<br>    relabel_configs:<br>      - source_labels: [__meta_kubernetes_namespace]<br>        action: replace<br>        target_label: k8s_namespace<br>      - source_labels: [__meta_kubernetes_pod_name]<br>        action: replace<br>        target_label: k8s_pod_name<br>      - source_labels: [__address__]<br>        action: replace<br>        regex: ([^:]+)(?::\d+)?<br>        replacement: ${1}:8080<br>        target_label: __address__<br>      - source_labels: [__meta_kubernetes_pod_label_app]<br>        action: keep<br>        regex: ocm-api-tests</pre><p>Its important to name this file prometheus.yml since Prometheus is going to be looking for a config file with this specific name in the mounted path.</p><p>To create the the ConfigMap run the following:</p><pre>oc create configmap prom-config --from-file=prometheus.yml</pre><p>This will create a configmap named prom-config with the content of our config file.</p><p>Next, we need to edit the Prometheus deployment to mount this configmap under /etc/prometheus , to do this, run the following command:</p><pre>oc edit dc prometheus</pre><p>This command should open you’re default editor with the contents of the deployment file. Under volumes we will create a new volume pointing to our ConfigMap :</p><pre>      volumes:<br>      - emptyDir: {}<br>        name: prometheus-volume-1<br>      - configMap:<br>          defaultMode: 420<br>          name: prom-config<br>        name: prom-config-volume</pre><p>Next, under the Prometheus container we will create the <em>volume mount</em>:</p><pre>        volumeMounts:<br>        - mountPath: /prometheus<br>          name: prometheus-volume-1<br>        - mountPath: /etc/prometheus/<br>          name: prom-config-volume</pre><p>Once saved, the edit will trigger a redeployment of Prometheus with our configuration in place.</p><p>Thats it, were all done! Hope you enjoyed this walk through.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a020ed03d5d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>