Commit Graph

545 Commits

Author SHA1 Message Date
Hector Sanjuan
89b8fe106e Fix #275: Wait for Raft updates before snapshotting on shutdown
Raft will fail to take a snapshot when applied index is
different from the last index. Therefore, we wait for
all updates to be aplied before snapshotting.

If still it doesn't work, we retry a few times.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2018-01-09 15:02:47 +01:00
Hector Sanjuan
b2651b52ea Refactor some stuff to please codeclimate
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-12-08 17:05:21 +01:00
Hector Sanjuan
b21d313547 rest/client: Return regular errors.
We had a problem happening when assigning the returned *api.Error
to default 'error' type.

Things like "if err != nil" would not work even when *api.Error is nil
I'm not sure why this happens, but this is very confusing for the user
integrating on top. It is better that we just return plain go errors.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-12-08 15:39:30 +01:00
Hector Sanjuan
62e8a011d0 rest/client: Allow passing Host and Port in the config.
This is easier in many cases and does not make the user
parse a multiaddress.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-12-08 15:38:30 +01:00
Hector Sanjuan
faeaf5dc6a api: attempt to trick code climate on dup code
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-12-08 01:09:52 +01:00
Hector Sanjuan
6a243df4da api: Support /ws/ and /dns/ multiaddresses parsing. Log all errors
The multiaddresses protocols for websockets and dns are only registered
with init() function when loading the modules. ipfs-cluster-ctl
uses just the api, which did not load these modules so converting
from serialized types caused bad panics.

We have also ignored errors in the api library under the thinking that it
would only parse things serialized by us, but this has made parsing errors
to go unnoticed. From now, all errors are logged and some precautions
are taking to better handle the possibility of nil objects.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-12-08 01:05:49 +01:00
Hector Sanjuan
72928d5e3b client: do not cancel request context while reading the answer
Apparently, cancelling the request context closes the response body
prematurely, before it's being fully read.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-12-08 00:22:01 +01:00
Hector Sanjuan
7b9ef115a2 rest/api/client: re-use the http client
This allows taking advantage of connection keep alive by having the
api client re-use the same connection. Additionally, an option
to close connections after every request is provided.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-12-07 11:27:37 +01:00
Hector Sanjuan
6d7c65aaa6 Review #260: Address comments
* Set default logging facility
* Remove old keep-alive comment in tests
* Use a port for TestPeersWithErrors which is not default

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-12-07 00:04:51 +01:00
Hector Sanjuan
0a8edc17c9 Fix #260: Add REST API client and use it in ipfs-cluster-ctl
This adds the pakage api/rest/client which implements a go-client
for the REST API component. It also update the ipfs-cluster-ctl
tool to rely on it.

Originally, I wanted this to live it in it's own separate repository,
but the api client uses /api/types.go, which is part of cluster.

Therefore it would need to import all of cluster as a dependency.
ipfs-cluster-ctl would also need to import go-ipfs-cluster-api-client
as a dependency, creating circular gx deps which would be a mess to
maintain.

Only the splitting of cluster in multiple repositories (at least for
api, rest, ipfs-cluster-ctl, rest/client and test) would allow better
dependency management by allowing rest/client and the ctl tool
to only import what is needed, but this is something which brings
maintenance costs and can probably wait a bit until cluster is more stable.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-12-06 20:12:01 +01:00
Hector Sanjuan
0693ff429e fix spelling: Fix spelling errors
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-12-06 15:15:54 +01:00
Hector Sanjuan
1e87fccf0e
Merge pull request #257 from te0d/feat/add-peer-identifier
Added Hostname Property to Configuration
2017-12-04 14:25:49 +01:00
Hector Sanjuan
84816729ff
Merge pull request #252 from te0d/feat/add-pin-name
Feat/add pin name
2017-12-04 14:25:39 +01:00
Hector Sanjuan
d6a7caf7a4 Issue #259: Address CR comments
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-12-04 13:59:48 +01:00
Tom O'Donnell (te0d)
7d43be33a4 Added Peername Configuration Test and Renamed to Peername
I've modified the peer identifier to be 'peername'. I've also
modified the TestLoadJSON to check that it is correctly read from
config and set to a default if empty.

Also added 'peername' fields to configurations for various tests.
2017-12-01 13:50:13 -05:00
Hector Sanjuan
4922c95589 Support --local parameter for Status[Local] and Sync[Local] operations
This allows to call the Rest API's status and sync endpoints with a
"?local=true" parameter. This will trigger operations but only on the
local peer. Cluster *Local and RPC-*Local methods have been accordingly,
although they are aliases for the PinTracker methods (but otherwise they
would not be exposed in external APIs). ipfs-cluster-ctl has been updated to
support the new flag.

The rationaly behind this feature is that sometimes, a single cluster peer
(or the ipfs daemon in it) is misbehaving. The user then wants to Sync,
Recover, or see Status for that single peer. This is specially relevant
when working with big pinsets in larger clusters, as a Status() call will
be considerably more expensive when broadcasted everywhere.

Note that the Rest API keeps returning GlobalPinInfo objects even on local=true
calls. This ensures that the user always gets the same datatype from an endpoint.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-12-01 12:56:26 +01:00
Tom O'Donnell (te0d)
d1ef3d0493 Fixes for Adding Peer Identifier from Code Review
I renamed Hostname to simply Name as to not imply relation to DNS.
Removed quotes from formatter, used helper function setting config,
and added defensive error check.
2017-11-30 15:21:53 -05:00
Tom O'Donnell (te0d)
3f28da4415 Fixed Pin's Name Attribute when not Specified
When not specified, the name was being assigned to whichever name
was assigned to the previous pin. Not sure exactly what was
happening, but it works after removing omitempty. The idea was to
make Name optional, but here it will always be assigned.
2017-11-30 10:14:24 -05:00
Tom O'Donnell (te0d)
bd829c3f31 Added Name to Pinned Items
Added Name field to be a part of the stored state of a Pin. This
allows the name to be stored as a part of the consensus if needed.

This is the bare minimum to use. Some other calls like status need
to be checked out.
2017-11-30 10:14:24 -05:00
Hector Sanjuan
e824aea55e RecoverAll: Implement RecoverAllLocal() which recovers all pins in a peer
This adds API, RPC calls to support RecoverAllLocal() (and expose RecoverLocal()
on the Rest API too). cluster-ctl is updated accordingly.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2017-11-30 01:53:31 +01:00
Tom O'Donnell (te0d)
c6c8512a27 Added Hostname Property to Configuration
I added a "hostname" property to a node's configuration file. Its
value defaults to the hostname provided by the OS, but can be
modified to anything beside an empty string in the config file.

The "hostname" was added to the output of the "id" call. Thus, peer
hostnames are available when listing peers.
2017-11-29 15:44:31 -05:00
Hector Sanjuan
f37c6c0620 Issue #219: Fix api types tests
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-11-10 18:23:38 +01:00
Hector Sanjuan
2a616aeddb Issue #219: Provide a list of peers and a list of addresses in the ID object.
Fix cluster-ctl to show right number of peers

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-11-10 16:11:09 +01:00
Hector Sanjuan
fb8fdb94c5 Issue #162: Improve Config.ToJSON() tests
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-10-20 10:42:41 +02:00
Hector Sanjuan
35e5e69471 Issue #162: Add tests for rest.Config
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-10-19 20:49:18 +02:00
Hector Sanjuan
8f06baa1bf Issue #162: Rework configuration format
The following commit reimplements ipfs-cluster configuration under
the following premises:

  * Each component is initialized with a configuration object
  defined by its module
  * Each component decides how the JSON representation of its
  configuration looks like
  * Each component parses and validates its own configuration
  * Each component exposes its own defaults
  * Component configurations are make the sections of a
  central JSON configuration file (which replaces the current
  JSON format)
  * Component configurations implement a common interface
  (config.ComponentConfig) with a set of common operations
  * The central configuration file is managed by a
  config.ConfigManager which:
    * Registers ComponentConfigs
    * Assigns the correspondent sections from the JSON file to each
    component and delegates the parsing
    * Delegates the JSON generation for each section
    * Can be notified when the configuration is updated and must be
    saved to disk

The new service.json would then look as follows:

```json
{
  "cluster": {
    "id": "QmTVW8NoRxC5wBhV7WtAYtRn7itipEESfozWN5KmXUQnk2",
    "private_key": "<...>",
    "secret": "00224102ae6aaf94f2606abf69a0e278251ecc1d64815b617ff19d6d2841f786",
    "peers": [],
    "bootstrap": [],
    "leave_on_shutdown": false,
    "listen_multiaddress": "/ip4/0.0.0.0/tcp/9096",
    "state_sync_interval": "1m0s",
    "ipfs_sync_interval": "2m10s",
    "replication_factor": -1,
    "monitor_ping_interval": "15s"
  },
  "consensus": {
    "raft": {
      "heartbeat_timeout": "1s",
      "election_timeout": "1s",
      "commit_timeout": "50ms",
      "max_append_entries": 64,
      "trailing_logs": 10240,
      "snapshot_interval": "2m0s",
      "snapshot_threshold": 8192,
      "leader_lease_timeout": "500ms"
    }
  },
  "api": {
    "restapi": {
      "listen_multiaddress": "/ip4/127.0.0.1/tcp/9094",
      "read_timeout": "30s",
      "read_header_timeout": "5s",
      "write_timeout": "1m0s",
      "idle_timeout": "2m0s"
    }
  },
  "ipfs_connector": {
    "ipfshttp": {
      "proxy_listen_multiaddress": "/ip4/127.0.0.1/tcp/9095",
      "node_multiaddress": "/ip4/127.0.0.1/tcp/5001",
      "connect_swarms_delay": "7s",
      "proxy_read_timeout": "10m0s",
      "proxy_read_header_timeout": "5s",
      "proxy_write_timeout": "10m0s",
      "proxy_idle_timeout": "1m0s"
    }
  },
  "monitor": {
    "monbasic": {
      "check_interval": "15s"
    }
  },
  "informer": {
    "disk": {
      "metric_ttl": "30s",
      "metric_type": "freespace"
    },
    "numpin": {
      "metric_ttl": "10s"
    }
  }
}
```

This new format aims to be easily extensible per component. As such,
it already surfaces quite a few new options which were hardcoded
before.

Additionally, since Go API have changed, some redundant methods have been
removed and small refactoring has happened to take advantage of the new
way.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-10-18 00:00:12 +02:00
dgrisham
25a910faad BasicAuth implementation -- CLI, server, and tests. 2017-10-14 15:55:21 -06:00
dgrisham
31cee53a55 Added --no-check-certificate flag for TLS API client 2017-07-23 10:11:10 -06:00
dgrisham
dd3db9bbc9 HTTPS REST API support implemented 2017-07-21 16:44:14 -06:00
Hector Sanjuan
cc8c9da28d Fixes #100: EOF responses when cluster peer is not responding
The ReadTimeout for the API was the same as for RPC. So the error
did not have time to be correctly returned to the client.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-05-18 13:16:27 +02:00
Hector Sanjuan
bb82c27b25 Fix #87: Implement ipfs-cluster-ctl pin ls <cid>
I have updated API endpoints to be /allocations rather than /pinlinst

It's more self-explanatory.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-04-06 21:12:16 +02:00
Hector Sanjuan
db6956b737 Fix #77: ipfs-cluster-ctl output tweaks.
Be more consistent when printing errors (i.e. if json encoding
is requested then it should be used for errors too). Do not
print "Request accepted".

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-03-28 19:10:50 +02:00
Hector Sanjuan
f3c1636062 Take advantage of go-multiaddr-net utilities.
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-03-16 15:51:24 +01:00
Hector Sanjuan
e2efef8469 go lint, go vet, put the Consensus component behind interface.
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-03-14 16:37:29 +01:00
Hector Sanjuan
37fab27ba6 Move MapPinTracker to its own submodule and add tests for it
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-03-14 16:10:45 +01:00
Hector Sanjuan
a6b99107ae Fix numpinalloc tests
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-03-14 14:31:26 +01:00
Hector Sanjuan
a40e90a78d Fix: metrics with nanoseconds TTLs
It turns out they only worked in round seconds. Tests send a metric
every second, so sometimes they were expired right away.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-03-14 14:18:23 +01:00
Hector Sanjuan
e99b7b4f79 [WIP]: Move REST API and IPFS HTTP Connector to its own submodules
Part of Issue #18.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-03-13 18:39:23 +01:00
Hector Sanjuan
01d65a1595 Support replication factor as a pin parameter
This adds a replication_factor query argument to the API
endpoint which allows to set a replication factor per Pin.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-03-08 18:50:54 +01:00
Hector Sanjuan
9b652bcfb3 Rename CidArg to Pin.
CidArg used to be an internal name for an argument that carried a Cid.
Now it has surfaced to API level and makes no sense. It is a Pin. It
represents a Pin (Cid, Allocations, Replication Factor)

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-03-08 16:57:27 +01:00
Hector Sanjuan
37046dc925 go vet fixes
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-02-15 15:46:51 +01:00
Hector Sanjuan
469cf51e62 Make sure all times appear as UTC
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-02-15 14:15:12 +01:00
Hector Sanjuan
2512ecb701 Issue #41: Add Replication factor
New PeerManager, Allocator, Informer components have been added along
with a new "replication_factor" configuration option.

First, cluster peers collect and push metrics (Informer) to the Cluster
leader regularly. The Informer is an interface that can be implemented
in custom wayts to support custom metrics.

Second, on a pin operation, using the information from the collected metrics,
an Allocator can provide a list of preferences as to where the new pin
should be assigned. The Allocator is an interface allowing to provide
different allocation strategies.

Both Allocator and Informer are Cluster Componenets, and have access
to the RPC API.

The allocations are kept in the shared state. Cluster peer failure
detection is still missing and re-allocation is still missing, although
re-pinning something when a node is down/metrics missing does re-allocate
the pin somewhere else.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-02-14 19:13:08 +01:00
Hector Sanjuan
c0697599ac Add nice text formatters to the ipfs-cluster-ctl app
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-02-09 16:30:53 +01:00
Hector Sanjuan
1b3d04e18b Move all API-related types to the /api subpackage.
At the beginning we opted for native types which were
serializable (PinInfo had a CidStr field instead of Cid).

Now we provide types in two versions: native and serializable.

Go methods use native. The rest of APIs (REST/RPC) use always
serializable versions. Methods are provided to convert between the
two.

The reason for moving these out of the way is to be able to re-use
type definitions when parsing API responses in `ipfs-cluster-ctl` or
any other clients that come up. API responses are just the serializable
version of types in JSON encoding. This also reduces having
duplicate types defs and parsing methods everywhere.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-02-09 16:30:53 +01:00