utapi from zenko-cloudserver dependencies
 
 
 
 
Go to file
Vitaliy Filippov facc276e8b move away require libv2/config from libv2/redis 2024-08-13 02:17:04 +03:00
.github Merge branch 'w/7.70/bugfix/UTAPI-101/fix_release_workflow' into tmp/octopus/w/8.1/bugfix/UTAPI-101/fix_release_workflow 2024-05-16 17:16:03 +00:00
bin ft(UTAPI-33): Add ensureServiceUser script 2021-10-15 13:12:42 -07:00
docs Update Release.md for ghcr migration 2024-04-18 15:55:13 +02:00
examples Merge remote-tracking branch 'origin/w/7.8/bugfix/S3C-3043_bump_scality_guidelines' into w/8.1/bugfix/S3C-3043_bump_scality_guidelines 2020-06-10 15:10:04 -07:00
handlers chore: remove babel 2017-05-23 15:09:06 -07:00
images Forget LFS object 2024-07-21 17:34:07 +03:00
lib Make vault client optional / support receiving its instance from outside 2024-07-23 19:22:54 +03:00
libV2 move away require libv2/config from libv2/redis 2024-08-13 02:17:04 +03:00
models Merge remote-tracking branch 'origin/bugfix/UTAPI-34-implementCRRActions' into w/7.10/bugfix/UTAPI-34-implementCRRActions 2021-10-28 16:08:38 -07:00
res DEV: Add DESIGN.md 2017-02-09 17:09:54 -08:00
responses chore: remove babel 2017-05-23 15:09:06 -07:00
router Make vault client optional / support receiving its instance from outside 2024-07-23 19:22:54 +03:00
tests Merge remote-tracking branch 'origin/w/7.70/improvement/UTAPI-97/reindex_only_latest_for_olock_buckets_option' into w/8.1/improvement/UTAPI-97/reindex_only_latest_for_olock_buckets_option 2023-12-11 09:38:41 -08:00
utils bf(S3C-1997): Fix ioredis failover for sentinels 2020-09-23 17:02:30 -07:00
validators Fix new linting errors 2020-06-10 14:48:53 -07:00
warpscript ft(UTAPI-75): Add metrics for latest checkpoint and snapshot 2022-06-03 09:40:27 -07:00
.babelrc FT: Node v6 2017-02-28 19:59:22 +01:00
.dockerignore ft(S3C-3351): Cache js dependencies in buildbot worker 2020-09-17 10:10:58 -07:00
.eslintrc feature: UTAPI-59 update eslintrc rules 2022-02-07 15:39:37 -08:00
.gitignore Fix new linting errors 2020-06-10 14:48:53 -07:00
.prettierrc Fix new linting errors 2020-06-10 14:48:53 -07:00
DESIGN.md FT: Add caching behavior to documents 2017-02-24 15:06:08 -08:00
Dockerfile impr(UTAPI-66): Update Dockerfile with --network-concurrency 2022-05-18 10:06:08 -07:00
LICENSE FT: Initiate repository with basics 2016-08-09 12:22:14 -07:00
README.md Merge remote-tracking branch 'origin/w/7.5/bugfix/S3C-1506/add-long-range-request-ft-tests' into w/8.0/bugfix/S3C-1506/add-long-range-request-ft-tests 2019-05-02 15:34:43 -07:00
circle.yml feature: node version 2018-03-26 13:26:27 +02:00
config.json feature: S3C-1212 expire bucket metrics on delete bucket 2018-06-26 15:10:27 -07:00
docker-compose.yaml UTAPI-98 Bump Redis version 2024-01-22 16:36:01 +01:00
docker-entrypoint.sh ft: ZENKO 465 Utapi docker image 2018-06-07 10:37:20 -07:00
index.js Merge branch 'w/7.8/bugfix/S3C-3240_fix_tasks_exports' into tmp/octopus/w/8.1/bugfix/S3C-3240_fix_tasks_exports 2020-08-10 23:23:15 +00:00
openapi.yaml Prometheus Exporters for Nodejs, Redis, Warp10 2021-07-30 17:25:28 -07:00
package.json Change git dependency URLs 2024-07-21 18:12:40 +03:00
requirements.txt Fix caching of python packages 2024-04-18 15:47:05 +02:00
server.js Make vault client optional / support receiving its instance from outside 2024-07-23 19:22:54 +03:00

README.md

utapi

Utapi logo

Circle CI

Service Utilization API for tracking resource usage and metrics reporting.

Design

Please refer to the design for more information.

Server

To run the server:

npm start

Client

The module exposes a client, named UtapiClient. Projects can use this client to push metrics directly to the underlying datastore (Redis) without the need of an extra HTTP request to Utapi.

const { UtapiClient } = require('utapi');

const config = {
    redis: {
        host: '127.0.0.1',
        port: 6379
    },
    localCache: {
        host: '127.0.0.1',
        port: 6379
    }
}
const c = new UtapiClient(config);

// The second argument to `pushMetric` is a hexadecimal string Request Unique
// Identifier used for logging.
c.pushMetric('createBucket', '3d534b1511e5630e68f0', { bucket: 'demo' });

c.pushMetric('putObject', '3d534b1511e5630e68f0', {
    bucket: 'demo',
    newByteLength: 1024,
    oldByteLength: null,
});

c.pushMetric('putObject', '3d534b1511e5630e68f0', {
    bucket: 'demo',
    newByteLength: 1024,
    oldByteLength: 256,
});

c.pushMetric('multiObjectDelete', '3d534b1511e5630e68f0', {
    bucket: 'demo',
    byteLength: 1024,
    numberOfObjects: 999,
});

If an error occurs during a pushMetric call and the client is unable to record metrics in the underlying datastore, metric data is instead stored in a local Redis cache. Utapi attempts to push these cached metrics (every five minutes, by default) using a component named UtapiReplay. If the pushMetric call initiated by UtapiReplay fails, the metric is reinserted into the local Redis cache. The particularities of this behavior are configurable. For further information, see design.

Listing Metrics with Utapi

To make a successful request to Utapi you would need

  1. IAM user with a policy giving access to Utapi
  2. Sign request with Auth V4

IAM user with a policy giving access to Utapi

Note: The examples here use AWS CLI but any AWS SDK is capable of these actions.

endpoint-url: This would be https://<host>:<port> where your Identity(IAM) Server is running.

  1. Create an IAM user

    aws iam --endpoint-url <endpoint> create-user --user-name <user-name>
    
  2. Create access key for the user

    aws iam --endpoint-url <endpoint> create-access-key --user-name <user-name>
    
  3. Define a managed IAM policy

    sample utapi policy

    cat - > utapipolicy.json <<EOF
    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "utapiMetrics",
                "Action": [ "utapi:ListMetrics" ],
                "Effect": "Allow",
                "Resource": [
                    "arn:scality:utapi::012345678901:buckets/*",
                    "arn:scality:utapi::012345678901:accounts/*",
                    "arn:scality:utapi::012345678901:users/*",
                ]
            }
        ]
    }
    EOF
    

    In the above sample, the Resource property includes a series of Amazon Resource Names (ARNs) used to define which resources the policy applies to. Thus the sample policy applies to a user with an account ID '012345678901', and grants access to metrics at the levels 'buckets', 'accounts', and 'users'.

    The account ID of the ARN can also be omitted, allowing any account to access metrics for those resources. As an example, we can extend the above sample policy to allow any account to access metrics at the level 'service':

    ...
    "Resource": [
        "arn:scality:utapi::012345678901:buckets/*",
        "arn:scality:utapi::012345678901:accounts/*",
        "arn:scality:utapi::012345678901:users/*",
        "arn:scality:utapi:::service/*",
    ]
    ...
    

    The omission of a metric level denies a user access to all resources at that level. For example, we can allow access to metrics only at the level 'buckets':

    ...
    "Resource": ["arn:scality:utapi::012345678901:buckets/*"]
    ...
    

    Further, access may be limited to specific resources within a metric level. For example, we can allow access to metrics only for a bucket 'foo':

    ...
    "Resource": ["arn:scality:utapi::012345678901:buckets/foo"]
    ...
    

    Or allow access to metrics for the bucket 'foo' for any user:

    ...
    "Resource": ["arn:scality:utapi:::buckets/foo"]
    ...
    
  4. Create a managed IAM policy

    Once your IAM policy is defined, create the policy using the following command.

    aws iam --endpoint-url <endpoint> create-policy --policy-name utapipolicy \
     --policy-document file://utapipolicy.json
    

    A sample output of the above command would look like

    {
        "Policy": {
            "PolicyName": "utapipolicy",
            "CreateDate": "2017-06-01T19:31:18.620Z",
            "AttachmentCount": 0,
            "IsAttachable": true,
            "PolicyId": "ZXR6A36LTYANPAI7NJ5UV",
            "DefaultVersionId": "v1",
            "Path": "/",
            "Arn": "arn:aws:iam::0123456789012:policy/utapipolicy",
            "UpdateDate": "2017-06-01T19:31:18.620Z"
        }
    }
    

    The arn property of the response, which we call <policy arn>, will be used in the next step to attach the policy to the user.

  5. Attach user to the managed policy

    aws --endpoint-url <endpoint> iam  attach-user-policy --user-name
    <user-name> --policy-arn <policy arn>
    

Now the user has access to ListMetrics request in Utapi on all buckets.

Signing request with Auth V4

There are two options here.

You can generate V4 signature using AWS SDKs or the node module aws4. See the following urls for reference.

You may also view examples making a request with Auth V4 using various languages and AWS SDKs here.

Alternatively, you can use a nifty command line tool available in Scality's CloudServer.

You can git clone the CloudServer repo from here https://github.com/scality/cloudserver and follow the instructions in the README to install the dependencies.

If you have CloudServer running inside a docker container you can docker exec into the CloudServer container as

docker exec -it <container-id> bash

and then run the command

node bin/list_metrics

It will generate the following output listing available options.

Usage: list_metrics [options]

  Options:

    -h, --help                    output usage information
    -V, --version                 output the version number
    -a, --access-key <accessKey>  Access key id
    -k, --secret-key <secretKey>  Secret access key
    -m, --metric <metric>         Metric type
    --buckets <buckets>           Name of bucket(s) with a comma separator if
                                  more than one
    --accounts <accounts>         Account ID(s) with a comma separator if more
                                  than one
    --users <users>               User ID(s) with a comma separator if more than
                                  one
    --service <service>           Name of service
    -s, --start <start>           Start of time range
    -r, --recent                  List metrics including the previous and
                                  current 15 minute interval
    -e --end <end>                End of time range
    -h, --host <host>             Host of the server
    -p, --port <port>             Port of the server
    --ssl                         Enable ssl
    -v, --verbose

An example call to list metrics for a bucket demo to Utapi in a https enabled deployment would be

node bin/list_metrics --metric buckets --buckets demo --start 1476231300000
--end 1476233099999 -a myAccessKey -k mySecretKey -h 127.0.0.1 -p 8100 --ssl

Both start and end times are time expressed as UNIX epoch timestamps expressed in milliseconds.

Keep in mind, since Utapi metrics are normalized to the nearest 15 min. interval, start time and end time need to be in the specific format as follows.

Start time

Start time needs to be normalized to the nearest 15 minute interval with seconds and milliseconds set to 0. So valid start timestamps would look something like 09:00:00:000, 09:15:00:000, 09:30:00:000 and 09:45:00:000.

For example

Date: Tue Oct 11 2016 17:35:25 GMT-0700 (PDT)

Unix timestamp (milliseconds): 1476232525320

Here's an example JS method to get a start timestamp

function getStartTimestamp(t) {
    const time = new Date(t);
    const minutes = time.getMinutes();
    const timestamp = time.setMinutes((minutes - minutes % 15), 0, 0);
    return timestamp;
}

This would format the start time timestamp to 1476231300000

End time

End time needs to be normalized to the nearest 15 minute end interval with seconds and milliseconds set to 59 and 999 respectively. So valid end timestamps would look something like 09:14:59:999, 09:29:59:999, 09:44:59:999 and 09:59:59:999.

Here's an example JS method to get an end timestamp

function getEndTimestamp(t) {
    const time = new Date(t);
    const minutes = time.getMinutes();
    const timestamp = time.setMinutes((minutes - minutes % 15) + 15, 0, -1);
    return timestamp;
}

This would format the end time timestamp to 1476233099999

Guidelines

Please read our coding and workflow guidelines at scality/Guidelines.

Contributing

In order to contribute, please follow the Contributing Guidelines.