stephenyeargin / hubot-grafana

📈🤖 Query Grafana dashboards
http://docs.grafana.org/tutorials/hubot_howto/
MIT License
154 stars 48 forks source link

Feature/small refactoring #176

Closed KeesCBakker closed 3 months ago

KeesCBakker commented 3 months ago

Some small refactoring:

KeesCBakker commented 3 months ago

No I see npm test is a bit slower as it should be, as it first tries to sync all the packages. This is due to the bootstrap script. Think that one is needed for our GitHub workflows. Let's see if we can decouple them.

KeesCBakker commented 3 months ago

Another problem I see is that halve of the time the tests are failing on my local machine:

image

When I run them again, everything works fine.

image

Looking into why. There might be some test interactions...

KeesCBakker commented 3 months ago

Made the testing faster in the dev container by using a volume (https://code.visualstudio.com/remote/advancedcontainers/improve-performance#_use-a-targeted-named-volume).

Test should respond with a png graph in the default s3 region fails half of the time (at my machine) because it sometimes returns panel 3 and sometimes 8. As we do not really care about the panel ID here (we're testing S3), I deduce the panel from the response.

    it('should respond with a png graph in the default s3 region', async () => {
      let response = await ctx.sendAndWaitForResponse('@hubot graf db AAy9r_bmk:cpu server=ww3.example.com now-6h');
      response = response.replace(/\/[a-f0-9]{40}\.png/i, '/abdcdef0123456789.png');

      let panelRegex = /panelId=(\d+)/
      expect(response).to.match(panelRegex);

      let panelId = response.match(panelRegex)[1]
      expect(response).to.eql(
        'CPU: https://graf.s3.us-standard.amazonaws.com/grafana/abdcdef0123456789.png - https://play.grafana.org/d/AAy9r_bmk/?panelId=' + panelId + '&fullscreen&from=now-6h&to=now&var-server=ww3.example.com'
      );
    });

Now it always works.

KeesCBakker commented 3 months ago

@stephenyeargin think this branch is ready to ship. Please check if you want to drop support for node 16 and you like the way we've refactored the testing and bootstrapping.