nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: godaddy/kubernetes-external-secrets
Pull request #310 (2020-03-25 01:30:24)

Remove newlines, spaces, and tabs from status string
Vault error messages seem to have newlines and tabs which don't look great in k8s status message. This PR cleans up the status string before sending to k8s.

Before:
<img width="554" alt="Screen Shot 2020-03-24 at 9 22 13 PM" src="https://user-images.githubusercontent.com/5752872/77492292-95d01780-6e16-11ea-93c0-3f770c7a1642.png">

After:
<img width="735" alt="Screen Shot 2020-03-24 at 9 29 21 PM" src="https://user-images.githubusercontent.com/5752872/77492298-9a94cb80-6e16-11ea-8dba-97902f1127d0.png">

Flydiverny: Sounds good to me, can we add a test or two? 
davidcorbin: Sounds good. Will do 👍


On March 24, 2020 at 11:49:59 PM, Markus Maga (notifications@github.com(mailto:notifications@github.com)) wrote:

>  
> Sounds good to me, can we add a test or two?
>  
>  
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub(https://github.com/godaddy/kubernetes-external-secrets/pull/310#issuecomment-603624981), or unsubscribe(https://github.com/notifications/unsubscribe-auth/ABL4QKCKY6BOLVZKTRU7ZRTRJF5OPANCNFSM4LTDNZFQ).
>  
>  
>  



Patch:
diff --git a/lib/poller.js b/lib/poller.js
index ea61251..a9577b0 100644
--- a/lib/poller.js
+++ b/lib/poller.js
@@ -161,6 +161,9 @@ class Poller {
   }
 
   async _updateStatus (status) {
+    // Remove newlines, spaces, and tabs from status string
+    status = status.replace(/(\r\n|\n|\r| (?= ))/gm, '').replace(/\t/g, ' ')
+
     try {
       this._logger.debug(`updating status for ${this._namespace}/${this._name} to: ${status}`)
       await this._status.put({


Test patch:
diff --git a/lib/poller.test.js b/lib/poller.test.js
index ce747eb..3c7e2a1 100644
--- a/lib/poller.test.js
+++ b/lib/poller.test.js
@@ -405,6 +405,15 @@ describe('Poller', () => {
       expect(error).to.not.equal(undefined)
       expect(error.message).equals('Not Found')
     })
+
+    it('handles odd whitespace and newlines in status', async () => {
+      const poller = pollerFactory()
+
+      await poller._updateStatus('\n\n\nLots      of spaces\n\n\n').then(() => {
+        const statusMessage = externalSecretsApiMock.status.put.getCall(0).args[0].body.status.status
+        expect(statusMessage).to.equal('Lots of spaces')
+      })
+    })
   })
 
   describe('_scheduleNextPoll', () => {
Repository: godaddy/kubernetes-external-secrets
Pull request #357 (2020-04-22 22:42:28)

Add last_state metric
It is a bit difficult to alert on sync_calls since they trigger into an error state and may stay there.
This adds the gauge last_state.  With last_state, people can easily alert on a value < 0 to indicate failure.


Patch:
diff --git a/README.md b/README.md
index 90838b7..6293f51 100644
--- a/README.md
+++ b/README.md
@@ -435,6 +435,7 @@ kubernetes-external-secrets exposes the following metrics over a prometheus endp
 | Metric                                    | Description                                                                     | Example                                                                       |
 | ----------------------------------------- | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
 | `sync_calls`                              | This metric counts the number of sync calls by backend, secret name and status  | `sync_calls{name="foo",namespace="example",backend="foo",status="success"} 1` |
+| `last_state`                              | A value of -1 or 1 where -1 means the last sync_call was an error and 1 means the last sync_call was a success  | `last_state{name="foo",namespace="example",backend="foo"} 1` |
 
 
 ## Development
diff --git a/lib/metrics.js b/lib/metrics.js
index 83095e0..efa4a88 100644
--- a/lib/metrics.js
+++ b/lib/metrics.js
@@ -15,6 +15,12 @@ class Metrics {
       labelNames: ['name', 'namespace', 'backend', 'status'],
       registers: [registry]
     })
+    this._lastState = new Prometheus.Gauge({
+      name: 'last_state',
+      help: 'Value -1 if the last sync was a failure, 1 otherwise.',
+      labelNames: ['name', 'namespace', 'backend'],
+      registers: [registry]
+    })
   }
 
   /**
@@ -31,6 +37,19 @@ class Metrics {
       backend,
       status
     })
+    if (status === 'success') {
+      this._lastState.set({
+        name,
+        namespace,
+        backend
+      }, 1)
+    } else {
+      this._lastState.set({
+        name,
+        namespace,
+        backend
+      }, -1)
+    }
   }
 }
 


Test patch:
diff --git a/lib/metrics-server.test.js b/lib/metrics-server.test.js
index f5c8b7e..b9ffe2b 100644
--- a/lib/metrics-server.test.js
+++ b/lib/metrics-server.test.js
@@ -57,5 +57,7 @@ describe('MetricsServer', () => {
 
     expect(res.text).to.have.string('sync_calls{name="foo",namespace="example",backend="foo",status="success"} 1')
     expect(res.text).to.have.string('sync_calls{name="bar",namespace="example",backend="foo",status="failed"} 1')
+    expect(res.text).to.have.string('last_state{name="foo",namespace="example",backend="foo"} 1')
+    expect(res.text).to.have.string('last_state{name="bar",namespace="example",backend="foo"} -1')
   })
 })