Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What are the requirements for the endpoint response to make it work for .updateData? #42

Open
denismakogon opened this issue Apr 14, 2018 · 5 comments

Comments

@denismakogon
Copy link

denismakogon commented Apr 14, 2018

So, i'm trying to implement simple thing - instead of relying on static JSON file call external service to return JSON object.

So, i have an endpoint that returns the following JSON:

{
    "connections": [
        {
            "class": "normal",
            "metrics": {
                "danger": 10,
                "normal": 3000
            },
            "source": "event-source",
            "target": "INTERNET"
        },
        {
            "class": "normal",
            "metrics": {
                "danger": 10,
                "normal": 3000
            },
            "source": "INTERNET",
            "target": "service-A"
        },
        {
            "class": "normal",
            "metrics": {
                "danger": 10,
                "normal": 3000
            },
            "source": "service-A",
            "target": "INTERNET"
        },
        {
            "class": "normal",
            "metrics": {
                "danger": 10,
                "normal": 3000
            },
            "source": "service-A",
            "target": "service-B"
        },
        {
            "class": "normal",
            "metrics": {
                "danger": 10,
                "normal": 3000
            },
            "source": "INTERNET",
            "target": "event-target"
        },
        {
            "class": "normal",
            "metrics": {
                "danger": 10,
                "normal": 3000
            },
            "source": "event-target",
            "target": "event-subscriber"
        },
        {
            "class": "normal",
            "metrics": {
                "danger": 10,
                "normal": 3000
            },
            "source": "service-B",
            "target": "event-target"
        }
    ],
    "name": "edge",
    "nodes": [
        {
            "class": "normal",
            "displayName": "INTERNET",
            "name": "INTERNET",
            "renderer": "focusedChild"
        },
        {
            "class": "normal",
            "displayName": "EventSource",
            "name": "event-source",
            "renderer": "focusedChild"
        },
        {
            "class": "normal",
            "connections": [
                {
                    "class": "normal",
                    "metrics": {
                        "danger": 10,
                        "normal": 3000
                    },
                    "source": "INTERNET",
                    "target": "service-B"
                }
            ],
            "displayName": "ServiceA",
            "name": "service-A",
            "nodes": [
                {
                    "class": "normal",
                    "displayName": "INTERNET",
                    "name": "INTERNET",
                    "renderer": "focusedChild"
                },
                {
                    "class": "normal",
                    "displayName": "ServiceB",
                    "name": "service-B",
                    "renderer": "focusedChild"
                }
            ],
            "renderer": "focusedChild"
        },
        {
            "class": "normal",
            "displayName": "Service-A",
            "name": "service-A",
            "renderer": "focusedChild"
        },
        {
            "class": "normal",
            "displayName": "EventTarget",
            "name": "event-target",
            "renderer": "focusedChild"
        },
        {
            "class": "normal",
            "displayName": "EventSubscriber",
            "name": "event-subscriber",
            "renderer": "focusedChild"
        }
    ],
    "renderer": "global"
}

cURL output:

* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /vizceral-config HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Length: 1729
< Content-Type: application/json; charset=utf-8
< Date: Sat, 14 Apr 2018 20:40:17 GMT
< 

My code looks like this:

  beginSampleData () {
    this.traffic = { nodes: [], connections: [] };
    request.get(`https://<service-url>/vizceral-config`)
        .set('Accept', 'application/json')
        .end((err, res) => {
            if (res && res.status === 200) {
                this.traffic.clientUpdateTime = Date.now();
                this.updateData(res.body);
            }
        });
    }

  update () {
      request.get(`https://<service-url>/vizceral-config`)
          .set('Accept', 'application/json')
          .end((err, res) => {
              if (res && res.status === 200) {
                  this.traffic.clientUpdateTime = Date.now();
                  this.updateData(res.body);
              }
          });
    }

  componentDidMount () {
      this.checkInitialRoute();
      this.beginSampleData();

      // Listen for changes to the stores
      filterStore.addChangeListener(this.filtersChanged);
      this.timer = setInterval(this.update.bind(this), 100000);
  }

  componentWillUnmount () {
      filterStore.removeChangeListener(this.filtersChanged);
      clearInterval(this.timer);
  }

But i'm facing the problem, i can't get graph visualized, it stucks loading the graph for some reason:
screen shot 2018-04-14 at 11 54 48 pm

I do see that vizceral app sends the request to the endpoint and it responds back with appropriate response (you can see that above). However, can't get graph visualized.

Looking forward to get help on this, thanks.

@denismakogon
Copy link
Author

tried to do the same with fetch.get instead of request.get, but didn't work as well.

@denismakogon
Copy link
Author

Tried a bit different approach to make the endpoint return a JSON file, nothing actually changed, UI still hangs.
Detailed response:

*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /config.json HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Disposition: attachment;filename=config.json
< Content-Length: 1704
< Content-Type: application/octet-stream
< Date: Sun, 15 Apr 2018 07:55:45 GMT
< 

@cglewis
Copy link

cglewis commented Jun 6, 2018

@denismakogon I'm doing a similar setup - chrome console logs is throwing the allow-origin error for me, so that might be what you're running into as well:

 No 'Access-Control-Allow-Origin' header is present on the requested resource.

@franpog859
Copy link

@cglewis Try to paste the first function at the beginning of your service - after the app declaration. It could be the issue with the CORS
https://enable-cors.org/server_expressjs.html

@nevosial
Copy link

I had a similar issue, but it worked after i did certain changes, so summing it up here,

  1. My updated trafficFlow.jsx code is quite similar to what @denismakogon has shown above. I use request.get() and set the timer in the componentDidMount() to match the time required to fetch the data.

  2. My backend api written using flask and returns a json object using the jsonify() function available from flask.

  3. I enabled CORS using the following approach while declaring my flask app.

from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants