obfuscurity / descartes

Introspective dashboard for Graphite
MIT License
502 stars 65 forks source link

Import graph in directories #152

Closed adrienbrault closed 10 years ago

adrienbrault commented 10 years ago

I have some graphs that are in a directory (with a dot in the name), and they dont show up in the import dialog.

obfuscurity commented 10 years ago

Need more info, please. What does your directory structure look like? Any errors in the web console?

adrienbrault commented 10 years ago

I think it is because there are special characters (like @) in the metrics names. I haven't had enough time today to make a fix, but I've seen it's in the javascript.

obfuscurity commented 10 years ago

Yeah I can imagine that would cause problems. I'm surprised Graphite even accepts those as valid characters.

adrienbrault commented 10 years ago

So, for the context, I am using hostedgraphite.com. I managed to get it to work using this patch:

--- a/lib/descartes/public/js/render-common.js
+++ b/lib/descartes/public/js/render-common.js
@@ -180,9 +180,11 @@ var constructGraphUrl = function(graph) {
   var myParseUrl = parseUrl(graphiteUrl);

   myAuthUrl = myParseUrl.protocol + '://' + graphiteUser + ':' + graphitePass + '@' + myParseUrl.host + ':' + myParseUrl.port;
+  myAuthUrl = graphiteUrl;

   // add our remaining params to the URL
   var myGraphUrl = myAuthUrl + '/render/?' + 'height=' + myGraphHeight + '&width=' + myGraphWidth;
+
   var targets = '';
   for (var j in graph.targets) {
     if (graph.targets[j].axis === 2) {
diff --git a/lib/descartes/public/js/render-graph.js b/lib/descartes/public/js/render-graph.js
index b7ec6c2..a0dbbd4 100644
--- a/lib/descartes/public/js/render-graph.js
+++ b/lib/descartes/public/js/render-graph.js
@@ -75,11 +75,7 @@ var treeversal = function(cb, node) {
   if (node == null) {
     node = "";
   }
-  if (node === "") {
-    prefix = "*";
-  } else {
-    prefix = node + ".*";
-  }
+  username = 'adrien.brault@hautelook.com';
   return $.ajax({
     beforeSend: function(xhr) {
       var creds = graphiteUser + ':' + graphitePass;
@@ -91,9 +87,13 @@ var treeversal = function(cb, node) {
     },
     dataType: 'json',
     error: function(xhr, textStatus, errorThrown) { console.log(errorThrown); },
-    url: graphiteUrl + "/browser/usergraph/?query=" + prefix + "&format=treejson&contexts=1&path=" + node
+    url: "{0}/browser/usergraph/?user={1}&format=treejson&contexts=1&path={2}"
+        .replace("{0}", graphiteUrl)
+        .replace("{1}", encodeURIComponent(username))
+        .replace("{2}", encodeURIComponent(node))
   }).done(function(d) {
     for (var i in d) {
       if (d[i].leaf === 0) {
         treeversal(cb, d[i].id);
       } else {

The issue is that the username contains dots, so graphite cannot correctly guess what the username really is.

The other issue I had is that the script removed the base path of the graphite url.

obfuscurity commented 10 years ago

I don't see us merging anything like this in, since it's specific to HostedGraphite.com. Glad you got it working for yourself though. :+1: