public async Task GcePlatform()
        {
            const string json            = @"
{
  'project': {
    'projectId': 'gce_project_id'
  },
  'instance': {
    'id': 'FakeInstanceId',
    'zone': 'projects/12345/zones/FakeZone'
  }
}
";
            var          platform        = new Platform(GcePlatformDetails.TryLoad(json));
            var          uploadedEntries = await RunTestWorkingServer(
                googleTarget =>
            {
                LogInfo("Message0");
                return(Task.FromResult(0));
            }, platform : platform, enableResourceTypeDetection : true);

            Assert.Equal(1, uploadedEntries.Count);
            var r = uploadedEntries[0].Resource;

            Assert.Equal("gce_instance", r.Type);
            Assert.Equal(3, r.Labels.Count);
            // This is the monitored resource project ID.
            Assert.Equal("gce_project_id", r.Labels["project_id"]);
            Assert.Equal("FakeInstanceId", r.Labels["instance_id"]);
            Assert.Equal("FakeZone", r.Labels["zone"]);
            // If the project ID is configured, it is used as the target for writing
            // logs, even if the code is running on GCP.
            Assert.Equal(s_projectId, uploadedEntries[0].LogNameAsLogName.ProjectId);
        }
Exemplo n.º 2
0
        public async Task GcePlatform()
        {
            const string json            = @"
{
  'project': {
    'projectId': '" + s_projectId + @"'
  },
  'instance': {
    'id': 'FakeInstanceId',
    'zone': 'FakeZone'
  }
}
";
            var          platform        = new Platform(GcePlatformDetails.TryLoad(json));
            var          uploadedEntries = await RunTestWorkingServer(async appender =>
            {
                appender.DoAppend(CreateLog(Level.Info, "0"));
                Assert.True(await appender.FlushAsync(s_testTimeout));
            }, platform : platform, enableResourceTypeDetection : true);

            Assert.Equal(1, uploadedEntries.Count);
            var r = uploadedEntries[0].Resource;

            Assert.Equal("gce_instance", r.Type);
            Assert.Equal(3, r.Labels.Count);
            Assert.Equal(s_projectId, r.Labels["project_id"]);
            Assert.Equal("FakeInstanceId", r.Labels["instance_id"]);
            Assert.Equal("FakeZone", r.Labels["zone"]);
        }
Exemplo n.º 3
0
        public void Gce_InvalidZoneFormatLocation()
        {
            var metadataJson = "{'project':{'projectId':'FakeProjectId'},'instance':{'id':'123','zone':'FakeLocation'}}";
            var gce          = new GcePlatformDetails(metadataJson, "FakeProjectId", "123", "FakeLocation");

            Assert.Throws <InvalidOperationException>(() => gce.Location);
        }
        public async Task GcePlatform()
        {
            const string json            = @"
{
  'project': {
    'projectId': '" + s_projectId + @"'
  },
  'instance': {
    'id': 'FakeInstanceId',
    'zone': 'FakeZone'
  }
}
";
            var          platform        = new Platform(GcePlatformDetails.TryLoad(json));
            var          uploadedEntries = await RunTestWorkingServer(
                googleTarget =>
            {
                LogInfo("Message0");
                return(Task.FromResult(0));
            }, platform : platform, enableResourceTypeDetection : true);

            Assert.Equal(1, uploadedEntries.Count);
            var r = uploadedEntries[0].Resource;

            Assert.Equal("gce_instance", r.Type);
            Assert.Equal(3, r.Labels.Count);
            Assert.Equal(s_projectId, r.Labels["project_id"]);
            Assert.Equal("FakeInstanceId", r.Labels["instance_id"]);
            Assert.Equal("FakeZone", r.Labels["zone"]);
        }
Exemplo n.º 5
0
        public void Gce_ValidZoneFormatLocation()
        {
            var metadataJson = "{'project':{'projectId':'FakeProjectId'},'instance':{'id':'123','zone':'projects/123456/zones/FakeLocation'}}";
            var gce          = new GcePlatformDetails(metadataJson, "FakeProjectId", "123", "projects/123456/zones/FakeLocation");

            Assert.Equal("FakeLocation", gce.Location);
        }
Exemplo n.º 6
0
        public void Project_Gce()
        {
            var details  = new GcePlatformDetails("json", "gce-project", "instance", "projects/123/zones/zone");
            var platform = new Platform(details);

            Assert.Equal("gce-project", platform.ProjectId);
        }
Exemplo n.º 7
0
 public void Gce_NoData()
 {
     Assert.Throws <ArgumentNullException>(() => GcePlatformDetails.TryLoad(null));
     Assert.Null(GcePlatformDetails.TryLoad(""));
     Assert.Throws <ArgumentNullException>(() => new GcePlatformDetails(null, "", "", ""));
     Assert.Throws <ArgumentNullException>(() => new GcePlatformDetails("", null, "", ""));
     Assert.Throws <ArgumentNullException>(() => new GcePlatformDetails("", "", null, ""));
     Assert.Throws <ArgumentNullException>(() => new GcePlatformDetails("", "", "", null));
 }
        public void GcePlatform()
        {
            const string json     = @"
{
  'project': {
    'projectId': 'FakeProjectId'
  },
  'instance': {
    'id': 'FakeInstanceId',
    'zone': 'FakeZone'
  }
}
";
            var          platform = new Platform(GcePlatformDetails.TryLoad(json));
            var          resource = MonitoredResourceBuilder.FromPlatform(platform);

            Assert.Equal("gce_instance", resource.Type);
            Assert.Equal(3, resource.Labels.Count);
            Assert.Equal("FakeProjectId", resource.Labels["project_id"]);
            Assert.Equal("FakeInstanceId", resource.Labels["instance_id"]);
            Assert.Equal("FakeZone", resource.Labels["zone"]);
        }
        public void GcePlatform()
        {
            const string json     = @"
{
  'project': {
    'projectId': 'FakeProjectId'
  },
  'instance': {
    'id': 'FakeInstanceId',
    'zone': 'FakeZone'
  }
}
";
            var          platform = new Platform(GcePlatformDetails.TryLoad(json));
            var          resource = MonitoredResourceBuilder.FromPlatform(platform);

            Assert.Equal("gce_instance", resource.Type);
            Assert.Equal(new Dictionary <string, string>
            {
                { "project_id", "FakeProjectId" },
                { "instance_id", "FakeInstanceId" },
                { "zone", "FakeZone" }
            }, resource.Labels);
        }