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

*: add trend api. #881

Merged
merged 6 commits into from
Dec 26, 2017
Merged

*: add trend api. #881

merged 6 commits into from
Dec 26, 2017

Conversation

disksing
Copy link
Contributor

@disksing disksing commented Dec 12, 2017

It's for visualization of cluster's activities.

Usage example:

$ curl -s "http://127.0.0.1:2379/pd/api/v1/trend?from=1513086582"  // unix epoch.
{
  "stores": [
    {
      "id": 1,
      "address": "127.0.0.1:20161",
      "state_name": "Up",  // Up/Down/Offline/Disconnect
      "capacity": 5368709120,  // in bytes.
      "available": 5279425783, // in bytes.
      "region_count": 64,
      "leader_count": 20,
      "start_ts": "2017-12-19T15:18:20+08:00",
      "last_heartbeat_ts": "2017-12-19T15:20:00.874237675+08:00",
      "uptime": "1m40.874237675s",
      "hot_write_flow": 89884,   // sum of all hot regions's write flows, in bytes.
      "hot_write_region_flows": [  // a list of region's write flows, in bytes.
        89884
      ],
      "hot_read_flow": 0,
      "hot_read_region_flows": null
    },
    {
      ...
    },
   
  ],
  "history": {
    "start": 1513086582,  // start time of the history.
    "end": 1513086616,    // end time of the history.
    "entries": [
      {
        "from": 4,    // source store id.
        "to": 1033,  // target store id.
        "kind": "region",  // resource kind, "region" or "leader".
        "count": 9   // total count of resource during the time.
      },
      {
        "from": 5,
        "to": 1033,
        "kind": "leader",
        "count": 8
      },
      {
        ...
      }
    ]
  }
}

@disksing disksing added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 12, 2017
@disksing disksing removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 21, 2017
@disksing
Copy link
Contributor Author

PTAL @Connor1996 @siddontang @nolouch

Copy link
Member

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

histories = append(histories, OperatorHistory{
FinishTime: now,
From: removePeerStores[i],
To: addPeerStores[i],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no order guarantee.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in fact we do not care about the order, only the changing trend.

if stats == nil {
return
}
if stat, ok := stats[storeID]; ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not thread-safe here by design?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's safe as each request are accessing different copy.

op := elem.Value.(*schedule.Operator)
if op.Kind()&mask != 0 {
operators = append(operators, op)
var histories []schedule.OperatorHistory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

histories := make( []schedule.OperatorHistory, 0, c.histories.Len())

Len() is O(1)

@tiancaiamao
Copy link
Contributor

LGTM

@disksing disksing merged commit 5598c00 into tikv:master Dec 26, 2017
@disksing disksing deleted the history branch December 26, 2017 07:16
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

Successfully merging this pull request may close these issues.

4 participants