Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 9747e04
Merge: f6fc96d 7194168
Author: Nikki Attea <[email protected]>
Date:   Mon Jun 4 07:33:37 2018 -0700

    Merge branch 'testing/metric-extraction' of https://github.com/sensu/sensu-go into testing/metric-extraction

    Signed-off-by: Nikki Attea <[email protected]>

commit f6fc96d
Author: Nikki Attea <[email protected]>
Date:   Fri Jun 1 10:50:46 2018 -0500

    Remove metric extraction e2e test in favor of a more detailed integration test

    Signed-off-by: Nikki Attea <[email protected]>

commit d6d1286
Author: Terrance Kennedy <[email protected]>
Date:   Fri Jun 1 14:46:27 2018 -0600

    Travis: unshallow git history to detect version

    Signed-off-by: Terrance Kennedy <[email protected]>

commit ca7a4b8
Author: Neal Granger <[email protected]>
Date:   Fri Jun 1 12:54:58 2018 -0700

    Display a modal when authentication fails (#1627)

    In the event that automatic session refresh fails, show the user a message instead of redirecting directly to the sign in page.

    Signed-off-by: Neal Granger <[email protected]>

commit ca88abe
Author: Terrance Kennedy <[email protected]>
Date:   Fri Jun 1 13:52:42 2018 -0600

    Remove tag info from deploy

    Signed-off-by: Terrance Kennedy <[email protected]>

commit 04be123
Author: Terrance Kennedy <[email protected]>
Date:   Fri Jun 1 15:21:26 2018 -0400

    Pass SENSU_BUILD_ITERATION to packaging container (#1641)

    Signed-off-by: Terrance Kennedy <[email protected]>

    ## What is this change?

    Passes the `SENSU_BUILD_ITERATION` environment variable into the sensu-go-build docker container when deploying packages.

    ## Why is this change necessary?

    Sensu nightly builds were broken on Travis because the version command could not determine the build iteration.

    ## Does your change need a Changelog entry?

    Not this time.

    ## Do you need clarification on anything?

    I'm good.

    ## Were there any complications while making this change?

    I noticed that the package_cloud gem was being installed on the host, which is unnecessary because it's only installed/used inside the sensu-go-build docker container. Builds should be a few seconds faster now too.

commit be0a32d
Author: Eric Chlebek <[email protected]>
Date:   Fri Jun 1 11:36:26 2018 -0700

    Comment out failing tests. (#1639)

    These tests are failing on some environments, and we don't know
    why yet.

    Signed-off-by: Eric Chlebek <[email protected]>

commit a59a476
Author: Nikki Attea <[email protected]>
Date:   Fri Jun 1 10:56:16 2018 -0500

    Remove omitempty from boolean fields (#1632)

    Signed-off-by: Nikki Attea <[email protected]>

commit 7194168
Author: Nikki Attea <[email protected]>
Date:   Fri Jun 1 10:50:46 2018 -0500

    Remove metric extraction e2e test in favor of a more detailed integration test

    Signed-off-by: Nikki Attea <[email protected]>

commit 318d489
Author: Eric Chlebek <[email protected]>
Date:   Thu May 31 11:19:40 2018 -0700

    Upgrade govaluate to release 3.1.0. (#1629)

    Closes #922

    Signed-off-by: Eric Chlebek <[email protected]>

Signed-off-by: Nikki Attea <[email protected]>
  • Loading branch information
Nikki Attea committed Jun 4, 2018
1 parent f0158dc commit 43b2f31
Show file tree
Hide file tree
Showing 30 changed files with 475 additions and 358 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.6.0
- export PATH="$HOME/.yarn/bin:$PATH"
install:
- "git fetch --tags"
# Travis clones with depth=50 by default. If the most recent tag is more than
# 50 commits back, git describe will fail. Fetch tags and full history.
- "git fetch --unshallow --tags"
- "./build.sh deps"
- "./build.sh build_tools"
script: "./build.sh $TEST_SUITE"
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ characters and therefore fixing a bug in sensuctl
- Fixed a bug where environments couldn't be deleted if there was an asset in
the organization they reside in.
- Dashboard's backend reverse proxy now works with TLS certs are configured.
- Fixed a bug with the IN operator in query statements.
- Boolean fields with a value of `false` now appear in json format (removed
`omitempty` from protobufs).

### Removed
- Removed Linux/386 & Windows/386 e2e jobs on Travis CI & AppVeyor
- Removed check output metric extraction e2e test, in favor of more detailed
integration coverage.

## [2.0.0-beta.1] - 2018-05-07
### Added
Expand Down
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ required = [
# https://github.com/Knetic/govaluate/issues/61
[[constraint]]
name = "github.com/sensu/govaluate"
branch = "nested-parameters"
version = "3.1.0"

[[constraint]]
name = "github.com/sirupsen/logrus"
Expand Down
18 changes: 18 additions & 0 deletions agent/check_handler_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package agent

import (
"encoding/json"
"io/ioutil"
"path/filepath"
"testing"
"time"
Expand Down Expand Up @@ -111,7 +112,15 @@ func TestExecuteCheck(t *testing.T) {
assert.NotZero(event.Timestamp)
assert.False(event.HasMetrics())

metrics := "metric.foo 1 123456789\nmetric.bar 2 987654321"
f, err := ioutil.TempFile("", "metric")
assert.NoError(err)
err = ioutil.WriteFile(f.Name(), []byte(metrics), 0644)
assert.NoError(err)
defer f.Close()
checkConfig.OutputMetricFormat = types.GraphiteOutputMetricFormat
catPath := testutil.CommandPath(filepath.Join(toolsDir, "cat"), f.Name())
checkConfig.Command = catPath

agent.executeCheck(request)

Expand All @@ -121,6 +130,15 @@ func TestExecuteCheck(t *testing.T) {
assert.NoError(json.Unmarshal(msg.Payload, event))
assert.NotZero(event.Timestamp)
assert.True(event.HasMetrics())
assert.Equal(2, len(event.Metrics.Points))
metric0 := event.Metrics.Points[0]
assert.Equal(float64(1), metric0.Value)
assert.Equal("metric.foo", metric0.Name)
assert.Equal(int64(123456789), metric0.Timestamp)
metric1 := event.Metrics.Points[1]
assert.Equal(float64(2), metric1.Value)
assert.Equal("metric.bar", metric1.Name)
assert.Equal(int64(987654321), metric1.Timestamp)
}

func TestPrepareCheck(t *testing.T) {
Expand Down
6 changes: 1 addition & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,6 @@ deploy() {

echo "Deploying..."

echo "Current tags:"
git --no-pager tag -l

# Authenticate to Google Cloud and deploy binaries
if [[ "${release}" != "nightly" ]]; then
openssl aes-256-cbc -K $encrypted_abd14401c428_key -iv $encrypted_abd14401c428_iv -in gcs-service-account.json.enc -out gcs-service-account.json -d
Expand All @@ -343,12 +340,11 @@ deploy() {
fi

# Deploy system packages to PackageCloud
gem install package_cloud
make clean
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
docker pull sensuapp/sensu-go-build
docker run -it -e SENSU_BUILD_ITERATION=$SENSU_BUILD_ITERATION -e CI=$CI -v `pwd`:/go/src/github.com/sensu/sensu-go sensuapp/sensu-go-build
docker run -it -v `pwd`:/go/src/github.com/sensu/sensu-go -e PACKAGECLOUD_TOKEN="$PACKAGECLOUD_TOKEN" -e CI=$CI sensuapp/sensu-go-build publish_travis
docker run -it -v `pwd`:/go/src/github.com/sensu/sensu-go -e PACKAGECLOUD_TOKEN="$PACKAGECLOUD_TOKEN" -e SENSU_BUILD_ITERATION=$SENSU_BUILD_ITERATION -e CI=$CI sensuapp/sensu-go-build publish_travis
docker run -it -v `pwd`:/go/src/github.com/sensu/sensu-go sensuapp/sensu-go-build clean

# Deploy Docker images to the Docker Hub
Expand Down
59 changes: 34 additions & 25 deletions cli/commands/timeutil/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ func TestDateToTime(t *testing.T) {
}

func TestKitchenToTime(t *testing.T) {
baseTime, _ := time.ParseInLocation(time.Kitchen, "3:04PM", time.UTC)
baseTime, err := time.ParseInLocation(time.Kitchen, "3:04PM", time.UTC)
if err != nil {
t.Fatal(err)
}

// Our test cases
tests := []struct {
Expand All @@ -74,12 +77,12 @@ func TestKitchenToTime(t *testing.T) {
str: "15:04 UTC",
want: baseTime,
},
{
name: "24-hour kitchen with canonical timezone",
str: "07:04 America/Vancouver",
skipWindows: true,
want: baseTime,
},
//{
// name: "24-hour kitchen with canonical timezone",
// str: "07:04 America/Vancouver",
// skipWindows: true,
// want: baseTime,
//},
{
name: "24-hour kitchen with numeric zone offset",
str: "07:04 -08:00",
Expand All @@ -95,12 +98,12 @@ func TestKitchenToTime(t *testing.T) {
str: "3:04PM UTC",
want: baseTime,
},
{
name: "12-hour kitchen with canonical timezone",
str: "10:04AM America/Montreal",
skipWindows: true,
want: baseTime,
},
//{
// name: "12-hour kitchen with canonical timezone",
// str: "10:04AM America/Montreal",
// skipWindows: true,
// want: baseTime,
//},
{
name: "12-hour kitchen with unknown location",
str: "10:04AM foo",
Expand Down Expand Up @@ -184,9 +187,15 @@ func TestConvertToUnix(t *testing.T) {
}

func TestConvertToUTC(t *testing.T) {
b, _ := time.ParseInLocation(time.Kitchen, "3:04PM", time.UTC)
b, err := time.ParseInLocation(time.Kitchen, "3:04PM", time.UTC)
if err != nil {
t.Fatal(err)
}
begin := b.Format(time.Kitchen)
e, _ := time.ParseInLocation(time.Kitchen, "4:04PM", time.UTC)
e, err := time.ParseInLocation(time.Kitchen, "4:04PM", time.UTC)
if err != nil {
t.Fatal(err)
}
end := e.Format(time.Kitchen)

tests := []struct {
Expand All @@ -206,16 +215,16 @@ func TestConvertToUTC(t *testing.T) {
wantBegin: begin,
wantEnd: end,
},
{
name: "12-hour kitchen canonical timezone",
window: &types.TimeWindowTimeRange{
Begin: "7:04AM America/Vancouver",
End: "8:04AM America/Vancouver",
},
skipWindows: true,
wantBegin: begin,
wantEnd: end,
},
//{
// name: "12-hour kitchen canonical timezone",
// window: &types.TimeWindowTimeRange{
// Begin: "7:04AM America/Vancouver",
// End: "8:04AM America/Vancouver",
// },
// skipWindows: true,
// wantBegin: begin,
// wantEnd: end,
//},
{
name: "24-hour kitchen numeric timezone",
window: &types.TimeWindowTimeRange{
Expand Down
14 changes: 2 additions & 12 deletions dashboard/src/apollo/authLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { ApolloLink, Observable } from "apollo-link";

import { when } from "/utils/promise";
import { UnauthorizedError } from "/errors/FetchError";
import QueryAbortedError from "/errors/QueryAbortedError";

import refreshTokens from "/mutations/refreshTokens";
import invalidateTokens from "/mutations/invalidateTokens";

const EXPIRY_THRESHOLD_MS = 13 * 60 * 1000;

Expand All @@ -28,17 +28,7 @@ const authLink = ({ getClient }) =>
sub = forward(operation).subscribe(observer);
},
when(UnauthorizedError, error => {
// Remove the current stored tokens if the token refresh attempt
// fails. This will redirect the user back to the login screen.
// We could potentially introduce a less disruptive behavior here,
// maybe show a modal allowing the user to re-enter credentials
// without loosing the current app state.
invalidateTokens(getClient());

// re-throw the UnauthorizedError instance to ensure later error
// handling (likely a <Query> instance) can deal with it
// appropriately.
throw error;
throw new QueryAbortedError(error);
}),
)
.catch(observer.error.bind(observer));
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/apollo/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const createClient = () => {
gql`
query SyncAuthQuery {
auth @client {
invalid
accessToken
refreshToken
expiresAt
Expand Down
79 changes: 47 additions & 32 deletions dashboard/src/apollo/resolvers/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import gql from "graphql-tag";

import { createTokens, invalidateTokens, refreshTokens } from "/utils/authAPI";
import { when } from "/utils/promise";
import { UnauthorizedError } from "/errors/FetchError";

const query = gql`
query AuthQuery {
Expand All @@ -12,10 +14,44 @@ const query = gql`
}
`;

const handleTokens = (cache, typename) => tokens => {
const { accessToken, refreshToken, expiresAt } = tokens;
const data = {
__typename: typename,
auth: {
__typename: "Auth",
invalid: false,
accessToken,
refreshToken,
expiresAt,
},
};

cache.writeData({ data });

return data;
};

const handleError = (cache, typename) =>
when(UnauthorizedError, error => {
const data = {
__typename: typename,
auth: {
__typename: "Auth",
invalid: true,
},
};

cache.writeData({ data });

throw error;
});

export default {
defaults: {
auth: {
__typename: "Auth",
invalid: false,
accessToken: null,
refreshToken: null,
expiresAt: null,
Expand All @@ -24,17 +60,11 @@ export default {
resolvers: {
Mutation: {
createTokens: (_, { username, password }, { cache }) =>
createTokens({ username, password }).then(tokens => {
const { accessToken, refreshToken, expiresAt } = tokens;
const data = {
__typename: "CreateTokensMutation",
auth: { __typename: "Auth", accessToken, refreshToken, expiresAt },
};

cache.writeData({ data });
createTokens({ username, password }).then(
handleTokens(cache, "CreateTokensMutation"),

return data;
}),
handleError(cache, "CreateTokensMutation"),
),

refreshTokens: (_, { notBefore = null }, { cache }) => {
const result = cache.readQuery({ query });
Expand All @@ -57,32 +87,17 @@ export default {
};
}

return refreshTokens(result.auth).then(tokens => {
const { accessToken, refreshToken, expiresAt } = tokens;
const data = {
__typename: "RefreshTokensMutation",
auth: { __typename: "Auth", accessToken, refreshToken, expiresAt },
};

cache.writeData({ data });

return data;
});
return refreshTokens(result.auth).then(
handleTokens(cache, "RefreshTokensMutation"),
handleError(cache, "RefreshTokensMutation"),
);
},

invalidateTokens: (_, vars, { cache }) => {
const result = cache.readQuery({ query });
return invalidateTokens(result.auth).then(tokens => {
const { accessToken, refreshToken, expiresAt } = tokens;
const data = {
__typename: "InvalidateTokensMutation",
auth: { __typename: "Auth", accessToken, refreshToken, expiresAt },
};

cache.writeData({ data });

return data;
});
return invalidateTokens(result.auth).then(
handleTokens(cache, "InvalidateTokensMutation"),
);
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions dashboard/src/apollo/schema/client.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ extend type Mutation {
}

type Auth {
"""
Indicates that the current access token has been rejected by the API and
cannot be automatically refreshed. The user must re-authenticate to continue.
"""
invalid: Boolean!

"Token used to access the system."
accessToken: String

Expand Down
6 changes: 6 additions & 0 deletions dashboard/src/apollo/schema/combined.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 43b2f31

Please sign in to comment.